graphql 1.8.0.pre2 → 1.8.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +1 -1
  3. data/lib/graphql/deprecated_dsl.rb +2 -0
  4. data/lib/graphql/enum_type.rb +1 -1
  5. data/lib/graphql/field.rb +10 -1
  6. data/lib/graphql/input_object_type.rb +3 -1
  7. data/lib/graphql/introspection.rb +3 -10
  8. data/lib/graphql/introspection/base_object.rb +15 -0
  9. data/lib/graphql/introspection/directive_location_enum.rb +11 -7
  10. data/lib/graphql/introspection/directive_type.rb +23 -16
  11. data/lib/graphql/introspection/dynamic_fields.rb +11 -0
  12. data/lib/graphql/introspection/entry_points.rb +29 -0
  13. data/lib/graphql/introspection/enum_value_type.rb +16 -11
  14. data/lib/graphql/introspection/field_type.rb +21 -12
  15. data/lib/graphql/introspection/input_value_type.rb +26 -23
  16. data/lib/graphql/introspection/schema_field.rb +7 -2
  17. data/lib/graphql/introspection/schema_type.rb +36 -22
  18. data/lib/graphql/introspection/type_by_name_field.rb +10 -2
  19. data/lib/graphql/introspection/type_kind_enum.rb +10 -6
  20. data/lib/graphql/introspection/type_type.rb +85 -23
  21. data/lib/graphql/introspection/typename_field.rb +1 -0
  22. data/lib/graphql/language.rb +1 -0
  23. data/lib/graphql/language/document_from_schema_definition.rb +129 -37
  24. data/lib/graphql/language/generation.rb +3 -182
  25. data/lib/graphql/language/nodes.rb +12 -2
  26. data/lib/graphql/language/parser.rb +63 -55
  27. data/lib/graphql/language/parser.y +2 -1
  28. data/lib/graphql/language/printer.rb +351 -0
  29. data/lib/graphql/object_type.rb +1 -1
  30. data/lib/graphql/query.rb +1 -1
  31. data/lib/graphql/query/arguments.rb +24 -8
  32. data/lib/graphql/query/context.rb +3 -0
  33. data/lib/graphql/query/literal_input.rb +4 -1
  34. data/lib/graphql/railtie.rb +28 -6
  35. data/lib/graphql/schema.rb +42 -7
  36. data/lib/graphql/schema/enum.rb +1 -0
  37. data/lib/graphql/schema/field.rb +26 -5
  38. data/lib/graphql/schema/field/dynamic_resolve.rb +18 -9
  39. data/lib/graphql/schema/input_object.rb +2 -2
  40. data/lib/graphql/schema/introspection_system.rb +93 -0
  41. data/lib/graphql/schema/late_bound_type.rb +32 -0
  42. data/lib/graphql/schema/member.rb +21 -1
  43. data/lib/graphql/schema/member/build_type.rb +8 -6
  44. data/lib/graphql/schema/member/has_fields.rb +1 -1
  45. data/lib/graphql/schema/member/instrumentation.rb +3 -1
  46. data/lib/graphql/schema/member/list_type_proxy.rb +4 -0
  47. data/lib/graphql/schema/member/non_null_type_proxy.rb +4 -0
  48. data/lib/graphql/schema/object.rb +2 -1
  49. data/lib/graphql/schema/printer.rb +33 -266
  50. data/lib/graphql/schema/traversal.rb +74 -6
  51. data/lib/graphql/schema/validation.rb +3 -2
  52. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +6 -6
  53. data/lib/graphql/tracing/scout_tracing.rb +2 -2
  54. data/lib/graphql/upgrader/member.rb +463 -63
  55. data/lib/graphql/version.rb +1 -1
  56. data/spec/fixtures/upgrader/blame_range.original.rb +43 -0
  57. data/spec/fixtures/upgrader/blame_range.transformed.rb +31 -0
  58. data/spec/fixtures/upgrader/subscribable.original.rb +51 -0
  59. data/spec/fixtures/upgrader/subscribable.transformed.rb +46 -0
  60. data/spec/fixtures/upgrader/type_x.original.rb +35 -0
  61. data/spec/fixtures/upgrader/type_x.transformed.rb +35 -0
  62. data/spec/graphql/language/document_from_schema_definition_spec.rb +729 -296
  63. data/spec/graphql/language/generation_spec.rb +21 -186
  64. data/spec/graphql/language/nodes_spec.rb +21 -0
  65. data/spec/graphql/language/printer_spec.rb +203 -0
  66. data/spec/graphql/query/arguments_spec.rb +14 -4
  67. data/spec/graphql/query/context_spec.rb +17 -0
  68. data/spec/graphql/schema/build_from_definition_spec.rb +13 -4
  69. data/spec/graphql/schema/field_spec.rb +14 -0
  70. data/spec/graphql/schema/introspection_system_spec.rb +39 -0
  71. data/spec/graphql/schema/object_spec.rb +12 -1
  72. data/spec/graphql/schema/printer_spec.rb +14 -14
  73. data/spec/graphql/tracing/platform_tracing_spec.rb +2 -2
  74. data/spec/graphql/upgrader/member_spec.rb +274 -62
  75. data/spec/support/jazz.rb +75 -3
  76. metadata +38 -9
  77. data/lib/graphql/introspection/arguments_field.rb +0 -7
  78. data/lib/graphql/introspection/enum_values_field.rb +0 -18
  79. data/lib/graphql/introspection/fields_field.rb +0 -13
  80. data/lib/graphql/introspection/input_fields_field.rb +0 -12
  81. data/lib/graphql/introspection/interfaces_field.rb +0 -11
  82. data/lib/graphql/introspection/of_type_field.rb +0 -6
  83. data/lib/graphql/introspection/possible_types_field.rb +0 -11
@@ -2,200 +2,35 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe GraphQL::Language::Generation do
5
- let(:document) { GraphQL::Language::Parser.parse(query_string) }
6
- let(:query_string) {%|
7
- query getStuff($someVar: Int = 1, $anotherVar: [String!], $skipNested: Boolean! = false) @skip(if: false) {
8
- myField: someField(someArg: $someVar, ok: 1.4) @skip(if: $anotherVar) @thing(or: "Whatever")
9
- anotherField(someArg: [1, 2, 3]) {
10
- nestedField
11
- ...moreNestedFields @skip(if: $skipNested)
12
- }
13
- ... on OtherType @include(unless: false) {
14
- field(arg: [{key: "value", anotherKey: 0.9, anotherAnotherKey: WHATEVER}])
15
- anotherField
16
- }
17
- ... {
18
- id
19
- }
5
+ describe "#to_query_tring" do
6
+ let(:document) {
7
+ GraphQL.parse('type Query { a: String! }')
20
8
  }
21
9
 
22
- fragment moreNestedFields on NestedType @or(something: "ok") {
23
- anotherNestedField
24
- }
25
- |}
26
-
27
- describe ".generate" do
28
- it "generates query string" do
29
- assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
30
- end
31
-
32
- describe "inputs" do
33
- let(:query_string) {%|
34
- query {
35
- field(null_value: null, null_in_array: [1, null, 3], int: 3, float: 4.7e-24, bool: false, string: "☀︎🏆\\n escaped \\" unicode ¶ /", enum: ENUM_NAME, array: [7, 8, 9], object: {a: [1, 2, 3], b: {c: "4"}}, unicode_bom: "\xef\xbb\xbfquery")
36
- }
37
- |}
38
-
39
- it "generate" do
40
- assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
10
+ class CustomPrinter < GraphQL::Language::Printer
11
+ def print_field_definition(print_field_definition)
12
+ "<Field Hidden>"
41
13
  end
42
14
  end
43
15
 
44
- describe "schema" do
45
- describe "schema with convention names for root types" do
46
- let(:query_string) {<<-schema
47
- schema {
48
- query: Query
49
- mutation: Mutation
50
- subscription: Subscription
51
- }
52
- schema
53
- }
54
-
55
- it 'omits schema definition' do
56
- refute document.to_query_string =~ /schema/
57
- end
58
- end
59
-
60
- describe "schema with custom query root name" do
61
- let(:query_string) {<<-schema
62
- schema {
63
- query: MyQuery
64
- mutation: Mutation
65
- subscription: Subscription
66
- }
67
- schema
68
- }
69
-
70
- it 'includes schema definition' do
71
- assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
72
- end
73
- end
74
-
75
- describe "schema with custom mutation root name" do
76
- let(:query_string) {<<-schema
77
- schema {
78
- query: Query
79
- mutation: MyMutation
80
- subscription: Subscription
81
- }
82
- schema
83
- }
84
-
85
- it 'includes schema definition' do
86
- assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
87
- end
88
- end
89
-
90
- describe "schema with custom subscription root name" do
91
- let(:query_string) {<<-schema
92
- schema {
93
- query: Query
94
- mutation: Mutation
95
- subscription: MySubscription
96
- }
97
- schema
98
- }
99
-
100
- it 'includes schema definition' do
101
- assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
102
- end
103
- end
104
-
105
- describe "full featured schema" do
106
- # From: https://github.com/graphql/graphql-js/blob/bc96406ab44453a120da25a0bd6e2b0237119ddf/src/language/__tests__/schema-kitchen-sink.graphql
107
- let(:query_string) {<<-schema
108
- schema {
109
- query: QueryType
110
- mutation: MutationType
111
- }
112
-
113
- # Union description
114
- union AnnotatedUnion @onUnion = A | B
115
-
116
- type Foo implements Bar {
117
- one: Type
118
- two(argument: InputType!): Type
119
- three(argument: InputType, other: String): Int
120
- four(argument: String = "string"): String
121
- five(argument: [String] = ["string", "string"]): String
122
- six(argument: InputType = {key: "value"}): Type
123
- seven(argument: String = null): Type
124
- }
16
+ it "accepts a custom printer" do
17
+ expected = <<-SCHEMA
18
+ type Query {
19
+ a: String!
20
+ }
21
+ SCHEMA
125
22
 
126
- # Scalar description
127
- scalar CustomScalar
128
-
129
- type AnnotatedObject @onObject(arg: "value") {
130
- annotatedField(arg: Type = "default" @onArg): Type @onField
131
- }
132
-
133
- interface Bar {
134
- one: Type
135
- four(argument: String = "string"): String
136
- }
137
-
138
- # Enum description
139
- enum Site {
140
- # Enum value description
141
- DESKTOP
142
- MOBILE
143
- }
144
-
145
- interface AnnotatedInterface @onInterface {
146
- annotatedField(arg: Type @onArg): Type @onField
147
- }
148
-
149
- union Feed = Story | Article | Advert
150
-
151
- # Input description
152
- input InputType {
153
- key: String!
154
- answer: Int = 42
155
- }
156
-
157
- union AnnotatedUnion @onUnion = A | B
158
-
159
- scalar CustomScalar
160
-
161
- # Directive description
162
- directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
163
-
164
- scalar AnnotatedScalar @onScalar
165
-
166
- enum Site {
167
- DESKTOP
168
- MOBILE
169
- }
170
-
171
- enum AnnotatedEnum @onEnum {
172
- ANNOTATED_VALUE @onEnumValue
173
- OTHER_VALUE
174
- }
175
-
176
- input InputType {
177
- key: String!
178
- answer: Int = 42
179
- }
180
-
181
- input AnnotatedInput @onInputObjectType {
182
- annotatedField: Type @onField
183
- }
184
-
185
- directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
186
-
187
- directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
188
- schema
189
- }
23
+ assert_equal expected.chomp, GraphQL::Language::Generation.generate(document)
24
+ end
190
25
 
191
- it "generate" do
192
- assert_equal query_string.gsub(/^ /, "").strip, document.to_query_string
193
- end
26
+ it "accepts a custom printer" do
27
+ expected = <<-SCHEMA
28
+ type Query {
29
+ <Field Hidden>
30
+ }
31
+ SCHEMA
194
32
 
195
- it "doesn't mutate the document" do
196
- assert_equal document.to_query_string, document.to_query_string
197
- end
198
- end
33
+ assert_equal expected.chomp, GraphQL::Language::Generation.generate(document, printer: CustomPrinter.new)
199
34
  end
200
35
  end
201
36
  end
@@ -33,4 +33,25 @@ describe GraphQL::Language::Nodes::AbstractNode do
33
33
  assert_nil doc.filename
34
34
  end
35
35
  end
36
+
37
+ describe "#to_query_tring" do
38
+ let(:document) {
39
+ GraphQL.parse('type Query { a: String! }')
40
+ }
41
+
42
+ class CustomPrinter < GraphQL::Language::Printer
43
+ def print_field_definition(print_field_definition)
44
+ "<Field Hidden>"
45
+ end
46
+ end
47
+
48
+ it "accepts a custom printer" do
49
+ expected = <<-SCHEMA
50
+ type Query {
51
+ <Field Hidden>
52
+ }
53
+ SCHEMA
54
+ assert_equal expected.chomp, document.to_query_string(printer: CustomPrinter.new)
55
+ end
56
+ end
36
57
  end
@@ -0,0 +1,203 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe GraphQL::Language::Printer do
5
+ let(:document) { GraphQL::Language::Parser.parse(query_string) }
6
+ let(:query_string) {%|
7
+ query getStuff($someVar: Int = 1, $anotherVar: [String!], $skipNested: Boolean! = false) @skip(if: false) {
8
+ myField: someField(someArg: $someVar, ok: 1.4) @skip(if: $anotherVar) @thing(or: "Whatever")
9
+ anotherField(someArg: [1, 2, 3]) {
10
+ nestedField
11
+ ...moreNestedFields @skip(if: $skipNested)
12
+ }
13
+ ... on OtherType @include(unless: false) {
14
+ field(arg: [{key: "value", anotherKey: 0.9, anotherAnotherKey: WHATEVER}])
15
+ anotherField
16
+ }
17
+ ... {
18
+ id
19
+ }
20
+ }
21
+
22
+ fragment moreNestedFields on NestedType @or(something: "ok") {
23
+ anotherNestedField
24
+ }
25
+ |}
26
+
27
+ let(:printer) { GraphQL::Language::Printer.new }
28
+
29
+ describe "#print" do
30
+ it "prints the query string" do
31
+ assert_equal query_string.gsub(/^ /, "").strip, printer.print(document)
32
+ end
33
+
34
+ describe "inputs" do
35
+ let(:query_string) {%|
36
+ query {
37
+ field(null_value: null, null_in_array: [1, null, 3], int: 3, float: 4.7e-24, bool: false, string: "☀︎🏆\\n escaped \\" unicode ¶ /", enum: ENUM_NAME, array: [7, 8, 9], object: {a: [1, 2, 3], b: {c: "4"}}, unicode_bom: "\xef\xbb\xbfquery")
38
+ }
39
+ |}
40
+
41
+ it "prints the query string" do
42
+ assert_equal query_string.gsub(/^ /, "").strip, printer.print(document)
43
+ end
44
+ end
45
+
46
+ describe "schema" do
47
+ describe "schema with convention names for root types" do
48
+ let(:query_string) {<<-schema
49
+ schema {
50
+ query: Query
51
+ mutation: Mutation
52
+ subscription: Subscription
53
+ }
54
+ schema
55
+ }
56
+
57
+ it 'omits schema definition' do
58
+ refute printer.print(document) =~ /schema/
59
+ end
60
+ end
61
+
62
+ describe "schema with custom query root name" do
63
+ let(:query_string) {<<-schema
64
+ schema {
65
+ query: MyQuery
66
+ mutation: Mutation
67
+ subscription: Subscription
68
+ }
69
+ schema
70
+ }
71
+
72
+ it 'includes schema definition' do
73
+ assert_equal query_string.gsub(/^ /, "").strip, printer.print(document)
74
+ end
75
+ end
76
+
77
+ describe "schema with custom mutation root name" do
78
+ let(:query_string) {<<-schema
79
+ schema {
80
+ query: Query
81
+ mutation: MyMutation
82
+ subscription: Subscription
83
+ }
84
+ schema
85
+ }
86
+
87
+ it 'includes schema definition' do
88
+ assert_equal query_string.gsub(/^ /, "").strip, printer.print(document)
89
+ end
90
+ end
91
+
92
+ describe "schema with custom subscription root name" do
93
+ let(:query_string) {<<-schema
94
+ schema {
95
+ query: Query
96
+ mutation: Mutation
97
+ subscription: MySubscription
98
+ }
99
+ schema
100
+ }
101
+
102
+ it 'includes schema definition' do
103
+ assert_equal query_string.gsub(/^ /, "").strip, printer.print(document)
104
+ end
105
+ end
106
+
107
+ describe "full featured schema" do
108
+ # From: https://github.com/graphql/graphql-js/blob/bc96406ab44453a120da25a0bd6e2b0237119ddf/src/language/__tests__/schema-kitchen-sink.graphql
109
+ let(:query_string) {<<-schema
110
+ schema {
111
+ query: QueryType
112
+ mutation: MutationType
113
+ }
114
+
115
+ # Union description
116
+ union AnnotatedUnion @onUnion = A | B
117
+
118
+ type Foo implements Bar {
119
+ one: Type
120
+ two(argument: InputType!): Type
121
+ three(argument: InputType, other: String): Int
122
+ four(argument: String = "string"): String
123
+ five(argument: [String] = ["string", "string"]): String
124
+ six(argument: InputType = {key: "value"}): Type
125
+ seven(argument: String = null): Type
126
+ }
127
+
128
+ # Scalar description
129
+ scalar CustomScalar
130
+
131
+ type AnnotatedObject @onObject(arg: "value") {
132
+ annotatedField(arg: Type = "default" @onArg): Type @onField
133
+ }
134
+
135
+ interface Bar {
136
+ one: Type
137
+ four(argument: String = "string"): String
138
+ }
139
+
140
+ # Enum description
141
+ enum Site {
142
+ # Enum value description
143
+ DESKTOP
144
+ MOBILE
145
+ }
146
+
147
+ interface AnnotatedInterface @onInterface {
148
+ annotatedField(arg: Type @onArg): Type @onField
149
+ }
150
+
151
+ union Feed = Story | Article | Advert
152
+
153
+ # Input description
154
+ input InputType {
155
+ key: String!
156
+ answer: Int = 42
157
+ }
158
+
159
+ union AnnotatedUnion @onUnion = A | B
160
+
161
+ scalar CustomScalar
162
+
163
+ # Directive description
164
+ directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
165
+
166
+ scalar AnnotatedScalar @onScalar
167
+
168
+ enum Site {
169
+ DESKTOP
170
+ MOBILE
171
+ }
172
+
173
+ enum AnnotatedEnum @onEnum {
174
+ ANNOTATED_VALUE @onEnumValue
175
+ OTHER_VALUE
176
+ }
177
+
178
+ input InputType {
179
+ key: String!
180
+ answer: Int = 42
181
+ }
182
+
183
+ input AnnotatedInput @onInputObjectType {
184
+ annotatedField: Type @onField
185
+ }
186
+
187
+ directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
188
+
189
+ directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
190
+ schema
191
+ }
192
+
193
+ it "generate" do
194
+ assert_equal query_string.gsub(/^ /, "").strip, printer.print(document)
195
+ end
196
+
197
+ it "doesn't mutate the document" do
198
+ assert_equal printer.print(document), printer.print(document)
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end