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
@@ -59,9 +59,9 @@ module Jazz
59
59
  # A custom field class that supports the `upcase:` option
60
60
  class BaseField < GraphQL::Schema::Field
61
61
  argument_class BaseArgument
62
- def initialize(*args, options, &block)
62
+ def initialize(*args, **options, &block)
63
63
  @upcase = options.delete(:upcase)
64
- super(*args, options, &block)
64
+ super(*args, **options, &block)
65
65
  end
66
66
 
67
67
  def to_graphql
@@ -197,8 +197,19 @@ module Jazz
197
197
  implements GloballyIdentifiableType
198
198
  implements NamedEntity
199
199
  description "Someone who plays an instrument"
200
- field :instrument, InstrumentType, null: false
200
+ field :instrument, InstrumentType, null: false do
201
+ description "An object played in order to produce music"
202
+ end
201
203
  field :favorite_key, Key, null: true
204
+ field :inspect_context, [String], null: false
205
+
206
+ def inspect_context
207
+ [
208
+ @context.custom_method,
209
+ @context[:magic_key],
210
+ @context[:normal_key]
211
+ ]
212
+ end
202
213
  end
203
214
 
204
215
  LegacyInputType = GraphQL::InputObjectType.define do
@@ -260,6 +271,7 @@ module Jazz
260
271
  field :nowPlaying, PerformingAct, null: false, resolve: ->(o, a, c) { Models.data["Ensemble"].first }
261
272
  # For asserting that the object is initialized once:
262
273
  field :object_id, Integer, null: false
274
+ field :inspect_context, [String], null: false
263
275
 
264
276
  def ensembles
265
277
  Models.data["Ensemble"]
@@ -297,6 +309,14 @@ module Jazz
297
309
  def inspect_key(key:)
298
310
  key
299
311
  end
312
+
313
+ def inspect_context
314
+ [
315
+ @context.custom_method,
316
+ @context[:magic_key],
317
+ @context[:normal_key]
318
+ ]
319
+ end
300
320
  end
301
321
 
302
322
  class EnsembleInput < GraphQL::Schema::InputObject
@@ -321,10 +341,62 @@ module Jazz
321
341
  end
322
342
  end
323
343
 
344
+ class CustomContext < GraphQL::Query::Context
345
+ def [](key)
346
+ if key == :magic_key
347
+ "magic_value"
348
+ else
349
+ super
350
+ end
351
+ end
352
+
353
+ def custom_method
354
+ "custom_method"
355
+ end
356
+ end
357
+
358
+ module Introspection
359
+ class TypeType < GraphQL::Introspection::TypeType
360
+ def name
361
+ @object.name.upcase
362
+ end
363
+ end
364
+
365
+ class SchemaType < GraphQL::Introspection::SchemaType
366
+ graphql_name "__Schema"
367
+
368
+ field :is_jazzy, Boolean, null: false
369
+ def is_jazzy
370
+ true
371
+ end
372
+ end
373
+
374
+ class DynamicFields < GraphQL::Introspection::DynamicFields
375
+ field :__typename_length, Integer, null: false, extras: [:irep_node]
376
+ field :__ast_node_class, String, null: false, extras: [:ast_node]
377
+ def __typename_length(irep_node:)
378
+ __typename(irep_node: irep_node).length
379
+ end
380
+
381
+ def __ast_node_class(ast_node:)
382
+ ast_node.class.name
383
+ end
384
+ end
385
+
386
+ class EntryPoints < GraphQL::Introspection::EntryPoints
387
+ field :__classname, String, "The Ruby class name of the root object", null: false
388
+ def __classname
389
+ @object.class.name
390
+ end
391
+ end
392
+ end
393
+
324
394
  # New-style Schema definition
325
395
  class Schema < GraphQL::Schema
326
396
  query(Query)
327
397
  mutation(Mutation)
398
+ context_class CustomContext
399
+ introspection(Introspection)
328
400
  use MetadataPlugin, value: "xyz"
329
401
  def self.resolve_type(type, obj, ctx)
330
402
  class_name = obj.class.name.split("::").last
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: 1.8.0.pre2
4
+ version: 1.8.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-29 00:00:00.000000000 Z
11
+ date: 2018-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips
@@ -248,6 +248,20 @@ dependencies:
248
248
  - - ">="
249
249
  - !ruby/object:Gem::Version
250
250
  version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: parser
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
251
265
  - !ruby/object:Gem::Dependency
252
266
  name: jekyll
253
267
  requirement: !ruby/object:Gem::Requirement
@@ -396,19 +410,15 @@ files:
396
410
  - lib/graphql/internal_representation/scope.rb
397
411
  - lib/graphql/internal_representation/visit.rb
398
412
  - lib/graphql/introspection.rb
399
- - lib/graphql/introspection/arguments_field.rb
413
+ - lib/graphql/introspection/base_object.rb
400
414
  - lib/graphql/introspection/directive_location_enum.rb
401
415
  - lib/graphql/introspection/directive_type.rb
416
+ - lib/graphql/introspection/dynamic_fields.rb
417
+ - lib/graphql/introspection/entry_points.rb
402
418
  - lib/graphql/introspection/enum_value_type.rb
403
- - lib/graphql/introspection/enum_values_field.rb
404
419
  - lib/graphql/introspection/field_type.rb
405
- - lib/graphql/introspection/fields_field.rb
406
- - lib/graphql/introspection/input_fields_field.rb
407
420
  - lib/graphql/introspection/input_value_type.rb
408
- - lib/graphql/introspection/interfaces_field.rb
409
421
  - lib/graphql/introspection/introspection_query.rb
410
- - lib/graphql/introspection/of_type_field.rb
411
- - lib/graphql/introspection/possible_types_field.rb
412
422
  - lib/graphql/introspection/schema_field.rb
413
423
  - lib/graphql/introspection/schema_type.rb
414
424
  - lib/graphql/introspection/type_by_name_field.rb
@@ -427,6 +437,7 @@ files:
427
437
  - lib/graphql/language/nodes.rb
428
438
  - lib/graphql/language/parser.rb
429
439
  - lib/graphql/language/parser.y
440
+ - lib/graphql/language/printer.rb
430
441
  - lib/graphql/language/token.rb
431
442
  - lib/graphql/language/visitor.rb
432
443
  - lib/graphql/list_type.rb
@@ -489,7 +500,9 @@ files:
489
500
  - lib/graphql/schema/field/unwrapped_resolve.rb
490
501
  - lib/graphql/schema/input_object.rb
491
502
  - lib/graphql/schema/interface.rb
503
+ - lib/graphql/schema/introspection_system.rb
492
504
  - lib/graphql/schema/invalid_type_error.rb
505
+ - lib/graphql/schema/late_bound_type.rb
493
506
  - lib/graphql/schema/loader.rb
494
507
  - lib/graphql/schema/member.rb
495
508
  - lib/graphql/schema/member/build_type.rb
@@ -869,6 +882,12 @@ files:
869
882
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/zy/zywotY5ANjNyE78CLDqC1eYRFwL1ZFzkT9J5LzNlI4M.cache
870
883
  - spec/dummy/tmp/restart.txt
871
884
  - spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png
885
+ - spec/fixtures/upgrader/blame_range.original.rb
886
+ - spec/fixtures/upgrader/blame_range.transformed.rb
887
+ - spec/fixtures/upgrader/subscribable.original.rb
888
+ - spec/fixtures/upgrader/subscribable.transformed.rb
889
+ - spec/fixtures/upgrader/type_x.original.rb
890
+ - spec/fixtures/upgrader/type_x.transformed.rb
872
891
  - spec/generators/graphql/enum_generator_spec.rb
873
892
  - spec/generators/graphql/function_generator_spec.rb
874
893
  - spec/generators/graphql/install_generator_spec.rb
@@ -925,6 +944,7 @@ files:
925
944
  - spec/graphql/language/lexer_spec.rb
926
945
  - spec/graphql/language/nodes_spec.rb
927
946
  - spec/graphql/language/parser_spec.rb
947
+ - spec/graphql/language/printer_spec.rb
928
948
  - spec/graphql/language/visitor_spec.rb
929
949
  - spec/graphql/list_type_spec.rb
930
950
  - spec/graphql/non_null_type_spec.rb
@@ -957,6 +977,7 @@ files:
957
977
  - spec/graphql/schema/input_object_spec.rb
958
978
  - spec/graphql/schema/instrumentation_spec.rb
959
979
  - spec/graphql/schema/interface_spec.rb
980
+ - spec/graphql/schema/introspection_system_spec.rb
960
981
  - spec/graphql/schema/loader_spec.rb
961
982
  - spec/graphql/schema/middleware_chain_spec.rb
962
983
  - spec/graphql/schema/object_spec.rb
@@ -1350,6 +1371,12 @@ test_files:
1350
1371
  - spec/dummy/tmp/cache/assets/sprockets/v3.0/Zz/Zzsh2ASGqBSWLSWIU4fAyxS3iVuJDxdTCw8jOOsUNzA.cache
1351
1372
  - spec/dummy/tmp/restart.txt
1352
1373
  - spec/dummy/tmp/screenshots/failures_test_it_handles_subscriptions.png
1374
+ - spec/fixtures/upgrader/blame_range.original.rb
1375
+ - spec/fixtures/upgrader/blame_range.transformed.rb
1376
+ - spec/fixtures/upgrader/subscribable.original.rb
1377
+ - spec/fixtures/upgrader/subscribable.transformed.rb
1378
+ - spec/fixtures/upgrader/type_x.original.rb
1379
+ - spec/fixtures/upgrader/type_x.transformed.rb
1353
1380
  - spec/generators/graphql/enum_generator_spec.rb
1354
1381
  - spec/generators/graphql/function_generator_spec.rb
1355
1382
  - spec/generators/graphql/install_generator_spec.rb
@@ -1406,6 +1433,7 @@ test_files:
1406
1433
  - spec/graphql/language/lexer_spec.rb
1407
1434
  - spec/graphql/language/nodes_spec.rb
1408
1435
  - spec/graphql/language/parser_spec.rb
1436
+ - spec/graphql/language/printer_spec.rb
1409
1437
  - spec/graphql/language/visitor_spec.rb
1410
1438
  - spec/graphql/list_type_spec.rb
1411
1439
  - spec/graphql/non_null_type_spec.rb
@@ -1438,6 +1466,7 @@ test_files:
1438
1466
  - spec/graphql/schema/input_object_spec.rb
1439
1467
  - spec/graphql/schema/instrumentation_spec.rb
1440
1468
  - spec/graphql/schema/interface_spec.rb
1469
+ - spec/graphql/schema/introspection_system_spec.rb
1441
1470
  - spec/graphql/schema/loader_spec.rb
1442
1471
  - spec/graphql/schema/middleware_chain_spec.rb
1443
1472
  - spec/graphql/schema/object_spec.rb
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::Introspection::ArgumentsField = GraphQL::Field.define do
3
- type !GraphQL::ListType.new(of_type: !GraphQL::Introspection::InputValueType)
4
- resolve ->(obj, args, ctx) {
5
- ctx.warden.arguments(obj)
6
- }
7
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::Introspection::EnumValuesField = GraphQL::Field.define do
3
- type types[!GraphQL::Introspection::EnumValueType]
4
- argument :includeDeprecated, types.Boolean, default_value: false
5
- resolve ->(object, arguments, context) do
6
- if !object.kind.enum?
7
- nil
8
- else
9
- enum_values = context.warden.enum_values(object)
10
-
11
- if !arguments["includeDeprecated"]
12
- enum_values = enum_values.select {|f| !f.deprecation_reason }
13
- end
14
-
15
- enum_values
16
- end
17
- end
18
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::Introspection::FieldsField = GraphQL::Field.define do
3
- type -> { types[!GraphQL::Introspection::FieldType] }
4
- argument :includeDeprecated, GraphQL::BOOLEAN_TYPE, default_value: false
5
- resolve ->(object, arguments, context) {
6
- return nil if !object.kind.fields?
7
- fields = context.warden.fields(object)
8
- if !arguments["includeDeprecated"]
9
- fields = fields.select {|f| !f.deprecation_reason }
10
- end
11
- fields.sort_by(&:name)
12
- }
13
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::Introspection::InputFieldsField = GraphQL::Field.define do
3
- name "inputFields"
4
- type types[!GraphQL::Introspection::InputValueType]
5
- resolve ->(target, a, ctx) {
6
- if target.kind.input_object?
7
- ctx.warden.arguments(target)
8
- else
9
- nil
10
- end
11
- }
12
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::Introspection::InterfacesField = GraphQL::Field.define do
3
- type -> { types[!GraphQL::Introspection::TypeType] }
4
- resolve ->(target, a, ctx) {
5
- if target.kind == GraphQL::TypeKinds::OBJECT
6
- ctx.warden.interfaces(target)
7
- else
8
- nil
9
- end
10
- }
11
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::Introspection::OfTypeField = GraphQL::Field.define do
3
- name "ofType"
4
- type -> { GraphQL::Introspection::TypeType }
5
- resolve ->(obj, args, ctx) { obj.kind.wraps? ? obj.of_type : nil }
6
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
- GraphQL::Introspection::PossibleTypesField = GraphQL::Field.define do
3
- type -> { types[!GraphQL::Introspection::TypeType] }
4
- resolve ->(target, args, ctx) {
5
- if target.kind.resolves?
6
- ctx.warden.possible_types(target)
7
- else
8
- nil
9
- end
10
- }
11
- end