Sha256: fbd725dea8354f13a64d056606d60842f19547cde01d6cd9590170a4042f7d69

Contents?: true

Size: 835 Bytes

Versions: 8

Compression:

Stored size: 835 Bytes

Contents

module GraphQL
  class Schema
    # Stores `{ name => type }` pairs for a given schema.
    # It behaves like a hash except for a couple things:
    #  - if you use `[key]` and that key isn't defined, 💥!
    #  - if you try to define the same key twice, 💥!
    #
    # If you want a type, but want to handle the undefined case, use {#fetch}.
    class TypeMap
      extend Forwardable
      def_delegators :@storage, :key?, :keys, :values, :to_h, :fetch, :each, :each_value

      def initialize
        @storage = {}
      end

      def [](key)
        @storage[key] || raise("No type found for '#{key}'")
      end

      def []=(key, value)
        if @storage.key?(key)
          raise("Duplicate type definition found for name '#{key}'")
        else
          @storage[key] = value
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-1.2.6 lib/graphql/schema/type_map.rb
graphql-1.2.5 lib/graphql/schema/type_map.rb
graphql-1.2.4 lib/graphql/schema/type_map.rb
graphql-1.2.3 lib/graphql/schema/type_map.rb
graphql-1.2.2 lib/graphql/schema/type_map.rb
graphql-1.2.1 lib/graphql/schema/type_map.rb
graphql-1.2.0 lib/graphql/schema/type_map.rb
graphql-1.1.0 lib/graphql/schema/type_map.rb