graphql 0.14.2 → 0.15.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.
- checksums.yaml +4 -4
- data/lib/graphql/language/lexer.rb +152 -234
- data/lib/graphql/language/lexer.rl +0 -6
- data/lib/graphql/language/parser.rb +300 -343
- data/lib/graphql/language/parser.y +1 -9
- data/lib/graphql/query.rb +2 -10
- data/lib/graphql/query/executor.rb +4 -9
- data/lib/graphql/query/serial_execution/field_resolution.rb +6 -8
- data/lib/graphql/schema.rb +0 -26
- data/lib/graphql/static_validation/type_stack.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/readme.md +1 -2
- data/spec/graphql/query/executor_spec.rb +2 -21
- data/spec/graphql/query/serial_execution/execution_context_spec.rb +0 -2
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +0 -3
- data/spec/graphql/query_spec.rb +0 -4
- metadata +2 -2
@@ -13,7 +13,7 @@ rule
|
|
13
13
|
| fragment_definition
|
14
14
|
|
15
15
|
operation_definition:
|
16
|
-
|
16
|
+
name operation_name_opt variable_definitions_opt directives_list_opt selection_set {
|
17
17
|
return make_node(
|
18
18
|
:OperationDefinition, {
|
19
19
|
operation_type: val[0],
|
@@ -34,11 +34,6 @@ rule
|
|
34
34
|
)
|
35
35
|
}
|
36
36
|
|
37
|
-
operation_type:
|
38
|
-
QUERY
|
39
|
-
| MUTATION
|
40
|
-
| SUBSCRIPTION
|
41
|
-
|
42
37
|
operation_name_opt:
|
43
38
|
/* none */ { return nil }
|
44
39
|
| name
|
@@ -121,9 +116,6 @@ rule
|
|
121
116
|
| FRAGMENT
|
122
117
|
| TRUE
|
123
118
|
| FALSE
|
124
|
-
| QUERY
|
125
|
-
| MUTATION
|
126
|
-
| SUBSCRIPTION
|
127
119
|
|
128
120
|
arguments_opt:
|
129
121
|
/* none */ { return [] }
|
data/lib/graphql/query.rb
CHANGED
@@ -8,28 +8,20 @@ module GraphQL
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_reader :schema, :document, :context, :fragments, :operations, :
|
11
|
+
attr_reader :schema, :document, :context, :fragments, :operations, :root_value, :max_depth
|
12
12
|
|
13
13
|
# Prepare query `query_string` on `schema`
|
14
14
|
# @param schema [GraphQL::Schema]
|
15
15
|
# @param query_string [String]
|
16
16
|
# @param context [#[]] an arbitrary hash of values which you can access in {GraphQL::Field#resolve}
|
17
17
|
# @param variables [Hash] values for `$variables` in the query
|
18
|
-
# @param debug [Boolean] DEPRECATED if true, errors are raised, if false, errors are put in the `errors` key
|
19
18
|
# @param validate [Boolean] if true, `query_string` will be validated with {StaticValidation::Validator}
|
20
19
|
# @param operation_name [String] if the query string contains many operations, this is the one which should be executed
|
21
20
|
# @param root_value [Object] the object used to resolve fields on the root type
|
22
|
-
def initialize(schema, query_string = nil, document: nil, context: nil, variables: {},
|
21
|
+
def initialize(schema, query_string = nil, document: nil, context: nil, variables: {}, validate: true, operation_name: nil, root_value: nil, max_depth: nil)
|
23
22
|
fail ArgumentError, "a query string or document is required" unless query_string || document
|
24
23
|
|
25
24
|
@schema = schema
|
26
|
-
if debug == false
|
27
|
-
warn("Muffling errors with `debug: false` is deprecated and will be removed. For a similar behavior, use `MySchema.middleware << GraphQL::Schema::CatchallMiddleware`.")
|
28
|
-
elsif debug == true
|
29
|
-
warn("`debug:` will be removed from a future GraphQL version (and raising errors will be the default behavior, like `debug: true`)")
|
30
|
-
end
|
31
|
-
@debug = debug || false
|
32
|
-
|
33
25
|
@max_depth = max_depth || schema.max_depth
|
34
26
|
@context = Context.new(query: self, values: context)
|
35
27
|
@root_value = root_value
|
@@ -8,19 +8,14 @@ module GraphQL
|
|
8
8
|
@query = query
|
9
9
|
end
|
10
10
|
|
11
|
-
# Evalute {operation_name} on {query}.
|
12
|
-
#
|
11
|
+
# Evalute {operation_name} on {query}.
|
12
|
+
# Handle {GraphQL::ExecutionError}s by putting them in the "errors" key.
|
13
13
|
# @return [Hash] A GraphQL response, with either a "data" key or an "errors" key
|
14
14
|
def result
|
15
15
|
execute
|
16
16
|
rescue GraphQL::ExecutionError => err
|
17
17
|
query.context.errors << err
|
18
18
|
{"errors" => [err.to_h]}
|
19
|
-
rescue StandardError => err
|
20
|
-
query.context.errors << err
|
21
|
-
query.debug && raise(err)
|
22
|
-
message = "Internal error" # : #{err} \n#{err.backtrace.join("\n ")}"
|
23
|
-
{"errors" => [{"message" => message}]}
|
24
19
|
end
|
25
20
|
|
26
21
|
private
|
@@ -30,8 +25,8 @@ module GraphQL
|
|
30
25
|
return {} if operation.nil?
|
31
26
|
|
32
27
|
op_type = operation.operation_type
|
33
|
-
root_type = query.schema.
|
34
|
-
execution_strategy_class = query.schema.
|
28
|
+
root_type = query.schema.public_send(op_type)
|
29
|
+
execution_strategy_class = query.schema.public_send("#{op_type}_execution_strategy")
|
35
30
|
execution_strategy = execution_strategy_class.new
|
36
31
|
|
37
32
|
query.context.execution_strategy = execution_strategy
|
@@ -22,11 +22,7 @@ module GraphQL
|
|
22
22
|
|
23
23
|
def result
|
24
24
|
result_name = ast_node.alias || ast_node.name
|
25
|
-
raw_value =
|
26
|
-
get_raw_value
|
27
|
-
rescue GraphQL::ExecutionError => err
|
28
|
-
err
|
29
|
-
end
|
25
|
+
raw_value = get_raw_value
|
30
26
|
{ result_name => get_finished_value(raw_value) }
|
31
27
|
end
|
32
28
|
|
@@ -49,15 +45,17 @@ module GraphQL
|
|
49
45
|
# Get the result of:
|
50
46
|
# - Any middleware on this schema
|
51
47
|
# - The field's resolve method
|
48
|
+
# If the middleware chain returns a GraphQL::ExecutionError, its message
|
49
|
+
# is added to the "errors" key.
|
52
50
|
def get_raw_value
|
53
51
|
steps = execution_context.query.schema.middleware + [get_middleware_proc_from_field_resolve]
|
54
52
|
chain = GraphQL::Schema::MiddlewareChain.new(
|
55
53
|
steps: steps,
|
56
54
|
arguments: [parent_type, target, field, arguments, execution_context.query.context]
|
57
55
|
)
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
chain.call
|
57
|
+
rescue GraphQL::ExecutionError => err
|
58
|
+
err
|
61
59
|
end
|
62
60
|
|
63
61
|
|
data/lib/graphql/schema.rb
CHANGED
@@ -92,31 +92,5 @@ module GraphQL
|
|
92
92
|
@interface_possible_types ||= GraphQL::Schema::PossibleTypes.new(self)
|
93
93
|
@interface_possible_types.possible_types(type_defn)
|
94
94
|
end
|
95
|
-
|
96
|
-
def root_type_for_operation(operation)
|
97
|
-
case operation
|
98
|
-
when "query"
|
99
|
-
query
|
100
|
-
when "mutation"
|
101
|
-
mutation
|
102
|
-
when "subscription"
|
103
|
-
subscription
|
104
|
-
else
|
105
|
-
raise ArgumentError, "unknown operation type: #{operation}"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def execution_strategy_for_operation(operation)
|
110
|
-
case operation
|
111
|
-
when "query"
|
112
|
-
query_execution_strategy
|
113
|
-
when "mutation"
|
114
|
-
mutation_execution_strategy
|
115
|
-
when "subscription"
|
116
|
-
subscription_execution_strategy
|
117
|
-
else
|
118
|
-
raise ArgumentError, "unknown operation type: #{operation}"
|
119
|
-
end
|
120
|
-
end
|
121
95
|
end
|
122
96
|
end
|
@@ -76,7 +76,7 @@ module GraphQL
|
|
76
76
|
class OperationDefinitionStrategy
|
77
77
|
def push(stack, node)
|
78
78
|
# eg, QueryType, MutationType
|
79
|
-
object_type = stack.schema.
|
79
|
+
object_type = stack.schema.public_send(node.operation_type)
|
80
80
|
stack.object_types.push(object_type)
|
81
81
|
end
|
82
82
|
|
data/lib/graphql/version.rb
CHANGED
data/readme.md
CHANGED
@@ -120,8 +120,7 @@ If you're building a backend for [Relay](http://facebook.github.io/relay/), you'
|
|
120
120
|
## To Do
|
121
121
|
|
122
122
|
- __1.0 items:__
|
123
|
-
- Support type name for field types
|
124
|
-
- Revisit error handling & `debug:` option
|
123
|
+
- Support type name for field types?
|
125
124
|
- Add a complexity validator (reject queries if they're too big)
|
126
125
|
- Add docs for shared behaviors & DRY code
|
127
126
|
- __Subscriptions__
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe GraphQL::Query::Executor do
|
4
|
-
let(:debug) { true }
|
5
4
|
let(:operation_name) { nil }
|
6
5
|
let(:schema) { DummySchema }
|
7
6
|
let(:variables) { {"cheeseId" => 2} }
|
@@ -9,7 +8,6 @@ describe GraphQL::Query::Executor do
|
|
9
8
|
schema,
|
10
9
|
query_string,
|
11
10
|
variables: variables,
|
12
|
-
debug: debug,
|
13
11
|
operation_name: operation_name,
|
14
12
|
)}
|
15
13
|
let(:result) { query.result }
|
@@ -118,25 +116,8 @@ describe GraphQL::Query::Executor do
|
|
118
116
|
describe "runtime errors" do
|
119
117
|
let(:query_string) {%| query noMilk { error }|}
|
120
118
|
|
121
|
-
|
122
|
-
|
123
|
-
let(:errors) { query.context.errors }
|
124
|
-
|
125
|
-
it "turns into error messages" do
|
126
|
-
expected = {"errors"=>[
|
127
|
-
{"message"=>"Internal error"}
|
128
|
-
]}
|
129
|
-
assert_equal(expected, result)
|
130
|
-
assert_equal([RuntimeError], errors.map(&:class))
|
131
|
-
assert_equal("This error was raised on purpose", errors.first.message)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe "if debug: true" do
|
136
|
-
let(:debug) { true }
|
137
|
-
it "raises error" do
|
138
|
-
assert_raises(RuntimeError) { result }
|
139
|
-
end
|
119
|
+
it "raises error" do
|
120
|
+
assert_raises(RuntimeError) { result }
|
140
121
|
end
|
141
122
|
|
142
123
|
describe "if nil is given for a non-null field" do
|
@@ -7,7 +7,6 @@ describe GraphQL::Query::SerialExecution::ExecutionContext do
|
|
7
7
|
}
|
8
8
|
fragment cheeseFields on Cheese { flavor }
|
9
9
|
|}
|
10
|
-
let(:debug) { false }
|
11
10
|
let(:operation_name) { nil }
|
12
11
|
let(:query_variables) { {"cheeseId" => 2} }
|
13
12
|
let(:schema) { DummySchema }
|
@@ -15,7 +14,6 @@ describe GraphQL::Query::SerialExecution::ExecutionContext do
|
|
15
14
|
schema,
|
16
15
|
query_string,
|
17
16
|
variables: query_variables,
|
18
|
-
debug: debug,
|
19
17
|
operation_name: operation_name,
|
20
18
|
)}
|
21
19
|
let(:execution_context) {
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe GraphQL::Query::SerialExecution::ValueResolution do
|
4
|
-
let(:debug) { false }
|
5
4
|
let(:query_root) {
|
6
5
|
day_of_week_enum = GraphQL::EnumType.define do
|
7
6
|
name "DayOfWeek"
|
@@ -34,7 +33,6 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
|
|
34
33
|
let(:schema) { GraphQL::Schema.new(query: query_root) }
|
35
34
|
let(:result) { schema.execute(
|
36
35
|
query_string,
|
37
|
-
debug: debug,
|
38
36
|
)}
|
39
37
|
|
40
38
|
describe "enum resolution" do
|
@@ -55,7 +53,6 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
|
|
55
53
|
end
|
56
54
|
|
57
55
|
describe "interface type resolution" do
|
58
|
-
let(:debug) { true }
|
59
56
|
let(:query_string) { %|
|
60
57
|
{
|
61
58
|
misbehavedInterface { someField }
|
data/spec/graphql/query_spec.rb
CHANGED
@@ -28,7 +28,6 @@ describe GraphQL::Query do
|
|
28
28
|
... on Milk { source }
|
29
29
|
}
|
30
30
|
|}
|
31
|
-
let(:debug) { false }
|
32
31
|
let(:operation_name) { nil }
|
33
32
|
let(:max_depth) { nil }
|
34
33
|
let(:query_variables) { {"cheeseId" => 2} }
|
@@ -39,7 +38,6 @@ describe GraphQL::Query do
|
|
39
38
|
schema,
|
40
39
|
query_string,
|
41
40
|
variables: query_variables,
|
42
|
-
debug: debug,
|
43
41
|
operation_name: operation_name,
|
44
42
|
max_depth: max_depth,
|
45
43
|
)}
|
@@ -51,7 +49,6 @@ describe GraphQL::Query do
|
|
51
49
|
GraphQL::Query.new(
|
52
50
|
schema,
|
53
51
|
variables: query_variables,
|
54
|
-
debug: debug,
|
55
52
|
operation_name: operation_name,
|
56
53
|
max_depth: max_depth,
|
57
54
|
)
|
@@ -64,7 +61,6 @@ describe GraphQL::Query do
|
|
64
61
|
schema,
|
65
62
|
document: document,
|
66
63
|
variables: query_variables,
|
67
|
-
debug: debug,
|
68
64
|
operation_name: operation_name,
|
69
65
|
max_depth: max_depth,
|
70
66
|
)}
|
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.
|
4
|
+
version: 0.15.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-06-
|
11
|
+
date: 2016-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|