graphql 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/graphql.rb +31 -41
 - data/lib/graphql/argument.rb +23 -21
 - data/lib/graphql/base_type.rb +5 -8
 - data/lib/graphql/define/assign_argument.rb +5 -2
 - data/lib/graphql/define/type_definer.rb +2 -1
 - data/lib/graphql/directive.rb +34 -36
 - data/lib/graphql/directive/include_directive.rb +3 -7
 - data/lib/graphql/directive/skip_directive.rb +3 -7
 - data/lib/graphql/enum_type.rb +78 -76
 - data/lib/graphql/execution_error.rb +1 -3
 - data/lib/graphql/field.rb +99 -95
 - data/lib/graphql/input_object_type.rb +49 -47
 - data/lib/graphql/interface_type.rb +31 -34
 - data/lib/graphql/introspection.rb +19 -18
 - data/lib/graphql/introspection/directive_location_enum.rb +8 -0
 - data/lib/graphql/introspection/directive_type.rb +1 -3
 - data/lib/graphql/introspection/field_type.rb +1 -1
 - data/lib/graphql/introspection/fields_field.rb +1 -1
 - data/lib/graphql/introspection/introspection_query.rb +1 -3
 - data/lib/graphql/introspection/possible_types_field.rb +7 -1
 - data/lib/graphql/introspection/schema_field.rb +13 -9
 - data/lib/graphql/introspection/type_by_name_field.rb +13 -17
 - data/lib/graphql/introspection/typename_field.rb +12 -8
 - data/lib/graphql/language.rb +5 -9
 - data/lib/graphql/language/lexer.rb +668 -0
 - data/lib/graphql/language/lexer.rl +149 -0
 - data/lib/graphql/language/parser.rb +842 -116
 - data/lib/graphql/language/parser.y +264 -0
 - data/lib/graphql/language/token.rb +21 -0
 - data/lib/graphql/list_type.rb +33 -31
 - data/lib/graphql/non_null_type.rb +33 -31
 - data/lib/graphql/object_type.rb +52 -55
 - data/lib/graphql/query.rb +83 -80
 - data/lib/graphql/query/context.rb +5 -1
 - data/lib/graphql/query/directive_resolution.rb +16 -0
 - data/lib/graphql/query/executor.rb +3 -3
 - data/lib/graphql/query/input_validation_result.rb +17 -15
 - data/lib/graphql/query/serial_execution.rb +5 -5
 - data/lib/graphql/query/serial_execution/execution_context.rb +4 -3
 - data/lib/graphql/query/serial_execution/selection_resolution.rb +19 -21
 - data/lib/graphql/query/serial_execution/value_resolution.rb +1 -1
 - data/lib/graphql/query/type_resolver.rb +22 -18
 - data/lib/graphql/query/variable_validation_error.rb +14 -12
 - data/lib/graphql/schema.rb +87 -77
 - data/lib/graphql/schema/each_item_validator.rb +16 -12
 - data/lib/graphql/schema/field_validator.rb +14 -10
 - data/lib/graphql/schema/implementation_validator.rb +26 -22
 - data/lib/graphql/schema/middleware_chain.rb +2 -1
 - data/lib/graphql/schema/possible_types.rb +34 -0
 - data/lib/graphql/schema/printer.rb +122 -120
 - data/lib/graphql/schema/type_expression.rb +1 -0
 - data/lib/graphql/schema/type_map.rb +3 -10
 - data/lib/graphql/schema/type_reducer.rb +65 -81
 - data/lib/graphql/schema/type_validator.rb +45 -41
 - data/lib/graphql/static_validation.rb +7 -9
 - data/lib/graphql/static_validation/all_rules.rb +29 -24
 - data/lib/graphql/static_validation/arguments_validator.rb +39 -35
 - data/lib/graphql/static_validation/literal_validator.rb +44 -40
 - data/lib/graphql/static_validation/message.rb +30 -26
 - data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +15 -11
 - data/lib/graphql/static_validation/rules/arguments_are_defined.rb +14 -10
 - data/lib/graphql/static_validation/rules/directives_are_defined.rb +16 -12
 - data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +59 -0
 - data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +25 -21
 - data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +28 -24
 - data/lib/graphql/static_validation/rules/fields_will_merge.rb +84 -80
 - data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +49 -43
 - data/lib/graphql/static_validation/rules/fragment_types_exist.rb +22 -17
 - data/lib/graphql/static_validation/rules/fragments_are_finite.rb +19 -15
 - data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
 - data/lib/graphql/static_validation/rules/fragments_are_used.rb +36 -23
 - data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +29 -25
 - data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +21 -17
 - data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +79 -70
 - data/lib/graphql/static_validation/rules/variables_are_input_types.rb +24 -20
 - data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +122 -119
 - data/lib/graphql/static_validation/type_stack.rb +138 -129
 - data/lib/graphql/static_validation/validator.rb +29 -25
 - data/lib/graphql/type_kinds.rb +42 -40
 - data/lib/graphql/union_type.rb +22 -16
 - data/lib/graphql/version.rb +1 -1
 - data/readme.md +12 -27
 - data/spec/graphql/base_type_spec.rb +3 -3
 - data/spec/graphql/directive_spec.rb +10 -18
 - data/spec/graphql/enum_type_spec.rb +7 -7
 - data/spec/graphql/execution_error_spec.rb +1 -1
 - data/spec/graphql/field_spec.rb +14 -13
 - data/spec/graphql/id_type_spec.rb +6 -6
 - data/spec/graphql/input_object_type_spec.rb +39 -39
 - data/spec/graphql/interface_type_spec.rb +16 -32
 - data/spec/graphql/introspection/directive_type_spec.rb +5 -9
 - data/spec/graphql/introspection/input_value_type_spec.rb +10 -4
 - data/spec/graphql/introspection/introspection_query_spec.rb +2 -2
 - data/spec/graphql/introspection/schema_type_spec.rb +2 -2
 - data/spec/graphql/introspection/type_type_spec.rb +34 -6
 - data/spec/graphql/language/parser_spec.rb +299 -105
 - data/spec/graphql/language/visitor_spec.rb +4 -4
 - data/spec/graphql/list_type_spec.rb +11 -11
 - data/spec/graphql/object_type_spec.rb +10 -10
 - data/spec/graphql/query/arguments_spec.rb +7 -7
 - data/spec/graphql/query/context_spec.rb +11 -3
 - data/spec/graphql/query/executor_spec.rb +26 -19
 - data/spec/graphql/query/serial_execution/execution_context_spec.rb +6 -6
 - data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
 - data/spec/graphql/query/type_resolver_spec.rb +3 -3
 - data/spec/graphql/query_spec.rb +6 -38
 - data/spec/graphql/scalar_type_spec.rb +28 -19
 - data/spec/graphql/schema/field_validator_spec.rb +1 -1
 - data/spec/graphql/schema/middleware_chain_spec.rb +12 -1
 - data/spec/graphql/schema/printer_spec.rb +12 -4
 - data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
 - data/spec/graphql/schema/type_expression_spec.rb +2 -2
 - data/spec/graphql/schema/type_reducer_spec.rb +21 -36
 - data/spec/graphql/schema/type_validator_spec.rb +9 -9
 - data/spec/graphql/schema_spec.rb +1 -1
 - data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +4 -4
 - data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -4
 - data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +5 -5
 - data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +39 -0
 - data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +5 -5
 - data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +4 -4
 - data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
 - data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -1
 - data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +2 -2
 - data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +2 -2
 - data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +2 -2
 - data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +3 -3
 - data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +3 -3
 - data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +5 -5
 - data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +3 -1
 - data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +4 -4
 - data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +3 -3
 - data/spec/graphql/static_validation/type_stack_spec.rb +3 -2
 - data/spec/graphql/static_validation/validator_spec.rb +26 -6
 - data/spec/graphql/union_type_spec.rb +5 -4
 - data/spec/spec_helper.rb +2 -5
 - data/spec/support/dairy_app.rb +30 -9
 - data/spec/support/dairy_data.rb +1 -1
 - data/spec/support/star_wars_data.rb +26 -26
 - data/spec/support/star_wars_schema.rb +1 -1
 - metadata +40 -21
 - data/lib/graphql/language/transform.rb +0 -113
 - data/lib/graphql/query/directive_chain.rb +0 -44
 - data/lib/graphql/repl.rb +0 -27
 - data/spec/graphql/language/transform_spec.rb +0 -156
 
    
        data/lib/graphql/field.rb
    CHANGED
    
    | 
         @@ -1,111 +1,115 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
            #
         
     | 
| 
       3 
     | 
    
         
            -
            # 
     | 
| 
       4 
     | 
    
         
            -
            #
         
     | 
| 
       5 
     | 
    
         
            -
            #
         
     | 
| 
       6 
     | 
    
         
            -
            # 
     | 
| 
       7 
     | 
    
         
            -
            # 
     | 
| 
       8 
     | 
    
         
            -
            # 
     | 
| 
       9 
     | 
    
         
            -
            # 
     | 
| 
       10 
     | 
    
         
            -
            #
         
     | 
| 
       11 
     | 
    
         
            -
            # 
     | 
| 
       12 
     | 
    
         
            -
            # 
     | 
| 
       13 
     | 
    
         
            -
            #
         
     | 
| 
       14 
     | 
    
         
            -
            # 
     | 
| 
       15 
     | 
    
         
            -
            # 
     | 
| 
       16 
     | 
    
         
            -
            #      
     | 
| 
       17 
     | 
    
         
            -
            #      
     | 
| 
       18 
     | 
    
         
            -
            #      
     | 
| 
       19 
     | 
    
         
            -
            # 
     | 
| 
       20 
     | 
    
         
            -
            #
         
     | 
| 
       21 
     | 
    
         
            -
            # 
     | 
| 
       22 
     | 
    
         
            -
            # 
     | 
| 
       23 
     | 
    
         
            -
            # 
     | 
| 
       24 
     | 
    
         
            -
            #      
     | 
| 
       25 
     | 
    
         
            -
            # 
     | 
| 
       26 
     | 
    
         
            -
            #
         
     | 
| 
       27 
     | 
    
         
            -
            # 
     | 
| 
       28 
     | 
    
         
            -
            # 
     | 
| 
       29 
     | 
    
         
            -
            # 
     | 
| 
       30 
     | 
    
         
            -
            #      
     | 
| 
       31 
     | 
    
         
            -
            #      
     | 
| 
       32 
     | 
    
         
            -
            #      
     | 
| 
       33 
     | 
    
         
            -
            # 
     | 
| 
       34 
     | 
    
         
            -
            #
         
     | 
| 
       35 
     | 
    
         
            -
            # 
     | 
| 
       36 
     | 
    
         
            -
            # 
     | 
| 
       37 
     | 
    
         
            -
            #      
     | 
| 
       38 
     | 
    
         
            -
            # 
     | 
| 
       39 
     | 
    
         
            -
            #
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
               
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            module GraphQL
         
     | 
| 
      
 2 
     | 
    
         
            +
              # {Field}s belong to {ObjectType}s and {InterfaceType}s.
         
     | 
| 
      
 3 
     | 
    
         
            +
              #
         
     | 
| 
      
 4 
     | 
    
         
            +
              # They're usually created with the `field` helper. If you create it by hand, make sure {#name} is a String.
         
     | 
| 
      
 5 
     | 
    
         
            +
              #
         
     | 
| 
      
 6 
     | 
    
         
            +
              #
         
     | 
| 
      
 7 
     | 
    
         
            +
              # @example creating a field
         
     | 
| 
      
 8 
     | 
    
         
            +
              #   GraphQL::ObjectType.define do
         
     | 
| 
      
 9 
     | 
    
         
            +
              #     field :name, types.String, "The name of this thing "
         
     | 
| 
      
 10 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 11 
     | 
    
         
            +
              #
         
     | 
| 
      
 12 
     | 
    
         
            +
              # @example handling a circular reference
         
     | 
| 
      
 13 
     | 
    
         
            +
              #   # If the field's type isn't defined yet, you have two options:
         
     | 
| 
      
 14 
     | 
    
         
            +
              #
         
     | 
| 
      
 15 
     | 
    
         
            +
              #   GraphQL::ObjectType.define do
         
     | 
| 
      
 16 
     | 
    
         
            +
              #     # If you pass a Proc, it will be evaluated at schema build-time
         
     | 
| 
      
 17 
     | 
    
         
            +
              #     field :city, -> { CityType }
         
     | 
| 
      
 18 
     | 
    
         
            +
              #     # If you pass a String, it will be looked up in the global namespace at schema build-time
         
     | 
| 
      
 19 
     | 
    
         
            +
              #     field :country, "CountryType"
         
     | 
| 
      
 20 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 21 
     | 
    
         
            +
              #
         
     | 
| 
      
 22 
     | 
    
         
            +
              # @example creating a field that accesses a different property on the object
         
     | 
| 
      
 23 
     | 
    
         
            +
              #   GraphQL::ObjectType.define do
         
     | 
| 
      
 24 
     | 
    
         
            +
              #     # use the `property` option:
         
     | 
| 
      
 25 
     | 
    
         
            +
              #     field :firstName, types.String, property: :first_name
         
     | 
| 
      
 26 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 27 
     | 
    
         
            +
              #
         
     | 
| 
      
 28 
     | 
    
         
            +
              # @example defining a field, then attaching it to a type
         
     | 
| 
      
 29 
     | 
    
         
            +
              #   name_field = GraphQL::Field.define do
         
     | 
| 
      
 30 
     | 
    
         
            +
              #     name("Name")
         
     | 
| 
      
 31 
     | 
    
         
            +
              #     type(!types.String)
         
     | 
| 
      
 32 
     | 
    
         
            +
              #     description("The name of this thing")
         
     | 
| 
      
 33 
     | 
    
         
            +
              #     resolve -> (object, arguments, context) { object.name }
         
     | 
| 
      
 34 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 35 
     | 
    
         
            +
              #
         
     | 
| 
      
 36 
     | 
    
         
            +
              #   NamedType = GraphQL::ObjectType.define do
         
     | 
| 
      
 37 
     | 
    
         
            +
              #     # use the `field` option:
         
     | 
| 
      
 38 
     | 
    
         
            +
              #     field :name, field: name_field
         
     | 
| 
      
 39 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 40 
     | 
    
         
            +
              #
         
     | 
| 
      
 41 
     | 
    
         
            +
              class Field
         
     | 
| 
      
 42 
     | 
    
         
            +
                include GraphQL::Define::InstanceDefinable
         
     | 
| 
      
 43 
     | 
    
         
            +
                accepts_definitions :name, :description, :resolve, :type, :property, :deprecation_reason, argument: GraphQL::Define::AssignArgument
         
     | 
| 
       43 
44 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                attr_accessor :deprecation_reason, :name, :description, :type, :property
         
     | 
| 
      
 46 
     | 
    
         
            +
                attr_reader :resolve_proc
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
                # @return [String] The name of this field on its {GraphQL::ObjectType} (or {GraphQL::InterfaceType})
         
     | 
| 
      
 49 
     | 
    
         
            +
                attr_reader :name
         
     | 
| 
       49 
50 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
                # @return [Hash<String, GraphQL::Argument>] Map String argument names to their {GraphQL::Argument} implementations
         
     | 
| 
      
 52 
     | 
    
         
            +
                attr_accessor :arguments
         
     | 
| 
       52 
53 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 55 
     | 
    
         
            +
                  @arguments = {}
         
     | 
| 
      
 56 
     | 
    
         
            +
                  @resolve_proc = build_default_resolver
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
       57 
58 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 59 
     | 
    
         
            +
                # Get a value for this field
         
     | 
| 
      
 60 
     | 
    
         
            +
                # @example resolving a field value
         
     | 
| 
      
 61 
     | 
    
         
            +
                #   field.resolve(obj, args, ctx)
         
     | 
| 
      
 62 
     | 
    
         
            +
                #
         
     | 
| 
      
 63 
     | 
    
         
            +
                # @param object [Object] The object this field belongs to
         
     | 
| 
      
 64 
     | 
    
         
            +
                # @param arguments [Hash] Arguments declared in the query
         
     | 
| 
      
 65 
     | 
    
         
            +
                # @param context [GraphQL::Query::Context]
         
     | 
| 
      
 66 
     | 
    
         
            +
                def resolve(object, arguments, context)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  @resolve_proc.call(object, arguments, context)
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
       68 
69 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
                def resolve=(resolve_proc)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  @resolve_proc = resolve_proc || build_default_resolver
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
       72 
73 
     | 
    
         | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
      
 74 
     | 
    
         
            +
                # Get the return type for this field.
         
     | 
| 
      
 75 
     | 
    
         
            +
                def type
         
     | 
| 
      
 76 
     | 
    
         
            +
                  case @type
         
     | 
| 
      
 77 
     | 
    
         
            +
                  when Proc
         
     | 
| 
      
 78 
     | 
    
         
            +
                    # lazy-eval it
         
     | 
| 
      
 79 
     | 
    
         
            +
                    @type = @type.call
         
     | 
| 
      
 80 
     | 
    
         
            +
                  when String
         
     | 
| 
      
 81 
     | 
    
         
            +
                    # Get a constant by this name
         
     | 
| 
      
 82 
     | 
    
         
            +
                    @type = Object.const_get(@type)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  else
         
     | 
| 
      
 84 
     | 
    
         
            +
                    @type
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
       84 
86 
     | 
    
         
             
                end
         
     | 
| 
       85 
     | 
    
         
            -
              end
         
     | 
| 
       86 
87 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
      
 88 
     | 
    
         
            +
                # You can only set a field's name _once_ -- this to prevent
         
     | 
| 
      
 89 
     | 
    
         
            +
                # passing the same {Field} to multiple `.field` calls.
         
     | 
| 
      
 90 
     | 
    
         
            +
                #
         
     | 
| 
      
 91 
     | 
    
         
            +
                # This is important because {#name} may be used by {#resolve}.
         
     | 
| 
      
 92 
     | 
    
         
            +
                def name=(new_name)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  if !new_name.is_a?(String)
         
     | 
| 
      
 94 
     | 
    
         
            +
                    raise ArgumentError.new("GraphQL field names must be strings; cannot use #{new_name.inspect} (#{new_name.class.name}) as a field name.") unless new_name.is_a?(String)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  elsif @name.nil?
         
     | 
| 
      
 96 
     | 
    
         
            +
                    @name = new_name
         
     | 
| 
      
 97 
     | 
    
         
            +
                  else
         
     | 
| 
      
 98 
     | 
    
         
            +
                    raise("Can't rename an already-named field. (Tried to rename \"#{@name}\" to \"#{new_name}\".) If you're passing a field with the `field:` argument, make sure it's an unused instance of GraphQL::Field.")
         
     | 
| 
      
 99 
     | 
    
         
            +
                  end
         
     | 
| 
       96 
100 
     | 
    
         
             
                end
         
     | 
| 
       97 
     | 
    
         
            -
              end
         
     | 
| 
       98 
101 
     | 
    
         | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
      
 102 
     | 
    
         
            +
                def to_s
         
     | 
| 
      
 103 
     | 
    
         
            +
                  "<Field: #{name || "not-named"}>"
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
       102 
105 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 106 
     | 
    
         
            +
                private
         
     | 
| 
       104 
107 
     | 
    
         | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
      
 108 
     | 
    
         
            +
                def build_default_resolver
         
     | 
| 
      
 109 
     | 
    
         
            +
                  -> (obj, args, ctx) do
         
     | 
| 
      
 110 
     | 
    
         
            +
                    resolve_method = self.property || self.name
         
     | 
| 
      
 111 
     | 
    
         
            +
                    obj.public_send(resolve_method)
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
       109 
113 
     | 
    
         
             
                end
         
     | 
| 
       110 
114 
     | 
    
         
             
              end
         
     | 
| 
       111 
115 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,66 +1,68 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
            #
         
     | 
| 
       3 
     | 
    
         
            -
            # 
     | 
| 
       4 
     | 
    
         
            -
            # 
     | 
| 
       5 
     | 
    
         
            -
            # 
     | 
| 
       6 
     | 
    
         
            -
            #      
     | 
| 
       7 
     | 
    
         
            -
            #     input_field : 
     | 
| 
       8 
     | 
    
         
            -
            # 
     | 
| 
       9 
     | 
    
         
            -
            #
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
      
 1 
     | 
    
         
            +
            module GraphQL
         
     | 
| 
      
 2 
     | 
    
         
            +
              # A complex input type for a field argument.
         
     | 
| 
      
 3 
     | 
    
         
            +
              #
         
     | 
| 
      
 4 
     | 
    
         
            +
              # @example An input type with name and number
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   PlayerInput = GraphQL::InputObjectType.define do
         
     | 
| 
      
 6 
     | 
    
         
            +
              #     name("Player")
         
     | 
| 
      
 7 
     | 
    
         
            +
              #     input_field :name, !types.String
         
     | 
| 
      
 8 
     | 
    
         
            +
              #     input_field :number, !types.Int
         
     | 
| 
      
 9 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 10 
     | 
    
         
            +
              #
         
     | 
| 
      
 11 
     | 
    
         
            +
              class InputObjectType < GraphQL::BaseType
         
     | 
| 
      
 12 
     | 
    
         
            +
                accepts_definitions input_field: GraphQL::Define::AssignArgument
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                # @return [Hash<String, GraphQL::Argument>] Map String argument names to their {GraphQL::Argument} implementations
         
     | 
| 
      
 15 
     | 
    
         
            +
                attr_accessor :arguments
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
                alias :input_fields :arguments
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @arguments = {}
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
                def kind
         
     | 
| 
      
 24 
     | 
    
         
            +
                  GraphQL::TypeKinds::INPUT_OBJECT
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
                def validate_non_null_input(input)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  result = GraphQL::Query::InputValidationResult.new
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
                  # Items in the input that are unexpected
         
     | 
| 
      
 31 
     | 
    
         
            +
                  input.each do |name, value|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    if arguments[name].nil?
         
     | 
| 
      
 33 
     | 
    
         
            +
                      result.add_problem("Field is not defined on #{self.name}", [name])
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
       33 
35 
     | 
    
         
             
                  end
         
     | 
| 
       34 
     | 
    
         
            -
                end
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                  # Items in the input that are expected, but have invalid values
         
     | 
| 
      
 38 
     | 
    
         
            +
                  invalid_fields = arguments.map do |name, field|
         
     | 
| 
      
 39 
     | 
    
         
            +
                    field_result = field.type.validate_input(input[name])
         
     | 
| 
      
 40 
     | 
    
         
            +
                    if !field_result.valid?
         
     | 
| 
      
 41 
     | 
    
         
            +
                      result.merge_result!(name, field_result)
         
     | 
| 
      
 42 
     | 
    
         
            +
                    end
         
     | 
| 
       41 
43 
     | 
    
         
             
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  result
         
     | 
| 
       42 
46 
     | 
    
         
             
                end
         
     | 
| 
       43 
47 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                 
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
                def coerce_non_null_input(value)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  input_values = {}
         
     | 
| 
       46 
50 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
                  arguments.each do |input_key, input_field_defn|
         
     | 
| 
      
 52 
     | 
    
         
            +
                    field_value = value[input_key]
         
     | 
| 
      
 53 
     | 
    
         
            +
                    field_value = input_field_defn.type.coerce_input(field_value)
         
     | 
| 
       49 
54 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
                    # Try getting the default value
         
     | 
| 
      
 56 
     | 
    
         
            +
                    if field_value.nil?
         
     | 
| 
      
 57 
     | 
    
         
            +
                      field_value = input_field_defn.default_value
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
       53 
59 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                     
     | 
| 
      
 60 
     | 
    
         
            +
                    if !field_value.nil?
         
     | 
| 
      
 61 
     | 
    
         
            +
                      input_values[input_key] = field_value
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
       57 
63 
     | 
    
         
             
                  end
         
     | 
| 
       58 
64 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                   
     | 
| 
       60 
     | 
    
         
            -
                    input_values[input_key] = field_value
         
     | 
| 
       61 
     | 
    
         
            -
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  GraphQL::Query::Arguments.new(input_values)
         
     | 
| 
       62 
66 
     | 
    
         
             
                end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                GraphQL::Query::Arguments.new(input_values)
         
     | 
| 
       65 
67 
     | 
    
         
             
              end
         
     | 
| 
       66 
68 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,41 +1,38 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
            #
         
     | 
| 
       3 
     | 
    
         
            -
            # 
     | 
| 
       4 
     | 
    
         
            -
            # 
     | 
| 
       5 
     | 
    
         
            -
            # 
     | 
| 
       6 
     | 
    
         
            -
            #      
     | 
| 
       7 
     | 
    
         
            -
            #
         
     | 
| 
       8 
     | 
    
         
            -
            # 
     | 
| 
       9 
     | 
    
         
            -
            #     field : 
     | 
| 
       10 
     | 
    
         
            -
            #     field : 
     | 
| 
       11 
     | 
    
         
            -
            # 
     | 
| 
       12 
     | 
    
         
            -
            #
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
               
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            module GraphQL
         
     | 
| 
      
 2 
     | 
    
         
            +
              # A collection of types which implement the same fields
         
     | 
| 
      
 3 
     | 
    
         
            +
              #
         
     | 
| 
      
 4 
     | 
    
         
            +
              # @example An interface with three required fields
         
     | 
| 
      
 5 
     | 
    
         
            +
              #   DeviceInterface = GraphQL::InterfaceType.define do
         
     | 
| 
      
 6 
     | 
    
         
            +
              #     name("Device")
         
     | 
| 
      
 7 
     | 
    
         
            +
              #     description("Hardware devices for computing")
         
     | 
| 
      
 8 
     | 
    
         
            +
              #
         
     | 
| 
      
 9 
     | 
    
         
            +
              #     field :ram, types.String
         
     | 
| 
      
 10 
     | 
    
         
            +
              #     field :processor, ProcessorType
         
     | 
| 
      
 11 
     | 
    
         
            +
              #     field :release_year, types.Int
         
     | 
| 
      
 12 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              class InterfaceType < GraphQL::BaseType
         
     | 
| 
      
 15 
     | 
    
         
            +
                include GraphQL::BaseType::HasPossibleTypes
         
     | 
| 
      
 16 
     | 
    
         
            +
                accepts_definitions :resolve_type, field: GraphQL::Define::AssignObjectField
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
                attr_accessor :fields
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @fields = {}
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
                def kind
         
     | 
| 
      
 25 
     | 
    
         
            +
                  GraphQL::TypeKinds::INTERFACE
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
       26 
27 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
              # @return [GraphQL::Field] The defined field for `field_name`
         
     | 
| 
       33 
     | 
    
         
            -
              def get_field(field_name)
         
     | 
| 
       34 
     | 
    
         
            -
                fields[field_name]
         
     | 
| 
       35 
     | 
    
         
            -
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
                # @return [GraphQL::Field] The defined field for `field_name`
         
     | 
| 
      
 29 
     | 
    
         
            +
                def get_field(field_name)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  fields[field_name]
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
       36 
32 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 33 
     | 
    
         
            +
                # @return [Array<GraphQL::Field>] All fields on this type
         
     | 
| 
      
 34 
     | 
    
         
            +
                def all_fields
         
     | 
| 
      
 35 
     | 
    
         
            +
                  fields.values
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
       40 
37 
     | 
    
         
             
              end
         
     | 
| 
       41 
38 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,24 +3,25 @@ module GraphQL 
     | 
|
| 
       3 
3 
     | 
    
         
             
              end
         
     | 
| 
       4 
4 
     | 
    
         
             
            end
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            require  
     | 
| 
       7 
     | 
    
         
            -
            require  
     | 
| 
       8 
     | 
    
         
            -
            require  
     | 
| 
       9 
     | 
    
         
            -
            require  
     | 
| 
      
 6 
     | 
    
         
            +
            require "graphql/introspection/typename_field"
         
     | 
| 
      
 7 
     | 
    
         
            +
            require "graphql/introspection/input_value_type"
         
     | 
| 
      
 8 
     | 
    
         
            +
            require "graphql/introspection/enum_value_type"
         
     | 
| 
      
 9 
     | 
    
         
            +
            require "graphql/introspection/type_kind_enum"
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
            require  
     | 
| 
       12 
     | 
    
         
            -
            require  
     | 
| 
       13 
     | 
    
         
            -
            require  
     | 
| 
       14 
     | 
    
         
            -
            require  
     | 
| 
       15 
     | 
    
         
            -
            require  
     | 
| 
       16 
     | 
    
         
            -
            require  
     | 
| 
      
 11 
     | 
    
         
            +
            require "graphql/introspection/fields_field"
         
     | 
| 
      
 12 
     | 
    
         
            +
            require "graphql/introspection/of_type_field"
         
     | 
| 
      
 13 
     | 
    
         
            +
            require "graphql/introspection/input_fields_field"
         
     | 
| 
      
 14 
     | 
    
         
            +
            require "graphql/introspection/possible_types_field"
         
     | 
| 
      
 15 
     | 
    
         
            +
            require "graphql/introspection/enum_values_field"
         
     | 
| 
      
 16 
     | 
    
         
            +
            require "graphql/introspection/interfaces_field"
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            require  
     | 
| 
       19 
     | 
    
         
            -
            require  
     | 
| 
       20 
     | 
    
         
            -
            require  
     | 
| 
      
 18 
     | 
    
         
            +
            require "graphql/introspection/type_type"
         
     | 
| 
      
 19 
     | 
    
         
            +
            require "graphql/introspection/arguments_field"
         
     | 
| 
      
 20 
     | 
    
         
            +
            require "graphql/introspection/field_type"
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
            require  
     | 
| 
       23 
     | 
    
         
            -
            require  
     | 
| 
       24 
     | 
    
         
            -
            require  
     | 
| 
       25 
     | 
    
         
            -
            require  
     | 
| 
       26 
     | 
    
         
            -
            require  
     | 
| 
      
 22 
     | 
    
         
            +
            require "graphql/introspection/directive_location_enum"
         
     | 
| 
      
 23 
     | 
    
         
            +
            require "graphql/introspection/directive_type"
         
     | 
| 
      
 24 
     | 
    
         
            +
            require "graphql/introspection/schema_type"
         
     | 
| 
      
 25 
     | 
    
         
            +
            require "graphql/introspection/schema_field"
         
     | 
| 
      
 26 
     | 
    
         
            +
            require "graphql/introspection/type_by_name_field"
         
     | 
| 
      
 27 
     | 
    
         
            +
            require "graphql/introspection/introspection_query"
         
     |