graphql 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +31 -41
  3. data/lib/graphql/argument.rb +23 -21
  4. data/lib/graphql/base_type.rb +5 -8
  5. data/lib/graphql/define/assign_argument.rb +5 -2
  6. data/lib/graphql/define/type_definer.rb +2 -1
  7. data/lib/graphql/directive.rb +34 -36
  8. data/lib/graphql/directive/include_directive.rb +3 -7
  9. data/lib/graphql/directive/skip_directive.rb +3 -7
  10. data/lib/graphql/enum_type.rb +78 -76
  11. data/lib/graphql/execution_error.rb +1 -3
  12. data/lib/graphql/field.rb +99 -95
  13. data/lib/graphql/input_object_type.rb +49 -47
  14. data/lib/graphql/interface_type.rb +31 -34
  15. data/lib/graphql/introspection.rb +19 -18
  16. data/lib/graphql/introspection/directive_location_enum.rb +8 -0
  17. data/lib/graphql/introspection/directive_type.rb +1 -3
  18. data/lib/graphql/introspection/field_type.rb +1 -1
  19. data/lib/graphql/introspection/fields_field.rb +1 -1
  20. data/lib/graphql/introspection/introspection_query.rb +1 -3
  21. data/lib/graphql/introspection/possible_types_field.rb +7 -1
  22. data/lib/graphql/introspection/schema_field.rb +13 -9
  23. data/lib/graphql/introspection/type_by_name_field.rb +13 -17
  24. data/lib/graphql/introspection/typename_field.rb +12 -8
  25. data/lib/graphql/language.rb +5 -9
  26. data/lib/graphql/language/lexer.rb +668 -0
  27. data/lib/graphql/language/lexer.rl +149 -0
  28. data/lib/graphql/language/parser.rb +842 -116
  29. data/lib/graphql/language/parser.y +264 -0
  30. data/lib/graphql/language/token.rb +21 -0
  31. data/lib/graphql/list_type.rb +33 -31
  32. data/lib/graphql/non_null_type.rb +33 -31
  33. data/lib/graphql/object_type.rb +52 -55
  34. data/lib/graphql/query.rb +83 -80
  35. data/lib/graphql/query/context.rb +5 -1
  36. data/lib/graphql/query/directive_resolution.rb +16 -0
  37. data/lib/graphql/query/executor.rb +3 -3
  38. data/lib/graphql/query/input_validation_result.rb +17 -15
  39. data/lib/graphql/query/serial_execution.rb +5 -5
  40. data/lib/graphql/query/serial_execution/execution_context.rb +4 -3
  41. data/lib/graphql/query/serial_execution/selection_resolution.rb +19 -21
  42. data/lib/graphql/query/serial_execution/value_resolution.rb +1 -1
  43. data/lib/graphql/query/type_resolver.rb +22 -18
  44. data/lib/graphql/query/variable_validation_error.rb +14 -12
  45. data/lib/graphql/schema.rb +87 -77
  46. data/lib/graphql/schema/each_item_validator.rb +16 -12
  47. data/lib/graphql/schema/field_validator.rb +14 -10
  48. data/lib/graphql/schema/implementation_validator.rb +26 -22
  49. data/lib/graphql/schema/middleware_chain.rb +2 -1
  50. data/lib/graphql/schema/possible_types.rb +34 -0
  51. data/lib/graphql/schema/printer.rb +122 -120
  52. data/lib/graphql/schema/type_expression.rb +1 -0
  53. data/lib/graphql/schema/type_map.rb +3 -10
  54. data/lib/graphql/schema/type_reducer.rb +65 -81
  55. data/lib/graphql/schema/type_validator.rb +45 -41
  56. data/lib/graphql/static_validation.rb +7 -9
  57. data/lib/graphql/static_validation/all_rules.rb +29 -24
  58. data/lib/graphql/static_validation/arguments_validator.rb +39 -35
  59. data/lib/graphql/static_validation/literal_validator.rb +44 -40
  60. data/lib/graphql/static_validation/message.rb +30 -26
  61. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +15 -11
  62. data/lib/graphql/static_validation/rules/arguments_are_defined.rb +14 -10
  63. data/lib/graphql/static_validation/rules/directives_are_defined.rb +16 -12
  64. data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +59 -0
  65. data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +25 -21
  66. data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +28 -24
  67. data/lib/graphql/static_validation/rules/fields_will_merge.rb +84 -80
  68. data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +49 -43
  69. data/lib/graphql/static_validation/rules/fragment_types_exist.rb +22 -17
  70. data/lib/graphql/static_validation/rules/fragments_are_finite.rb +19 -15
  71. data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +25 -20
  72. data/lib/graphql/static_validation/rules/fragments_are_used.rb +36 -23
  73. data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +29 -25
  74. data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +21 -17
  75. data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +79 -70
  76. data/lib/graphql/static_validation/rules/variables_are_input_types.rb +24 -20
  77. data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +122 -119
  78. data/lib/graphql/static_validation/type_stack.rb +138 -129
  79. data/lib/graphql/static_validation/validator.rb +29 -25
  80. data/lib/graphql/type_kinds.rb +42 -40
  81. data/lib/graphql/union_type.rb +22 -16
  82. data/lib/graphql/version.rb +1 -1
  83. data/readme.md +12 -27
  84. data/spec/graphql/base_type_spec.rb +3 -3
  85. data/spec/graphql/directive_spec.rb +10 -18
  86. data/spec/graphql/enum_type_spec.rb +7 -7
  87. data/spec/graphql/execution_error_spec.rb +1 -1
  88. data/spec/graphql/field_spec.rb +14 -13
  89. data/spec/graphql/id_type_spec.rb +6 -6
  90. data/spec/graphql/input_object_type_spec.rb +39 -39
  91. data/spec/graphql/interface_type_spec.rb +16 -32
  92. data/spec/graphql/introspection/directive_type_spec.rb +5 -9
  93. data/spec/graphql/introspection/input_value_type_spec.rb +10 -4
  94. data/spec/graphql/introspection/introspection_query_spec.rb +2 -2
  95. data/spec/graphql/introspection/schema_type_spec.rb +2 -2
  96. data/spec/graphql/introspection/type_type_spec.rb +34 -6
  97. data/spec/graphql/language/parser_spec.rb +299 -105
  98. data/spec/graphql/language/visitor_spec.rb +4 -4
  99. data/spec/graphql/list_type_spec.rb +11 -11
  100. data/spec/graphql/object_type_spec.rb +10 -10
  101. data/spec/graphql/query/arguments_spec.rb +7 -7
  102. data/spec/graphql/query/context_spec.rb +11 -3
  103. data/spec/graphql/query/executor_spec.rb +26 -19
  104. data/spec/graphql/query/serial_execution/execution_context_spec.rb +6 -6
  105. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -2
  106. data/spec/graphql/query/type_resolver_spec.rb +3 -3
  107. data/spec/graphql/query_spec.rb +6 -38
  108. data/spec/graphql/scalar_type_spec.rb +28 -19
  109. data/spec/graphql/schema/field_validator_spec.rb +1 -1
  110. data/spec/graphql/schema/middleware_chain_spec.rb +12 -1
  111. data/spec/graphql/schema/printer_spec.rb +12 -4
  112. data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
  113. data/spec/graphql/schema/type_expression_spec.rb +2 -2
  114. data/spec/graphql/schema/type_reducer_spec.rb +21 -36
  115. data/spec/graphql/schema/type_validator_spec.rb +9 -9
  116. data/spec/graphql/schema_spec.rb +1 -1
  117. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +4 -4
  118. data/spec/graphql/static_validation/rules/arguments_are_defined_spec.rb +4 -4
  119. data/spec/graphql/static_validation/rules/directives_are_defined_spec.rb +5 -5
  120. data/spec/graphql/static_validation/rules/directives_are_in_valid_locations_spec.rb +39 -0
  121. data/spec/graphql/static_validation/rules/fields_are_defined_on_type_spec.rb +5 -5
  122. data/spec/graphql/static_validation/rules/fields_have_appropriate_selections_spec.rb +4 -4
  123. data/spec/graphql/static_validation/rules/fields_will_merge_spec.rb +2 -2
  124. data/spec/graphql/static_validation/rules/fragment_spreads_are_possible_spec.rb +1 -1
  125. data/spec/graphql/static_validation/rules/fragment_types_exist_spec.rb +2 -2
  126. data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +2 -2
  127. data/spec/graphql/static_validation/rules/fragments_are_on_composite_types_spec.rb +2 -2
  128. data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +3 -3
  129. data/spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb +3 -3
  130. data/spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb +5 -5
  131. data/spec/graphql/static_validation/rules/variable_usages_are_allowed_spec.rb +3 -1
  132. data/spec/graphql/static_validation/rules/variables_are_input_types_spec.rb +4 -4
  133. data/spec/graphql/static_validation/rules/variables_are_used_and_defined_spec.rb +3 -3
  134. data/spec/graphql/static_validation/type_stack_spec.rb +3 -2
  135. data/spec/graphql/static_validation/validator_spec.rb +26 -6
  136. data/spec/graphql/union_type_spec.rb +5 -4
  137. data/spec/spec_helper.rb +2 -5
  138. data/spec/support/dairy_app.rb +30 -9
  139. data/spec/support/dairy_data.rb +1 -1
  140. data/spec/support/star_wars_data.rb +26 -26
  141. data/spec/support/star_wars_schema.rb +1 -1
  142. metadata +40 -21
  143. data/lib/graphql/language/transform.rb +0 -113
  144. data/lib/graphql/query/directive_chain.rb +0 -44
  145. data/lib/graphql/repl.rb +0 -27
  146. data/spec/graphql/language/transform_spec.rb +0 -156
@@ -0,0 +1,8 @@
1
+ GraphQL::Introspection::DirectiveLocationEnum = GraphQL::EnumType.define do
2
+ name "__DirectiveLocation"
3
+ description "Parts of the query where a directive may be located"
4
+
5
+ GraphQL::Directive::LOCATIONS.each do |location|
6
+ value(location.to_s, value: location)
7
+ end
8
+ end
@@ -4,7 +4,5 @@ GraphQL::Introspection::DirectiveType = GraphQL::ObjectType.define do
4
4
  field :name, !types.String, "The name of this directive"
5
5
  field :description, types.String, "The description for this type"
6
6
  field :args, field: GraphQL::Introspection::ArgumentsField
7
- field :onOperation, !types.Boolean, "Does this directive apply to operations?", property: :on_operation?
8
- field :onFragment, !types.Boolean, "Does this directive apply to fragments?", property: :on_fragment?
9
- field :onField, !types.Boolean, "Does this directive apply to fields?", property: :on_field?
7
+ field :locations, !types[!GraphQL::Introspection::DirectiveLocationEnum]
10
8
  end
@@ -5,7 +5,7 @@ GraphQL::Introspection::FieldType = GraphQL::ObjectType.define do
5
5
  field :description, types.String, "The description of this field"
6
6
  field :type, !GraphQL::Introspection::TypeType, "The return type of this field"
7
7
  field :isDeprecated, !types.Boolean, "Is this field deprecated?" do
8
- resolve -> (obj, a, c) { !!obj.deprecation_reason }
8
+ resolve -> (obj, a, c) { !!obj.deprecation_reason }
9
9
  end
10
10
  field :args, field: GraphQL::Introspection::ArgumentsField
11
11
  field :deprecationReason, types.String, "Why this field was deprecated", property: :deprecation_reason
@@ -8,6 +8,6 @@ GraphQL::Introspection::FieldsField = GraphQL::Field.define do
8
8
  if !arguments["includeDeprecated"]
9
9
  fields = fields.select {|f| !f.deprecation_reason }
10
10
  end
11
- fields.sort_by { |f| f.name }
11
+ fields.sort_by(&:name)
12
12
  }
13
13
  end
@@ -12,12 +12,10 @@ query IntrospectionQuery {
12
12
  directives {
13
13
  name
14
14
  description
15
+ locations
15
16
  args {
16
17
  ...InputValue
17
18
  }
18
- onOperation
19
- onFragment
20
- onField
21
19
  }
22
20
  }
23
21
  }
@@ -1,5 +1,11 @@
1
1
  GraphQL::Introspection::PossibleTypesField = GraphQL::Field.define do
2
2
  description "Types which compose this Union or Interface"
3
3
  type -> { types[!GraphQL::Introspection::TypeType] }
4
- resolve -> (target, a, c) { target.kind.resolves? ? target.possible_types : nil }
4
+ resolve -> (target, args, ctx) {
5
+ if target.kind.resolves?
6
+ ctx.schema.possible_types(target)
7
+ else
8
+ nil
9
+ end
10
+ }
5
11
  end
@@ -1,11 +1,15 @@
1
- # A wrapper to implement `__schema`
2
- class GraphQL::Introspection::SchemaField
3
- def self.create(wrapped_type)
4
- GraphQL::Field.define do
5
- name("__schema")
6
- description("This GraphQL schema")
7
- type(!GraphQL::Introspection::SchemaType)
8
- resolve -> (o, a, c) { wrapped_type }
9
- end
1
+ module GraphQL
2
+ module Introspection
3
+ # A wrapper to implement `__schema`
4
+ class SchemaField
5
+ def self.create(wrapped_type)
6
+ GraphQL::Field.define do
7
+ name("__schema")
8
+ description("This GraphQL schema")
9
+ type(!GraphQL::Introspection::SchemaType)
10
+ resolve -> (o, a, c) { wrapped_type }
11
+ end
12
+ end
13
+ end
10
14
  end
11
15
  end
@@ -1,20 +1,16 @@
1
- # A wrapper to create `__type(name: )` dynamically.
2
- class GraphQL::Introspection::TypeByNameField
3
- DEFINITION = Proc.new { |f, type, field, arg, type_hash|
4
- f.name("__type")
5
- f.description("A type in the GraphQL system")
6
- f.arguments({name: arg.build(type: !type.String)})
7
- f.type(!GraphQL::Introspection::TypeType)
8
- f.resolve -> (o, args, c) { type_hash[args["name"]] }
9
- }
10
-
11
- def self.create(type_hash)
12
- GraphQL::Field.define do
13
- name("__type")
14
- description("A type in the GraphQL system")
15
- type(!GraphQL::Introspection::TypeType)
16
- argument :name, !types.String
17
- resolve -> (o, args, c) { type_hash[args["name"]] }
1
+ module GraphQL
2
+ module Introspection
3
+ # A wrapper to create `__type(name: )` dynamically.
4
+ class TypeByNameField
5
+ def self.create(type_hash)
6
+ GraphQL::Field.define do
7
+ name("__type")
8
+ description("A type in the GraphQL system")
9
+ type(!GraphQL::Introspection::TypeType)
10
+ argument :name, !types.String
11
+ resolve -> (o, args, c) { type_hash[args["name"]] }
12
+ end
13
+ end
18
14
  end
19
15
  end
20
16
  end
@@ -1,11 +1,15 @@
1
- # A wrapper to create `__typename`.
2
- class GraphQL::Introspection::TypenameField
3
- def self.create(wrapped_type)
4
- GraphQL::Field.define do
5
- name "__typename"
6
- description "The name of this type"
7
- type -> { !GraphQL::STRING_TYPE }
8
- resolve -> (obj, a, c) { wrapped_type.name }
1
+ module GraphQL
2
+ module Introspection
3
+ # A wrapper to create `__typename`.
4
+ class TypenameField
5
+ def self.create(wrapped_type)
6
+ GraphQL::Field.define do
7
+ name "__typename"
8
+ description "The name of this type"
9
+ type -> { !GraphQL::STRING_TYPE }
10
+ resolve -> (obj, a, c) { wrapped_type.name }
11
+ end
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -1,9 +1,5 @@
1
- require 'graphql/language/parser'
2
- require 'graphql/language/transform'
3
- require 'graphql/language/nodes'
4
- require 'graphql/language/visitor'
5
-
6
- module GraphQL
7
- TRANSFORM = GraphQL::Language::Transform.new
8
- PARSER = GraphQL::Language::Parser.new
9
- end
1
+ require "graphql/language/lexer"
2
+ require "graphql/language/nodes"
3
+ require "graphql/language/parser"
4
+ require "graphql/language/token"
5
+ require "graphql/language/visitor"
@@ -0,0 +1,668 @@
1
+
2
+ # line 1 "lib/graphql/language/lexer.rl"
3
+
4
+ # line 65 "lib/graphql/language/lexer.rl"
5
+
6
+
7
+
8
+ module GraphQL
9
+ module Language
10
+ module Lexer
11
+ def self.tokenize(query_string)
12
+ run_lexer(query_string)
13
+ end
14
+
15
+ # Replace any escaped unicode or whitespace with the _actual_ characters
16
+ # To avoid allocating more strings, this modifies the string passed into it
17
+ def self.replace_escaped_characters_in_place(raw_string)
18
+ raw_string.gsub!(ESCAPES, ESCAPES_REPLACE)
19
+ raw_string.gsub!(UTF_8, &UTF_8_REPLACE)
20
+ nil
21
+ end
22
+
23
+ private
24
+
25
+
26
+ # line 27 "lib/graphql/language/lexer.rb"
27
+ class << self
28
+ attr_accessor :_graphql_lexer_actions
29
+ private :_graphql_lexer_actions, :_graphql_lexer_actions=
30
+ end
31
+ self._graphql_lexer_actions = [
32
+ 0, 1, 2, 1, 12, 1, 13, 1,
33
+ 14, 1, 15, 1, 16, 1, 17, 1,
34
+ 18, 1, 19, 1, 20, 1, 21, 1,
35
+ 22, 1, 23, 1, 24, 1, 25, 1,
36
+ 26, 1, 27, 1, 28, 1, 29, 1,
37
+ 30, 1, 31, 1, 32, 1, 33, 2,
38
+ 0, 1, 2, 3, 4, 2, 3, 5,
39
+ 2, 3, 6, 2, 3, 7, 2, 3,
40
+ 8, 2, 3, 9, 2, 3, 10, 2,
41
+ 3, 11
42
+ ]
43
+
44
+ class << self
45
+ attr_accessor :_graphql_lexer_key_offsets
46
+ private :_graphql_lexer_key_offsets, :_graphql_lexer_key_offsets=
47
+ end
48
+ self._graphql_lexer_key_offsets = [
49
+ 0, 0, 2, 4, 7, 9, 11, 15,
50
+ 16, 17, 48, 51, 53, 55, 62, 64,
51
+ 70, 77, 84, 93, 101, 109, 117, 125,
52
+ 133, 141, 149, 157, 165, 173, 181, 189
53
+ ]
54
+
55
+ class << self
56
+ attr_accessor :_graphql_lexer_trans_keys
57
+ private :_graphql_lexer_trans_keys, :_graphql_lexer_trans_keys=
58
+ end
59
+ self._graphql_lexer_trans_keys = [
60
+ 34, 92, 34, 92, 48, 49, 57, 48,
61
+ 57, 48, 57, 43, 45, 48, 57, 46,
62
+ 46, 9, 10, 13, 32, 33, 34, 35,
63
+ 36, 40, 41, 44, 45, 46, 48, 58,
64
+ 61, 64, 91, 93, 95, 102, 111, 116,
65
+ 123, 125, 49, 57, 65, 90, 97, 122,
66
+ 9, 32, 44, 34, 92, 10, 13, 43,
67
+ 45, 46, 69, 101, 48, 57, 48, 57,
68
+ 43, 45, 69, 101, 48, 57, 43, 45,
69
+ 46, 69, 101, 48, 57, 95, 48, 57,
70
+ 65, 90, 97, 122, 95, 97, 114, 48,
71
+ 57, 65, 90, 98, 122, 95, 108, 48,
72
+ 57, 65, 90, 97, 122, 95, 115, 48,
73
+ 57, 65, 90, 97, 122, 95, 101, 48,
74
+ 57, 65, 90, 97, 122, 95, 97, 48,
75
+ 57, 65, 90, 98, 122, 95, 103, 48,
76
+ 57, 65, 90, 97, 122, 95, 109, 48,
77
+ 57, 65, 90, 97, 122, 95, 101, 48,
78
+ 57, 65, 90, 97, 122, 95, 110, 48,
79
+ 57, 65, 90, 97, 122, 95, 116, 48,
80
+ 57, 65, 90, 97, 122, 95, 110, 48,
81
+ 57, 65, 90, 97, 122, 95, 114, 48,
82
+ 57, 65, 90, 97, 122, 95, 117, 48,
83
+ 57, 65, 90, 97, 122, 95, 101, 48,
84
+ 57, 65, 90, 97, 122, 0
85
+ ]
86
+
87
+ class << self
88
+ attr_accessor :_graphql_lexer_single_lengths
89
+ private :_graphql_lexer_single_lengths, :_graphql_lexer_single_lengths=
90
+ end
91
+ self._graphql_lexer_single_lengths = [
92
+ 0, 2, 2, 1, 0, 0, 2, 1,
93
+ 1, 25, 3, 2, 2, 5, 0, 4,
94
+ 5, 1, 3, 2, 2, 2, 2, 2,
95
+ 2, 2, 2, 2, 2, 2, 2, 2
96
+ ]
97
+
98
+ class << self
99
+ attr_accessor :_graphql_lexer_range_lengths
100
+ private :_graphql_lexer_range_lengths, :_graphql_lexer_range_lengths=
101
+ end
102
+ self._graphql_lexer_range_lengths = [
103
+ 0, 0, 0, 1, 1, 1, 1, 0,
104
+ 0, 3, 0, 0, 0, 1, 1, 1,
105
+ 1, 3, 3, 3, 3, 3, 3, 3,
106
+ 3, 3, 3, 3, 3, 3, 3, 3
107
+ ]
108
+
109
+ class << self
110
+ attr_accessor :_graphql_lexer_index_offsets
111
+ private :_graphql_lexer_index_offsets, :_graphql_lexer_index_offsets=
112
+ end
113
+ self._graphql_lexer_index_offsets = [
114
+ 0, 0, 3, 6, 9, 11, 13, 17,
115
+ 19, 21, 50, 54, 57, 60, 67, 69,
116
+ 75, 82, 87, 94, 100, 106, 112, 118,
117
+ 124, 130, 136, 142, 148, 154, 160, 166
118
+ ]
119
+
120
+ class << self
121
+ attr_accessor :_graphql_lexer_indicies
122
+ private :_graphql_lexer_indicies, :_graphql_lexer_indicies=
123
+ end
124
+ self._graphql_lexer_indicies = [
125
+ 2, 3, 1, 4, 3, 1, 5, 7,
126
+ 6, 8, 0, 10, 9, 11, 11, 8,
127
+ 0, 12, 6, 13, 6, 14, 15, 15,
128
+ 14, 16, 1, 17, 18, 19, 20, 14,
129
+ 21, 22, 5, 23, 24, 25, 27, 28,
130
+ 26, 29, 30, 31, 32, 33, 7, 26,
131
+ 26, 6, 14, 14, 14, 34, 2, 3,
132
+ 1, 36, 36, 17, 11, 11, 38, 39,
133
+ 39, 8, 37, 8, 40, 11, 11, 39,
134
+ 39, 10, 40, 11, 11, 38, 39, 39,
135
+ 7, 37, 26, 26, 26, 26, 0, 26,
136
+ 42, 43, 26, 26, 26, 41, 26, 44,
137
+ 26, 26, 26, 41, 26, 45, 26, 26,
138
+ 26, 41, 26, 46, 26, 26, 26, 41,
139
+ 26, 47, 26, 26, 26, 41, 26, 48,
140
+ 26, 26, 26, 41, 26, 49, 26, 26,
141
+ 26, 41, 26, 50, 26, 26, 26, 41,
142
+ 26, 51, 26, 26, 26, 41, 26, 52,
143
+ 26, 26, 26, 41, 26, 53, 26, 26,
144
+ 26, 41, 26, 54, 26, 26, 26, 41,
145
+ 26, 55, 26, 26, 26, 41, 26, 56,
146
+ 26, 26, 26, 41, 0
147
+ ]
148
+
149
+ class << self
150
+ attr_accessor :_graphql_lexer_trans_targs
151
+ private :_graphql_lexer_trans_targs, :_graphql_lexer_trans_targs=
152
+ end
153
+ self._graphql_lexer_trans_targs = [
154
+ 9, 1, 9, 2, 11, 13, 0, 16,
155
+ 14, 9, 15, 4, 8, 9, 10, 9,
156
+ 9, 12, 9, 9, 9, 3, 7, 9,
157
+ 9, 9, 17, 9, 9, 18, 28, 29,
158
+ 9, 9, 9, 9, 9, 9, 5, 6,
159
+ 9, 9, 19, 22, 20, 21, 17, 23,
160
+ 24, 25, 26, 27, 17, 17, 30, 31,
161
+ 17
162
+ ]
163
+
164
+ class << self
165
+ attr_accessor :_graphql_lexer_trans_actions
166
+ private :_graphql_lexer_trans_actions, :_graphql_lexer_trans_actions=
167
+ end
168
+ self._graphql_lexer_trans_actions = [
169
+ 45, 0, 17, 0, 68, 50, 0, 50,
170
+ 0, 43, 53, 0, 0, 23, 0, 29,
171
+ 27, 0, 19, 7, 9, 0, 0, 15,
172
+ 25, 21, 71, 11, 13, 0, 0, 0,
173
+ 3, 5, 39, 35, 41, 31, 0, 0,
174
+ 33, 37, 0, 0, 0, 0, 65, 0,
175
+ 0, 0, 0, 0, 59, 56, 0, 0,
176
+ 62
177
+ ]
178
+
179
+ class << self
180
+ attr_accessor :_graphql_lexer_to_state_actions
181
+ private :_graphql_lexer_to_state_actions, :_graphql_lexer_to_state_actions=
182
+ end
183
+ self._graphql_lexer_to_state_actions = [
184
+ 0, 0, 0, 0, 0, 0, 0, 0,
185
+ 0, 47, 0, 0, 0, 0, 0, 0,
186
+ 0, 0, 0, 0, 0, 0, 0, 0,
187
+ 0, 0, 0, 0, 0, 0, 0, 0
188
+ ]
189
+
190
+ class << self
191
+ attr_accessor :_graphql_lexer_from_state_actions
192
+ private :_graphql_lexer_from_state_actions, :_graphql_lexer_from_state_actions=
193
+ end
194
+ self._graphql_lexer_from_state_actions = [
195
+ 0, 0, 0, 0, 0, 0, 0, 0,
196
+ 0, 1, 0, 0, 0, 0, 0, 0,
197
+ 0, 0, 0, 0, 0, 0, 0, 0,
198
+ 0, 0, 0, 0, 0, 0, 0, 0
199
+ ]
200
+
201
+ class << self
202
+ attr_accessor :_graphql_lexer_eof_trans
203
+ private :_graphql_lexer_eof_trans, :_graphql_lexer_eof_trans=
204
+ end
205
+ self._graphql_lexer_eof_trans = [
206
+ 0, 1, 1, 0, 1, 10, 1, 0,
207
+ 0, 0, 35, 36, 37, 38, 41, 41,
208
+ 38, 1, 42, 42, 42, 42, 42, 42,
209
+ 42, 42, 42, 42, 42, 42, 42, 42
210
+ ]
211
+
212
+ class << self
213
+ attr_accessor :graphql_lexer_start
214
+ end
215
+ self.graphql_lexer_start = 9;
216
+ class << self
217
+ attr_accessor :graphql_lexer_first_final
218
+ end
219
+ self.graphql_lexer_first_final = 9;
220
+ class << self
221
+ attr_accessor :graphql_lexer_error
222
+ end
223
+ self.graphql_lexer_error = 0;
224
+
225
+ class << self
226
+ attr_accessor :graphql_lexer_en_main
227
+ end
228
+ self.graphql_lexer_en_main = 9;
229
+
230
+
231
+ # line 86 "lib/graphql/language/lexer.rl"
232
+
233
+ def self.run_lexer(query_string)
234
+ data = query_string.unpack("c*")
235
+ eof = data.length
236
+
237
+ meta = {
238
+ line: 1,
239
+ col: 1,
240
+ data: data,
241
+ tokens: []
242
+ }
243
+
244
+
245
+ # line 246 "lib/graphql/language/lexer.rb"
246
+ begin
247
+ p ||= 0
248
+ pe ||= data.length
249
+ cs = graphql_lexer_start
250
+ ts = nil
251
+ te = nil
252
+ act = 0
253
+ end
254
+
255
+ # line 99 "lib/graphql/language/lexer.rl"
256
+
257
+ emit_token = -> (name) {
258
+ emit(name, ts, te, meta)
259
+ }
260
+
261
+
262
+ # line 263 "lib/graphql/language/lexer.rb"
263
+ begin
264
+ _klen, _trans, _keys, _acts, _nacts = nil
265
+ _goto_level = 0
266
+ _resume = 10
267
+ _eof_trans = 15
268
+ _again = 20
269
+ _test_eof = 30
270
+ _out = 40
271
+ while true
272
+ _trigger_goto = false
273
+ if _goto_level <= 0
274
+ if p == pe
275
+ _goto_level = _test_eof
276
+ next
277
+ end
278
+ if cs == 0
279
+ _goto_level = _out
280
+ next
281
+ end
282
+ end
283
+ if _goto_level <= _resume
284
+ _acts = _graphql_lexer_from_state_actions[cs]
285
+ _nacts = _graphql_lexer_actions[_acts]
286
+ _acts += 1
287
+ while _nacts > 0
288
+ _nacts -= 1
289
+ _acts += 1
290
+ case _graphql_lexer_actions[_acts - 1]
291
+ when 2 then
292
+ # line 1 "NONE"
293
+ begin
294
+ ts = p
295
+ end
296
+ # line 297 "lib/graphql/language/lexer.rb"
297
+ end # from state action switch
298
+ end
299
+ if _trigger_goto
300
+ next
301
+ end
302
+ _keys = _graphql_lexer_key_offsets[cs]
303
+ _trans = _graphql_lexer_index_offsets[cs]
304
+ _klen = _graphql_lexer_single_lengths[cs]
305
+ _break_match = false
306
+
307
+ begin
308
+ if _klen > 0
309
+ _lower = _keys
310
+ _upper = _keys + _klen - 1
311
+
312
+ loop do
313
+ break if _upper < _lower
314
+ _mid = _lower + ( (_upper - _lower) >> 1 )
315
+
316
+ if data[p].ord < _graphql_lexer_trans_keys[_mid]
317
+ _upper = _mid - 1
318
+ elsif data[p].ord > _graphql_lexer_trans_keys[_mid]
319
+ _lower = _mid + 1
320
+ else
321
+ _trans += (_mid - _keys)
322
+ _break_match = true
323
+ break
324
+ end
325
+ end # loop
326
+ break if _break_match
327
+ _keys += _klen
328
+ _trans += _klen
329
+ end
330
+ _klen = _graphql_lexer_range_lengths[cs]
331
+ if _klen > 0
332
+ _lower = _keys
333
+ _upper = _keys + (_klen << 1) - 2
334
+ loop do
335
+ break if _upper < _lower
336
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1)
337
+ if data[p].ord < _graphql_lexer_trans_keys[_mid]
338
+ _upper = _mid - 2
339
+ elsif data[p].ord > _graphql_lexer_trans_keys[_mid+1]
340
+ _lower = _mid + 2
341
+ else
342
+ _trans += ((_mid - _keys) >> 1)
343
+ _break_match = true
344
+ break
345
+ end
346
+ end # loop
347
+ break if _break_match
348
+ _trans += _klen
349
+ end
350
+ end while false
351
+ _trans = _graphql_lexer_indicies[_trans]
352
+ end
353
+ if _goto_level <= _eof_trans
354
+ cs = _graphql_lexer_trans_targs[_trans]
355
+ if _graphql_lexer_trans_actions[_trans] != 0
356
+ _acts = _graphql_lexer_trans_actions[_trans]
357
+ _nacts = _graphql_lexer_actions[_acts]
358
+ _acts += 1
359
+ while _nacts > 0
360
+ _nacts -= 1
361
+ _acts += 1
362
+ case _graphql_lexer_actions[_acts - 1]
363
+ when 3 then
364
+ # line 1 "NONE"
365
+ begin
366
+ te = p+1
367
+ end
368
+ when 4 then
369
+ # line 35 "lib/graphql/language/lexer.rl"
370
+ begin
371
+ act = 1; end
372
+ when 5 then
373
+ # line 36 "lib/graphql/language/lexer.rl"
374
+ begin
375
+ act = 2; end
376
+ when 6 then
377
+ # line 37 "lib/graphql/language/lexer.rl"
378
+ begin
379
+ act = 3; end
380
+ when 7 then
381
+ # line 38 "lib/graphql/language/lexer.rl"
382
+ begin
383
+ act = 4; end
384
+ when 8 then
385
+ # line 39 "lib/graphql/language/lexer.rl"
386
+ begin
387
+ act = 5; end
388
+ when 9 then
389
+ # line 40 "lib/graphql/language/lexer.rl"
390
+ begin
391
+ act = 6; end
392
+ when 10 then
393
+ # line 48 "lib/graphql/language/lexer.rl"
394
+ begin
395
+ act = 14; end
396
+ when 11 then
397
+ # line 54 "lib/graphql/language/lexer.rl"
398
+ begin
399
+ act = 20; end
400
+ when 12 then
401
+ # line 41 "lib/graphql/language/lexer.rl"
402
+ begin
403
+ te = p+1
404
+ begin emit_token.call(:RCURLY) end
405
+ end
406
+ when 13 then
407
+ # line 42 "lib/graphql/language/lexer.rl"
408
+ begin
409
+ te = p+1
410
+ begin emit_token.call(:LCURLY) end
411
+ end
412
+ when 14 then
413
+ # line 43 "lib/graphql/language/lexer.rl"
414
+ begin
415
+ te = p+1
416
+ begin emit_token.call(:RPAREN) end
417
+ end
418
+ when 15 then
419
+ # line 44 "lib/graphql/language/lexer.rl"
420
+ begin
421
+ te = p+1
422
+ begin emit_token.call(:LPAREN) end
423
+ end
424
+ when 16 then
425
+ # line 45 "lib/graphql/language/lexer.rl"
426
+ begin
427
+ te = p+1
428
+ begin emit_token.call(:RBRACKET) end
429
+ end
430
+ when 17 then
431
+ # line 46 "lib/graphql/language/lexer.rl"
432
+ begin
433
+ te = p+1
434
+ begin emit_token.call(:LBRACKET) end
435
+ end
436
+ when 18 then
437
+ # line 47 "lib/graphql/language/lexer.rl"
438
+ begin
439
+ te = p+1
440
+ begin emit_token.call(:COLON) end
441
+ end
442
+ when 19 then
443
+ # line 48 "lib/graphql/language/lexer.rl"
444
+ begin
445
+ te = p+1
446
+ begin emit_string(ts + 1, te - 1, meta) end
447
+ end
448
+ when 20 then
449
+ # line 49 "lib/graphql/language/lexer.rl"
450
+ begin
451
+ te = p+1
452
+ begin emit_token.call(:VAR_SIGN) end
453
+ end
454
+ when 21 then
455
+ # line 50 "lib/graphql/language/lexer.rl"
456
+ begin
457
+ te = p+1
458
+ begin emit_token.call(:DIR_SIGN) end
459
+ end
460
+ when 22 then
461
+ # line 51 "lib/graphql/language/lexer.rl"
462
+ begin
463
+ te = p+1
464
+ begin emit_token.call(:ELLIPSIS) end
465
+ end
466
+ when 23 then
467
+ # line 52 "lib/graphql/language/lexer.rl"
468
+ begin
469
+ te = p+1
470
+ begin emit_token.call(:EQUALS) end
471
+ end
472
+ when 24 then
473
+ # line 53 "lib/graphql/language/lexer.rl"
474
+ begin
475
+ te = p+1
476
+ begin emit_token.call(:BANG) end
477
+ end
478
+ when 25 then
479
+ # line 56 "lib/graphql/language/lexer.rl"
480
+ begin
481
+ te = p+1
482
+ begin
483
+ meta[:line] += 1
484
+ meta[:col] = 1
485
+ end
486
+ end
487
+ when 26 then
488
+ # line 35 "lib/graphql/language/lexer.rl"
489
+ begin
490
+ te = p
491
+ p = p - 1; begin emit_token.call(:INT) end
492
+ end
493
+ when 27 then
494
+ # line 36 "lib/graphql/language/lexer.rl"
495
+ begin
496
+ te = p
497
+ p = p - 1; begin emit_token.call(:FLOAT) end
498
+ end
499
+ when 28 then
500
+ # line 48 "lib/graphql/language/lexer.rl"
501
+ begin
502
+ te = p
503
+ p = p - 1; begin emit_string(ts + 1, te - 1, meta) end
504
+ end
505
+ when 29 then
506
+ # line 54 "lib/graphql/language/lexer.rl"
507
+ begin
508
+ te = p
509
+ p = p - 1; begin emit_token.call(:IDENTIFIER) end
510
+ end
511
+ when 30 then
512
+ # line 61 "lib/graphql/language/lexer.rl"
513
+ begin
514
+ te = p
515
+ p = p - 1; begin meta[:col] += te - ts end
516
+ end
517
+ when 31 then
518
+ # line 62 "lib/graphql/language/lexer.rl"
519
+ begin
520
+ te = p
521
+ p = p - 1; begin meta[:col] += te - ts end
522
+ end
523
+ when 32 then
524
+ # line 35 "lib/graphql/language/lexer.rl"
525
+ begin
526
+ begin p = ((te))-1; end
527
+ begin emit_token.call(:INT) end
528
+ end
529
+ when 33 then
530
+ # line 1 "NONE"
531
+ begin
532
+ case act
533
+ when 0 then
534
+ begin begin
535
+ cs = 0
536
+ _trigger_goto = true
537
+ _goto_level = _again
538
+ break
539
+ end
540
+ end
541
+ when 1 then
542
+ begin begin p = ((te))-1; end
543
+ emit_token.call(:INT) end
544
+ when 2 then
545
+ begin begin p = ((te))-1; end
546
+ emit_token.call(:FLOAT) end
547
+ when 3 then
548
+ begin begin p = ((te))-1; end
549
+ emit_token.call(:ON) end
550
+ when 4 then
551
+ begin begin p = ((te))-1; end
552
+ emit_token.call(:FRAGMENT) end
553
+ when 5 then
554
+ begin begin p = ((te))-1; end
555
+ emit_token.call(:TRUE) end
556
+ when 6 then
557
+ begin begin p = ((te))-1; end
558
+ emit_token.call(:FALSE) end
559
+ when 14 then
560
+ begin begin p = ((te))-1; end
561
+ emit_string(ts + 1, te - 1, meta) end
562
+ when 20 then
563
+ begin begin p = ((te))-1; end
564
+ emit_token.call(:IDENTIFIER) end
565
+ end
566
+ end
567
+ # line 568 "lib/graphql/language/lexer.rb"
568
+ end # action switch
569
+ end
570
+ end
571
+ if _trigger_goto
572
+ next
573
+ end
574
+ end
575
+ if _goto_level <= _again
576
+ _acts = _graphql_lexer_to_state_actions[cs]
577
+ _nacts = _graphql_lexer_actions[_acts]
578
+ _acts += 1
579
+ while _nacts > 0
580
+ _nacts -= 1
581
+ _acts += 1
582
+ case _graphql_lexer_actions[_acts - 1]
583
+ when 0 then
584
+ # line 1 "NONE"
585
+ begin
586
+ ts = nil; end
587
+ when 1 then
588
+ # line 1 "NONE"
589
+ begin
590
+ act = 0
591
+ end
592
+ # line 593 "lib/graphql/language/lexer.rb"
593
+ end # to state action switch
594
+ end
595
+ if _trigger_goto
596
+ next
597
+ end
598
+ if cs == 0
599
+ _goto_level = _out
600
+ next
601
+ end
602
+ p += 1
603
+ if p != pe
604
+ _goto_level = _resume
605
+ next
606
+ end
607
+ end
608
+ if _goto_level <= _test_eof
609
+ if p == eof
610
+ if _graphql_lexer_eof_trans[cs] > 0
611
+ _trans = _graphql_lexer_eof_trans[cs] - 1;
612
+ _goto_level = _eof_trans
613
+ next;
614
+ end
615
+ end
616
+ end
617
+ if _goto_level <= _out
618
+ break
619
+ end
620
+ end
621
+ end
622
+
623
+ # line 105 "lib/graphql/language/lexer.rl"
624
+
625
+ meta[:tokens]
626
+ end
627
+
628
+ def self.emit(token_name, ts, te, meta)
629
+ meta[:tokens] << GraphQL::Language::Token.new(
630
+ name: token_name,
631
+ value: meta[:data][ts...te].pack("c*"),
632
+ line: meta[:line],
633
+ col: meta[:col],
634
+ )
635
+ # Bump the column counter for the next token
636
+ meta[:col] += te - ts
637
+ end
638
+
639
+ ESCAPES = /\\["\\\/bfnrt]/
640
+ ESCAPES_REPLACE = {
641
+ '\\"' => '"',
642
+ "\\\\" => "\\",
643
+ "\\/" => '/',
644
+ "\\b" => "\b",
645
+ "\\f" => "\f",
646
+ "\\n" => "\n",
647
+ "\\r" => "\r",
648
+ "\\t" => "\t",
649
+ }
650
+
651
+ UTF_8 = /\\u[\dAa-f]{4}/i
652
+ UTF_8_REPLACE = -> (m) { [m[-4..-1].to_i(16)].pack('U'.freeze) }
653
+
654
+ def self.emit_string(ts, te, meta)
655
+ value = meta[:data][ts...te].pack("c*").force_encoding("UTF-8")
656
+ replace_escaped_characters_in_place(value)
657
+
658
+ meta[:tokens] << GraphQL::Language::Token.new(
659
+ name: :STRING,
660
+ value: value,
661
+ line: meta[:line],
662
+ col: meta[:col],
663
+ )
664
+ meta[:col] += te - ts
665
+ end
666
+ end
667
+ end
668
+ end