graphql 0.19.4 → 1.0.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +5 -0
  3. data/lib/graphql/define/assign_enum_value.rb +4 -3
  4. data/lib/graphql/enum_type.rb +3 -10
  5. data/lib/graphql/language/generation.rb +6 -2
  6. data/lib/graphql/language/parser.rb +270 -270
  7. data/lib/graphql/language/parser.y +2 -2
  8. data/lib/graphql/language/parser_tests.rb +2 -2
  9. data/lib/graphql/query.rb +33 -38
  10. data/lib/graphql/query/serial_execution/field_resolution.rb +29 -33
  11. data/lib/graphql/query/serial_execution/value_resolution.rb +5 -2
  12. data/lib/graphql/query/variables.rb +5 -1
  13. data/lib/graphql/relay/base_connection.rb +5 -16
  14. data/lib/graphql/relay/mutation.rb +0 -17
  15. data/lib/graphql/schema.rb +2 -10
  16. data/lib/graphql/schema/loader.rb +1 -1
  17. data/lib/graphql/schema/printer.rb +1 -1
  18. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +1 -1
  19. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +3 -2
  20. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +10 -6
  21. data/lib/graphql/static_validation/type_stack.rb +2 -2
  22. data/lib/graphql/static_validation/validator.rb +1 -1
  23. data/lib/graphql/unresolved_type_error.rb +0 -5
  24. data/lib/graphql/version.rb +1 -1
  25. data/readme.md +3 -79
  26. data/spec/graphql/language/parser_spec.rb +1 -1
  27. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +4 -6
  28. data/spec/graphql/relay/base_connection_spec.rb +19 -0
  29. data/spec/graphql/relay/mutation_spec.rb +1 -1
  30. data/spec/graphql/relay/relation_connection_spec.rb +7 -0
  31. data/spec/graphql/schema/printer_spec.rb +6 -2
  32. data/spec/graphql/schema/timeout_middleware_spec.rb +3 -2
  33. data/spec/graphql/static_validation/validator_spec.rb +1 -1
  34. data/spec/spec_helper.rb +1 -3
  35. data/spec/support/static_validation_helpers.rb +1 -1
  36. metadata +5 -44
@@ -57,7 +57,7 @@ module GraphQL
57
57
  module FragmentWithTypeStrategy
58
58
  def push(stack, node)
59
59
  object_type = if node.type
60
- stack.schema.types.fetch(node.type, nil)
60
+ stack.schema.types.fetch(node.type.name, nil)
61
61
  else
62
62
  stack.object_types.last
63
63
  end
@@ -86,7 +86,7 @@ module GraphQL
86
86
  extend FragmentWithTypeStrategy
87
87
  module_function
88
88
  def push_path_member(stack, node)
89
- stack.path.push("...#{node.type ? " on #{node.type}" : ""}")
89
+ stack.path.push("...#{node.type ? " on #{node.type.to_query_string}" : ""}")
90
90
  end
91
91
  end
92
92
 
@@ -33,7 +33,7 @@ module GraphQL
33
33
  context.visitor.visit
34
34
 
35
35
  {
36
- errors: context.errors.map(&:to_h),
36
+ errors: context.errors,
37
37
  # If there were errors, the irep is garbage
38
38
  irep: context.errors.none? ? rewrite.operations : nil,
39
39
  }
@@ -8,9 +8,4 @@ module GraphQL
8
8
  super(message)
9
9
  end
10
10
  end
11
-
12
- class ObjectType
13
- # @deprecated Use {GraphQL::UnresolvedTypeError} instead
14
- UnresolvedTypeError = GraphQL::UnresolvedTypeError
15
- end
16
11
  end
@@ -1,3 +1,3 @@
1
1
  module GraphQL
2
- VERSION = "0.19.4"
2
+ VERSION = "1.0.0"
3
3
  end
data/readme.md CHANGED
@@ -24,63 +24,9 @@ gem 'graphql'
24
24
  $ bundle install
25
25
  ```
26
26
 
27
- ## Overview
27
+ ## Getting Started
28
28
 
29
- #### Declare types & build a schema
30
-
31
- ```ruby
32
- # Declare a type...
33
- PostType = GraphQL::ObjectType.define do
34
- name "Post"
35
- description "A blog post"
36
-
37
- field :id, !types.ID
38
- field :title, !types.String
39
- field :body, !types.String
40
- field :comments, types[!CommentType]
41
- end
42
-
43
- # ...and a query root
44
- QueryType = GraphQL::ObjectType.define do
45
- name "Query"
46
- description "The query root of this schema"
47
-
48
- field :post do
49
- type PostType
50
- argument :id, !types.ID
51
- resolve ->(obj, args, ctx) { Post.find(args["id"]) }
52
- end
53
- end
54
-
55
- # Then create your schema
56
- Schema = GraphQL::Schema.define do
57
- query QueryType
58
- max_depth 8
59
- end
60
- ```
61
-
62
- #### Execute queries
63
-
64
- Execute GraphQL queries on a given schema, from a query string.
65
-
66
- ```ruby
67
- result_hash = Schema.execute(query_string)
68
- # {
69
- # "data" => {
70
- # "post" => {
71
- # "id" => 1,
72
- # "title" => "GraphQL is nice"
73
- # }
74
- # }
75
- # }
76
- ```
77
-
78
- #### Use with Relay
79
-
80
- If you're building a backend for [Relay](http://facebook.github.io/relay/), you'll need:
81
-
82
- - A JSON dump of the schema, which you can get by sending [`GraphQL::Introspection::INTROSPECTION_QUERY`](https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/introspection/introspection_query.rb)
83
- - Relay-specific helpers for GraphQL, see [`GraphQL::Relay`](http://www.rubydoc.info/github/rmosolgo/graphql-ruby/file/guides/relay.md)
29
+ See "Getting Started" on the [website](https://rmosolgo.github.io/graphql-ruby/) or on [GitHub](https://github.com/rmosolgo/graphql-ruby/blob/master/guides/index.md)
84
30
 
85
31
  ## Goals
86
32
 
@@ -94,23 +40,7 @@ If you're building a backend for [Relay](http://facebook.github.io/relay/), you'
94
40
  - __Report bugs__ by posting a description, full stack trace, and all relevant code in a [GitHub issue](https://github.com/rmosolgo/graphql-ruby/issues).
95
41
  - __Features & patches__ are welcome! Consider discussing it in an [issue](https://github.com/rmosolgo/graphql-ruby/issues) or in the [#ruby channel on Slack](https://graphql-slack.herokuapp.com/) to make sure we're on the same page.
96
42
  - __Run the tests__ with `rake test` or start up guard with `bundle exec guard`.
97
- - __Build the site__ with `rake site:serve`, then visit `localhost:4000`.
98
-
99
- ## Related Projects
100
-
101
- ### Code
102
-
103
- - `graphql-ruby` + Rails demo ([src](https://github.com/rmosolgo/graphql-ruby-demo) / [heroku](http://graphql-ruby-demo.herokuapp.com))
104
- - [`graphql-batch`](https://github.com/shopify/graphql-batch), a batched query execution strategy
105
- - [`graphql-libgraphqlparser`](https://github.com/rmosolgo/graphql-libgraphqlparser-ruby), bindings to [libgraphqlparser](https://github.com/graphql/libgraphqlparser), a C-level parser.
106
-
107
- ### Blog Posts
108
-
109
- - Building a blog in GraphQL and Relay on Rails [Introduction](https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-getting-started-955a49d251de), [Part 1]( https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-creating-types-and-schema-b3f9b232ccfc), [Part 2](https://medium.com/@gauravtiwari/graphql-and-relay-on-rails-first-relay-powered-react-component-cb3f9ee95eca)
110
- - https://medium.com/@khor/relay-facebook-on-rails-8b4af2057152
111
- - https://blog.jacobwgillespie.com/from-rest-to-graphql-b4e95e94c26b#.4cjtklrwt
112
- - http://mgiroux.me/2015/getting-started-with-rails-graphql-relay/
113
- - http://mgiroux.me/2015/uploading-files-using-relay-with-rails/
43
+ - __Build the site__ with `rake site:serve`, then visit `http://localhost:4000/graphql-ruby/`.
114
44
 
115
45
  ## To Do
116
46
 
@@ -141,10 +71,4 @@ If you're building a backend for [Relay](http://facebook.github.io/relay/), you'
141
71
  - Renaming fragments from local names to unique names
142
72
  - Support AST subclasses? This would be hard, I think classes are used as hash keys in many places.
143
73
  - Support object deep-copy (schema, type, field, argument)? To support multiple schemas based on the same types. ([discussion](https://github.com/rmosolgo/graphql-ruby/issues/269))
144
- - Improve the website
145
- - Feature the logo in the header
146
- - Split `readme.md` into `index.md` (a homepage with code samples) and a technical readme (how to install, link to homepage)
147
- - Move "Related projects" to a guide
148
- - Revisit guides, maybe split them into smaller, more specific pages
149
- - Put guide titles into the `<title />`
150
74
  - Document encrypted & versioned cursors
@@ -25,7 +25,7 @@ describe GraphQL::Language::Parser do
25
25
  assert fragment.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
26
26
  assert_equal nil, fragment.name
27
27
  assert_equal 1, fragment.selections.length
28
- assert_equal "NestedType", fragment.type
28
+ assert_equal "NestedType", fragment.type.name
29
29
  assert_equal 1, fragment.directives.length
30
30
  assert_equal [2, 7], fragment.position
31
31
  end
@@ -27,8 +27,6 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
27
27
  name "OtherObject"
28
28
  end
29
29
 
30
- OtherObject = Class.new
31
-
32
30
  query_root = GraphQL::ObjectType.define do
33
31
  name "Query"
34
32
  field :tomorrow, day_of_week_enum do
@@ -39,7 +37,7 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
39
37
  resolve ->(obj, args, ctx) { Object.new }
40
38
  end
41
39
  field :resolvesToWrongTypeInterface, interface do
42
- resolve ->(obj, args, ctx) { OtherObject.new }
40
+ resolve ->(obj, args, ctx) { :something }
43
41
  end
44
42
  end
45
43
 
@@ -47,7 +45,7 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
47
45
  query(query_root)
48
46
  orphan_types [some_object]
49
47
  resolve_type ->(obj, ctx) do
50
- if obj.is_a?(OtherObject)
48
+ if obj.is_a?(Symbol)
51
49
  other_object
52
50
  else
53
51
  nil
@@ -86,7 +84,7 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
86
84
  |}
87
85
 
88
86
  it "raises an error" do
89
- err = assert_raises(GraphQL::ObjectType::UnresolvedTypeError) { result }
87
+ err = assert_raises(GraphQL::UnresolvedTypeError) { result }
90
88
  expected_message = %|The value from "resolvesToNilInterface" on "Query" could not be resolved to "SomeInterface". (Received: nil, Expected: [SomeObject])|
91
89
  assert_equal expected_message, err.message
92
90
  end
@@ -100,7 +98,7 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
100
98
  |}
101
99
 
102
100
  it "raises an error" do
103
- err = assert_raises(GraphQL::ObjectType::UnresolvedTypeError) { result }
101
+ err = assert_raises(GraphQL::UnresolvedTypeError) { result }
104
102
  expected_message = %|The value from "resolvesToWrongTypeInterface" on "Query" could not be resolved to "SomeInterface". (Received: OtherObject, Expected: [SomeObject])|
105
103
  assert_equal expected_message, err.message
106
104
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe GraphQL::Relay::BaseConnection do
4
+
5
+ describe ".connection_for_nodes" do
6
+
7
+ it "resolves most specific connection type" do
8
+ class SpecialArray < Array; end
9
+ class SpecialArrayConnection < GraphQL::Relay::BaseConnection; end
10
+ GraphQL::Relay::BaseConnection.register_connection_implementation(SpecialArray, SpecialArrayConnection)
11
+
12
+ nodes = SpecialArray.new
13
+
14
+ GraphQL::Relay::BaseConnection.connection_for_nodes(nodes)
15
+ .must_equal SpecialArrayConnection
16
+ end
17
+
18
+ end
19
+ end
@@ -72,7 +72,7 @@ describe GraphQL::Relay::Mutation do
72
72
  GraphQL::Relay::Mutation.define do
73
73
  name "CustomReturnTypeTest"
74
74
  return_type custom_type
75
- resolve ->(input, ctx) {
75
+ resolve ->(obj, input, ctx) {
76
76
  OpenStruct.new(name: "Custom Return Type Test")
77
77
  }
78
78
  end
@@ -361,4 +361,11 @@ describe GraphQL::Relay::RelationConnection do
361
361
  assert_includes err.message, "item not found"
362
362
  end
363
363
  end
364
+
365
+ it "is chosen for a relation" do
366
+ relation = Base.where(faction_id: 1)
367
+ assert relation.is_a?(ActiveRecord::Relation)
368
+ connection = GraphQL::Relay::BaseConnection.connection_for_nodes(relation)
369
+ assert_equal GraphQL::Relay::RelationConnection, connection
370
+ end
364
371
  end
@@ -83,7 +83,7 @@ describe GraphQL::Schema::Printer do
83
83
 
84
84
  field :post do
85
85
  type post_type
86
- argument :id, !types.ID
86
+ argument :id, !types.ID, 'Post ID'
87
87
  argument :varied, variant_input_type, default_value: { id: "123", int: 234, float: 2.3, enum: :foo, sub: [{ string: "str" }] }
88
88
  resolve ->(obj, args, ctx) { Post.find(args["id"]) }
89
89
  end
@@ -440,7 +440,11 @@ type Post {
440
440
 
441
441
  # The query root of this schema
442
442
  type Query {
443
- post(id: ID!, varied: Varied = {id: \"123\", int: 234, float: 2.3, enum: FOO, sub: [{string: \"str\"}]}): Post
443
+ post(
444
+ # Post ID
445
+ id: ID!
446
+ varied: Varied = {id: \"123\", int: 234, float: 2.3, enum: FOO, sub: [{string: \"str\"}]}
447
+ ): Post
444
448
  }
445
449
 
446
450
  # Test
@@ -166,7 +166,7 @@ describe GraphQL::Schema::TimeoutMiddleware do
166
166
  describe "with a custom block" do
167
167
  let(:timeout_middleware) {
168
168
  GraphQL::Schema::TimeoutMiddleware.new(max_seconds: max_seconds) do |err, query|
169
- raise("Query timed out after 2s: #{query.class.name}")
169
+ raise("Query timed out after 2s: #{query.class.name} on #{query.context.ast_node.alias}")
170
170
  end
171
171
  }
172
172
  let(:query_string) {%|
@@ -180,7 +180,8 @@ describe GraphQL::Schema::TimeoutMiddleware do
180
180
  |}
181
181
 
182
182
  it "calls the block" do
183
- assert_raises(RuntimeError) { result }
183
+ err = assert_raises(RuntimeError) { result }
184
+ assert_equal "Query timed out after 2s: GraphQL::Query on d", err.message
184
185
  end
185
186
  end
186
187
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe GraphQL::StaticValidation::Validator do
4
4
  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema) }
5
5
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }
6
- let(:errors) { validator.validate(query)[:errors] }
6
+ let(:errors) { validator.validate(query)[:errors].map(&:to_h) }
7
7
 
8
8
 
9
9
  describe "validation order" do
@@ -8,9 +8,7 @@ require "benchmark"
8
8
  require "minitest/autorun"
9
9
  require "minitest/focus"
10
10
  require "minitest/reporters"
11
- require "pry"
12
- require 'pry-stack_explorer'
13
- Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
11
+ Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
14
12
 
15
13
  Minitest::Spec.make_my_diffs_pretty!
16
14
 
@@ -14,7 +14,7 @@ module StaticValidationHelpers
14
14
  target_schema = schema
15
15
  validator = GraphQL::StaticValidation::Validator.new(schema: target_schema)
16
16
  query = GraphQL::Query.new(target_schema, query_string)
17
- validator.validate(query)[:errors]
17
+ validator.validate(query)[:errors].map(&:to_h)
18
18
  end
19
19
 
20
20
  def error_messages
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.19.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.4'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.10'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.10'
41
- - !ruby/object:Gem::Dependency
42
- name: pry-stack_explorer
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: guard
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -276,20 +248,6 @@ dependencies:
276
248
  - - ">="
277
249
  - !ruby/object:Gem::Version
278
250
  version: '0'
279
- - !ruby/object:Gem::Dependency
280
- name: html-proofer
281
- requirement: !ruby/object:Gem::Requirement
282
- requirements:
283
- - - ">="
284
- - !ruby/object:Gem::Version
285
- version: '0'
286
- type: :development
287
- prerelease: false
288
- version_requirements: !ruby/object:Gem::Requirement
289
- requirements:
290
- - - ">="
291
- - !ruby/object:Gem::Version
292
- version: '0'
293
251
  description: A GraphQL server implementation for Ruby. Includes schema definition,
294
252
  query parsing, static validation, type definition, and query execution.
295
253
  email:
@@ -298,6 +256,7 @@ executables: []
298
256
  extensions: []
299
257
  extra_rdoc_files: []
300
258
  files:
259
+ - ".yardopts"
301
260
  - MIT-LICENSE
302
261
  - lib/graphql.rb
303
262
  - lib/graphql/analysis.rb
@@ -497,6 +456,7 @@ files:
497
456
  - spec/graphql/query/variables_spec.rb
498
457
  - spec/graphql/query_spec.rb
499
458
  - spec/graphql/relay/array_connection_spec.rb
459
+ - spec/graphql/relay/base_connection_spec.rb
500
460
  - spec/graphql/relay/connection_field_spec.rb
501
461
  - spec/graphql/relay/connection_type_spec.rb
502
462
  - spec/graphql/relay/mutation_spec.rb
@@ -615,6 +575,7 @@ test_files:
615
575
  - spec/graphql/query/variables_spec.rb
616
576
  - spec/graphql/query_spec.rb
617
577
  - spec/graphql/relay/array_connection_spec.rb
578
+ - spec/graphql/relay/base_connection_spec.rb
618
579
  - spec/graphql/relay/connection_field_spec.rb
619
580
  - spec/graphql/relay/connection_type_spec.rb
620
581
  - spec/graphql/relay/mutation_spec.rb