graphql 0.10.1 → 0.10.2
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/language/parser.rb +1 -1
 - data/lib/graphql/language/transform.rb +1 -0
 - data/lib/graphql/schema/type_reducer.rb +4 -2
 - data/lib/graphql/version.rb +1 -1
 - data/readme.md +5 -1
 - data/spec/graphql/language/parser_spec.rb +1 -1
 - data/spec/graphql/language/transform_spec.rb +1 -1
 - data/spec/graphql/schema/type_reducer_spec.rb +13 -1
 - data/spec/support/calculator_schema.rb +73 -0
 - metadata +4 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a8c997dbb80987c2b0312c95913b8cb7bef898be
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f77f1a3b90d96887a93ee560f8dd5ba5370a4453
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 4f20614f4bcefc6ed7771c516046ae24581785ea25579e0bd5a8bdcad1cbd7d5eca7c981e59b4eec08bb54772cdb15c3f5f44f62eee1ea51d224e2c87608c821
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: a525157abbc09c4b1abd6e55a18b975305dbb93d8583709850bc159cb2e7d87ee62dd3b3d7fddf9188daa3e6c07f1bb83f2c8715c921c8b12b1e898e823dfbf0
         
     | 
| 
         @@ -97,7 +97,7 @@ module GraphQL 
     | 
|
| 
       97 
97 
     | 
    
         
             
                  rule(:value_input_object) { str("{") >> space? >> value_input_object_pair.repeat(1).as(:input_object) >> space? >> str("}") }
         
     | 
| 
       98 
98 
     | 
    
         
             
                  rule(:value_input_object_pair) { space? >> name.as(:input_object_name) >>  space? >> str(":") >> space? >> value.as(:input_object_value) >> separator? }
         
     | 
| 
       99 
99 
     | 
    
         
             
                  rule(:value_int) { (value_sign? >> match('\d').repeat(1)).as(:int) }
         
     | 
| 
       100 
     | 
    
         
            -
                  rule(:value_string) { str('"') >> value_string_char.repeat.as(:string) >> str('"')}
         
     | 
| 
      
 100 
     | 
    
         
            +
                  rule(:value_string) { str('"') >> value_string_char.repeat.maybe.as(:optional_string_content).as(:string) >> str('"')}
         
     | 
| 
       101 
101 
     | 
    
         
             
                  rule(:value_string_char) { value_string_escaped_char | value_string_escaped_unicode | value_string_source_char}
         
     | 
| 
       102 
102 
     | 
    
         
             
                  rule(:value_string_escaped_char) { str("\\") >> match('["\/bfnrt]') }
         
     | 
| 
       103 
103 
     | 
    
         
             
                  rule(:value_string_escaped_unicode) { str("\\") >> match('u[\dA-Fa-f]{4}')}
         
     | 
| 
         @@ -110,6 +110,7 @@ module GraphQL 
     | 
|
| 
       110 
110 
     | 
    
         
             
                    string.gsub!(UTF_8, &UTF_8_REPLACE)
         
     | 
| 
       111 
111 
     | 
    
         
             
                    string
         
     | 
| 
       112 
112 
     | 
    
         
             
                  }
         
     | 
| 
      
 113 
     | 
    
         
            +
                  rule(optional_string_content: simple(:v)) { v.to_s }
         
     | 
| 
       113 
114 
     | 
    
         
             
                  rule(variable: simple(:v)) { create_node(:VariableIdentifier, name: v.to_s, position_source: v) }
         
     | 
| 
       114 
115 
     | 
    
         
             
                  rule(enum: simple(:v)) { create_node(:Enum, name: v.to_s, position_source: v)}
         
     | 
| 
       115 
116 
     | 
    
         
             
                end
         
     | 
| 
         @@ -4,7 +4,6 @@ class GraphQL::Schema::TypeReducer 
     | 
|
| 
       4 
4 
     | 
    
         
             
              attr_reader :type, :existing_type_hash
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
              def initialize(type, existing_type_hash)
         
     | 
| 
       7 
     | 
    
         
            -
                type = type.nil? ? nil : type.unwrap
         
     | 
| 
       8 
7 
     | 
    
         
             
                validate_type(type)
         
     | 
| 
       9 
8 
     | 
    
         
             
                if type.respond_to?(:name) && existing_type_hash.fetch(type.name, nil).equal?(type)
         
     | 
| 
       10 
9 
     | 
    
         
             
                  @result = existing_type_hash
         
     | 
| 
         @@ -58,7 +57,10 @@ class GraphQL::Schema::TypeReducer 
     | 
|
| 
       58 
57 
     | 
    
         
             
              end
         
     | 
| 
       59 
58 
     | 
    
         | 
| 
       60 
59 
     | 
    
         
             
              def reduce_type(type, type_hash)
         
     | 
| 
       61 
     | 
    
         
            -
                 
     | 
| 
      
 60 
     | 
    
         
            +
                unless type.is_a?(GraphQL::BaseType)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  raise GraphQL::Schema::InvalidTypeError.new(type, ["Must be a GraphQL::BaseType"])
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
                self.class.new(type.unwrap, type_hash).result
         
     | 
| 
       62 
64 
     | 
    
         
             
              end
         
     | 
| 
       63 
65 
     | 
    
         | 
| 
       64 
66 
     | 
    
         
             
              def validate_type(type)
         
     | 
    
        data/lib/graphql/version.rb
    CHANGED
    
    
    
        data/readme.md
    CHANGED
    
    | 
         @@ -8,7 +8,11 @@ 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            A Ruby implementation of [GraphQL](http://graphql.org/).
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             -  
     | 
| 
      
 11 
     | 
    
         
            +
             - Guides
         
     | 
| 
      
 12 
     | 
    
         
            +
                 - [Introduction](https://github.com/rmosolgo/graphql-ruby/blob/master/guides/introduction.md)
         
     | 
| 
      
 13 
     | 
    
         
            +
                 - [Defining Your Schema](https://github.com/rmosolgo/graphql-ruby/blob/master/guides/defining_your_schema.md)
         
     | 
| 
      
 14 
     | 
    
         
            +
                 - [Executing Queries](https://github.com/rmosolgo/graphql-ruby/blob/master/guides/executing_queries.md)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       12 
16 
     | 
    
         
             
             - [API Documentation](http://www.rubydoc.info/github/rmosolgo/graphql-ruby)
         
     | 
| 
       13 
17 
     | 
    
         | 
| 
       14 
18 
     | 
    
         
             
            ## Installation
         
     | 
| 
         @@ -68,7 +68,7 @@ describe GraphQL::Language::Parser do 
     | 
|
| 
       68 
68 
     | 
    
         
             
                assert(parser.field.parse_with_debug(%|myField { name, id }|), 'gets subselections')
         
     | 
| 
       69 
69 
     | 
    
         
             
                assert(parser.field.parse_with_debug(%{myAlias: myField}), 'gets an alias')
         
     | 
| 
       70 
70 
     | 
    
         
             
                assert(parser.field.parse_with_debug(%{myField(intKey: 1, floatKey: 1.1e5)}), 'gets arguments')
         
     | 
| 
       71 
     | 
    
         
            -
                assert(parser.field.parse_with_debug('myAlias: myField(stringKey: "\"my_string\"", boolKey: false, objKey: { key : true }, otherObjKey: {key: true})'), 'gets alias and arguments')
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert(parser.field.parse_with_debug('myAlias: myField(stringKey: "\"my_string\"", emptyStringKey: "", boolKey: false, objKey: { key : true }, otherObjKey: {key: true})'), 'gets alias and arguments')
         
     | 
| 
       72 
72 
     | 
    
         
             
                assert(parser.field.parse_with_debug(%|myField @withFlag, @skip(if: true) { name, id }|), 'gets with directive')
         
     | 
| 
       73 
73 
     | 
    
         
             
              end
         
     | 
| 
       74 
74 
     | 
    
         | 
| 
         @@ -88,7 +88,7 @@ describe GraphQL::Language::Transform do 
     | 
|
| 
       88 
88 
     | 
    
         
             
              end
         
     | 
| 
       89 
89 
     | 
    
         | 
| 
       90 
90 
     | 
    
         
             
              it 'transforms fields' do
         
     | 
| 
       91 
     | 
    
         
            -
                res = get_result(%|best_pals: friends(first: 3, coolnessLevel: SO_COOL, query: {nice: {very: true}})|, parse: :field)
         
     | 
| 
      
 91 
     | 
    
         
            +
                res = get_result(%|best_pals: friends(first: 3, coolnessLevel: SO_COOL, query: {nice: {very: true}}, emptyStr: "")|, parse: :field)
         
     | 
| 
       92 
92 
     | 
    
         
             
                assert_equal(GraphQL::Language::Nodes::Field, res.class)
         
     | 
| 
       93 
93 
     | 
    
         
             
                assert_equal(1, res.line)
         
     | 
| 
       94 
94 
     | 
    
         
             
                assert_equal(1, res.col)
         
     | 
| 
         @@ -51,10 +51,22 @@ describe GraphQL::Schema::TypeReducer do 
     | 
|
| 
       51 
51 
     | 
    
         
             
                  end
         
     | 
| 
       52 
52 
     | 
    
         
             
                }
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
                 
     | 
| 
      
 54 
     | 
    
         
            +
                let(:another_invalid_type) {
         
     | 
| 
      
 55 
     | 
    
         
            +
                  GraphQL::ObjectType.define do
         
     | 
| 
      
 56 
     | 
    
         
            +
                    name "AnotherInvalidType"
         
     | 
| 
      
 57 
     | 
    
         
            +
                    field :someField, String
         
     | 
| 
      
 58 
     | 
    
         
            +
                  end
         
     | 
| 
      
 59 
     | 
    
         
            +
                }
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                it 'raises an InvalidTypeError when passed nil' do
         
     | 
| 
       55 
62 
     | 
    
         
             
                  reducer = GraphQL::Schema::TypeReducer.new(invalid_type, {})
         
     | 
| 
       56 
63 
     | 
    
         
             
                  assert_raises(GraphQL::Schema::InvalidTypeError) { reducer.result }
         
     | 
| 
       57 
64 
     | 
    
         
             
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                it 'raises an InvalidTypeError when passed an object that isnt a GraphQL::BaseType' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  reducer = GraphQL::Schema::TypeReducer.new(another_invalid_type, {})
         
     | 
| 
      
 68 
     | 
    
         
            +
                  assert_raises(GraphQL::Schema::InvalidTypeError) { reducer.result }
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
       58 
70 
     | 
    
         
             
              end
         
     | 
| 
       59 
71 
     | 
    
         | 
| 
       60 
72 
     | 
    
         
             
              describe 'when a schema has multiple types with the same name' do
         
     | 
| 
         @@ -0,0 +1,73 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # This GraphQL Schema performs operations on numbers.
         
     | 
| 
      
 2 
     | 
    
         
            +
            # It can perform operations on values you give it and return values
         
     | 
| 
      
 3 
     | 
    
         
            +
            # It also maintains some state which can be updated or read
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            # You can reduce a list of values to a single value
         
     | 
| 
      
 6 
     | 
    
         
            +
            REDUCERS = {
         
     | 
| 
      
 7 
     | 
    
         
            +
              "SUM" => -> (values) { [values.inject(&:+)] },
         
     | 
| 
      
 8 
     | 
    
         
            +
              "MAX" => :max.to_proc,
         
     | 
| 
      
 9 
     | 
    
         
            +
              "MIN" => :min.to_proc,
         
     | 
| 
      
 10 
     | 
    
         
            +
            }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ReducerEnum = GraphQL::EnumType.define do
         
     | 
| 
      
 13 
     | 
    
         
            +
              REDUCERS.map do |op_name, op_proc|
         
     | 
| 
      
 14 
     | 
    
         
            +
                value(op_name)
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            # You can make a new list by transforming each member
         
     | 
| 
      
 19 
     | 
    
         
            +
            MAPPERS = {
         
     | 
| 
      
 20 
     | 
    
         
            +
              "ADD" => -> (val, arg) { val + arg },
         
     | 
| 
      
 21 
     | 
    
         
            +
              "SUB" => -> (val, arg) { val - arg },
         
     | 
| 
      
 22 
     | 
    
         
            +
              "EQ" => -> (val, arg) { val == arg ? 1 : 0},
         
     | 
| 
      
 23 
     | 
    
         
            +
            }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            MapperEnum = GraphQL::EnumType.define do
         
     | 
| 
      
 26 
     | 
    
         
            +
              MAPPERS.map do |op_name, op_proc|
         
     | 
| 
      
 27 
     | 
    
         
            +
                value(op_name)
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            # Input a list of integers
         
     | 
| 
      
 32 
     | 
    
         
            +
            ListOfInts = GraphQL::INT_TYPE.to_list_type
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            # Expose a list of values and perform operations
         
     | 
| 
      
 35 
     | 
    
         
            +
            ValuesType = GraphQL::ObjectType.define do
         
     | 
| 
      
 36 
     | 
    
         
            +
              field :values, ListOfInts do
         
     | 
| 
      
 37 
     | 
    
         
            +
                resolve -> (obj, _args, _ctx) { obj }
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              # Get a single value based on the values in this list
         
     | 
| 
      
 41 
     | 
    
         
            +
              field :reduce, types.Int do
         
     | 
| 
      
 42 
     | 
    
         
            +
                argument :operation, !ReducerEnum
         
     | 
| 
      
 43 
     | 
    
         
            +
                resolve -> (obj, args, ctx)  {
         
     | 
| 
      
 44 
     | 
    
         
            +
                  reduce_name = args[:operation]
         
     | 
| 
      
 45 
     | 
    
         
            +
                  reduce_fn = REDUCERS[reduce_name]
         
     | 
| 
      
 46 
     | 
    
         
            +
                  reduce_fn.call(obj)
         
     | 
| 
      
 47 
     | 
    
         
            +
                }
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              # Handle self-referential fields by wrapping the type in a proc.
         
     | 
| 
      
 51 
     | 
    
         
            +
              # It will be lazy-eval'ed
         
     | 
| 
      
 52 
     | 
    
         
            +
              field :map, -> { ValuesType } do
         
     | 
| 
      
 53 
     | 
    
         
            +
                argument :operation, !MapperEnum
         
     | 
| 
      
 54 
     | 
    
         
            +
                argument :argument, !types.Int
         
     | 
| 
      
 55 
     | 
    
         
            +
                resolve -> (obj, args, ctx) {
         
     | 
| 
      
 56 
     | 
    
         
            +
                  op_arg = args[:argument]
         
     | 
| 
      
 57 
     | 
    
         
            +
                  op_name = args[:operation]
         
     | 
| 
      
 58 
     | 
    
         
            +
                  op_func = MAPPERS[op_name]
         
     | 
| 
      
 59 
     | 
    
         
            +
                  obj.map { |item| op_func.call(item, op_arg) }
         
     | 
| 
      
 60 
     | 
    
         
            +
                }
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
      
 62 
     | 
    
         
            +
            end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            QueryType = GraphQL::ObjectType.define do
         
     | 
| 
      
 65 
     | 
    
         
            +
              name("Query")
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
              field :perform, ValuesType do
         
     | 
| 
      
 68 
     | 
    
         
            +
                argument :initial, !ListOfInts
         
     | 
| 
      
 69 
     | 
    
         
            +
                resolve -> (obj, args, ctx) { args[:initial] }
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
            end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            CalculatorSchema = GraphQL::Schema.new(query: QueryType)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: graphql
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.10. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.10.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Robert Mosolgo
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015-10 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-11-10 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: parslet
         
     | 
| 
         @@ -313,6 +313,7 @@ files: 
     | 
|
| 
       313 
313 
     | 
    
         
             
            - spec/graphql/static_validation/validator_spec.rb
         
     | 
| 
       314 
314 
     | 
    
         
             
            - spec/graphql/union_type_spec.rb
         
     | 
| 
       315 
315 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
      
 316 
     | 
    
         
            +
            - spec/support/calculator_schema.rb
         
     | 
| 
       316 
317 
     | 
    
         
             
            - spec/support/dairy_app.rb
         
     | 
| 
       317 
318 
     | 
    
         
             
            - spec/support/dairy_data.rb
         
     | 
| 
       318 
319 
     | 
    
         
             
            - spec/support/star_wars_data.rb
         
     | 
| 
         @@ -394,6 +395,7 @@ test_files: 
     | 
|
| 
       394 
395 
     | 
    
         
             
            - spec/graphql/static_validation/validator_spec.rb
         
     | 
| 
       395 
396 
     | 
    
         
             
            - spec/graphql/union_type_spec.rb
         
     | 
| 
       396 
397 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
      
 398 
     | 
    
         
            +
            - spec/support/calculator_schema.rb
         
     | 
| 
       397 
399 
     | 
    
         
             
            - spec/support/dairy_app.rb
         
     | 
| 
       398 
400 
     | 
    
         
             
            - spec/support/dairy_data.rb
         
     | 
| 
       399 
401 
     | 
    
         
             
            - spec/support/star_wars_data.rb
         
     |