graphql 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8c997dbb80987c2b0312c95913b8cb7bef898be
4
- data.tar.gz: f77f1a3b90d96887a93ee560f8dd5ba5370a4453
3
+ metadata.gz: cace79bd801a58fbf53eb0ff5a5ef4ea501b1208
4
+ data.tar.gz: 495b61e0510a41d880db3a99008446650196742a
5
5
  SHA512:
6
- metadata.gz: 4f20614f4bcefc6ed7771c516046ae24581785ea25579e0bd5a8bdcad1cbd7d5eca7c981e59b4eec08bb54772cdb15c3f5f44f62eee1ea51d224e2c87608c821
7
- data.tar.gz: a525157abbc09c4b1abd6e55a18b975305dbb93d8583709850bc159cb2e7d87ee62dd3b3d7fddf9188daa3e6c07f1bb83f2c8715c921c8b12b1e898e823dfbf0
6
+ metadata.gz: 635f9a6cbc5d9093227b3699cb93271526c105fff445bacc4e1a39777a51a6b8db1fcc5c692271a0de4d00045b2dd3d33b39dfea90f33c74176ef6ea3e7a57cb
7
+ data.tar.gz: 8ca5879203ad6178ad7fff7e3ef12e76de2c90825b1de2e5efd831afe654f49bb3d02b0f9ef6a5d5654586ee20693452ba971e645717d2e561caba396c6c1e3d
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require "parslet"
3
+ require "set"
3
4
  require "singleton"
4
5
  require "forwardable"
5
6
 
@@ -5,6 +5,7 @@ query IntrospectionQuery {
5
5
  __schema {
6
6
  queryType { name }
7
7
  mutationType { name }
8
+ subscriptionType { name }
8
9
  types {
9
10
  ...FullType
10
11
  }
@@ -24,7 +25,7 @@ fragment FullType on __Type {
24
25
  kind
25
26
  name
26
27
  description
27
- fields {
28
+ fields(includeDeprecated: true) {
28
29
  name
29
30
  description
30
31
  args {
@@ -42,7 +43,7 @@ fragment FullType on __Type {
42
43
  interfaces {
43
44
  ...TypeRef
44
45
  }
45
- enumValues {
46
+ enumValues(includeDeprecated: true) {
46
47
  name
47
48
  description
48
49
  isDeprecated
@@ -17,4 +17,8 @@ GraphQL::Introspection::SchemaType = GraphQL::ObjectType.define do
17
17
  field :mutationType, GraphQL::Introspection::TypeType, "The mutation root of this schema" do
18
18
  resolve -> (obj, arg, ctx) { obj.mutation }
19
19
  end
20
+
21
+ field :subscriptionType, GraphQL::Introspection::TypeType, "The subscription root of this schema" do
22
+ resolve -> (obj, arg, ctx) { obj.subscription }
23
+ end
20
24
  end
@@ -43,7 +43,7 @@ module GraphQL
43
43
  directives.maybe.as(:optional_directives).as(:directives) >> space? >>
44
44
  selections.as(:selections)
45
45
  }
46
- rule(:operation_type) { (str("query") | str("mutation")) }
46
+ rule(:operation_type) { (str("query") | str("mutation") | str("subscription")) }
47
47
  rule(:operation_variable_definitions) { str("(") >> space? >> (operation_variable_definition >> separator?).repeat(1) >> space? >> str(")") }
48
48
  rule(:operation_variable_definition) {
49
49
  value_variable.as(:variable_name) >> space? >>
@@ -29,14 +29,11 @@ module GraphQL
29
29
  operation = query.selected_operation
30
30
  return {} if operation.nil?
31
31
 
32
- if operation.operation_type == "query"
33
- root_type = query.schema.query
34
- execution_strategy_class = query.schema.query_execution_strategy
35
- elsif operation.operation_type == "mutation"
36
- root_type = query.schema.mutation
37
- execution_strategy_class = query.schema.mutation_execution_strategy
38
- end
32
+ op_type = operation.operation_type
33
+ root_type = query.schema.public_send(op_type)
34
+ execution_strategy_class = query.schema.public_send("#{op_type}_execution_strategy")
39
35
  execution_strategy = execution_strategy_class.new
36
+
40
37
  query.context.execution_strategy = execution_strategy
41
38
  data_result = execution_strategy.execute(operation, root_type, query)
42
39
  result = { "data" => data_result }
@@ -5,18 +5,22 @@ class GraphQL::Schema
5
5
  DIRECTIVES = [GraphQL::Directive::SkipDirective, GraphQL::Directive::IncludeDirective]
6
6
  DYNAMIC_FIELDS = ["__type", "__typename", "__schema"]
7
7
 
8
- attr_reader :query, :mutation, :directives, :static_validator
8
+ attr_reader :query, :mutation, :subscription, :directives, :static_validator
9
9
  # Override these if you don't want the default executor:
10
- attr_accessor :query_execution_strategy, :mutation_execution_strategy
10
+ attr_accessor :query_execution_strategy,
11
+ :mutation_execution_strategy,
12
+ :subscription_execution_strategy
11
13
 
12
14
  # @return [Array<#call>] Middlewares suitable for MiddlewareChain, applied to fields during execution
13
15
  attr_reader :middleware
14
16
 
15
17
  # @param query [GraphQL::ObjectType] the query root for the schema
16
- # @param mutation [GraphQL::ObjectType, nil] the mutation root for the schema
17
- def initialize(query:, mutation: nil)
18
+ # @param mutation [GraphQL::ObjectType] the mutation root for the schema
19
+ # @param subscription [GraphQL::ObjectType] the subscription root for the schema
20
+ def initialize(query:, mutation: nil, subscription: nil)
18
21
  @query = query
19
22
  @mutation = mutation
23
+ @subscription = subscription
20
24
  @directives = DIRECTIVES.reduce({}) { |m, d| m[d.name] = d; m }
21
25
  @static_validator = GraphQL::StaticValidation::Validator.new(schema: self)
22
26
  @rescue_middleware = GraphQL::Schema::RescueMiddleware.new
@@ -24,6 +28,7 @@ class GraphQL::Schema
24
28
  # Default to the built-in execution strategy:
25
29
  self.query_execution_strategy = GraphQL::Query::SerialExecution
26
30
  self.mutation_execution_strategy = GraphQL::Query::SerialExecution
31
+ self.subscription_execution_strategy = GraphQL::Query::SerialExecution
27
32
  end
28
33
 
29
34
  def_delegators :@rescue_middleware, :rescue_from, :remove_handler
@@ -1,3 +1,3 @@
1
1
  module GraphQL
2
- VERSION = "0.10.2"
2
+ VERSION = "0.10.3"
3
3
  end
@@ -22,6 +22,9 @@ describe GraphQL::Language::Parser do
22
22
  ... family # background info, of course
23
23
  }
24
24
  }
25
+ subscription watchStuff {
26
+ field, otherField
27
+ }
25
28
 
26
29
  # a fragment:
27
30
  fragment family on Species {
@@ -41,7 +44,7 @@ describe GraphQL::Language::Parser do
41
44
  it 'parses operation definitions' do
42
45
  assert(parser.operation_definition.parse_with_debug(%|{id, name, ...people}|), "just a selection")
43
46
  assert(parser.operation_definition.parse_with_debug(%|query personStuff {id, name, ...people, ... stuff}|), "named fetch")
44
- assert(parser.operation_definition.parse_with_debug(%|query personStuff @flagDirective {id, name, ...people}|), "with a directive")
47
+ assert(parser.operation_definition.parse_with_debug(%|subscription personStuff @flagDirective {id, name, ...people}|), "with a directive")
45
48
  assert(parser.operation_definition.parse_with_debug(%|mutation changeStuff($stuff: Int = 1 $things: [SomeType]! = [{something: 1}, {something: 2}], $another: Sometype = {something: 3}) { id }|), "mutation with arguments")
46
49
  assert(parser.operation_definition.parse_with_debug(%|mutation { id }|), "unnamed")
47
50
  end
@@ -103,6 +103,7 @@ type __Schema {
103
103
  directives: [__Directive!]!
104
104
  queryType: __Type!
105
105
  mutationType: __Type
106
+ subscriptionType: __Type
106
107
  }
107
108
 
108
109
  type __Type {
@@ -13,4 +13,11 @@ describe GraphQL::Schema do
13
13
  assert_equal(2, rescue_middleware.rescue_table.length)
14
14
  end
15
15
  end
16
+
17
+ describe "#subscription" do
18
+ it "calls fields on the subscription type" do
19
+ res = schema.execute("subscription { test }")
20
+ assert_equal("Test", res["data"]["test"])
21
+ end
22
+ end
16
23
  end
@@ -1,73 +1,74 @@
1
1
  # This GraphQL Schema performs operations on numbers.
2
2
  # It can perform operations on values you give it and return values
3
3
  # It also maintains some state which can be updated or read
4
+ module Calculator
5
+ # You can reduce a list of values to a single value
6
+ REDUCERS = {
7
+ "SUM" => -> (values) { [values.inject(&:+)] },
8
+ "MAX" => :max.to_proc,
9
+ "MIN" => :min.to_proc,
10
+ }
4
11
 
5
- # You can reduce a list of values to a single value
6
- REDUCERS = {
7
- "SUM" => -> (values) { [values.inject(&:+)] },
8
- "MAX" => :max.to_proc,
9
- "MIN" => :min.to_proc,
10
- }
11
-
12
- ReducerEnum = GraphQL::EnumType.define do
13
- REDUCERS.map do |op_name, op_proc|
14
- value(op_name)
12
+ ReducerEnum = GraphQL::EnumType.define do
13
+ REDUCERS.map do |op_name, op_proc|
14
+ value(op_name)
15
+ end
15
16
  end
16
- end
17
17
 
18
- # You can make a new list by transforming each member
19
- MAPPERS = {
20
- "ADD" => -> (val, arg) { val + arg },
21
- "SUB" => -> (val, arg) { val - arg },
22
- "EQ" => -> (val, arg) { val == arg ? 1 : 0},
23
- }
18
+ # You can make a new list by transforming each member
19
+ MAPPERS = {
20
+ "ADD" => -> (val, arg) { val + arg },
21
+ "SUB" => -> (val, arg) { val - arg },
22
+ "EQ" => -> (val, arg) { val == arg ? 1 : 0},
23
+ }
24
24
 
25
- MapperEnum = GraphQL::EnumType.define do
26
- MAPPERS.map do |op_name, op_proc|
27
- value(op_name)
25
+ MapperEnum = GraphQL::EnumType.define do
26
+ MAPPERS.map do |op_name, op_proc|
27
+ value(op_name)
28
+ end
28
29
  end
29
- end
30
30
 
31
- # Input a list of integers
32
- ListOfInts = GraphQL::INT_TYPE.to_list_type
31
+ # Input a list of integers
32
+ ListOfInts = GraphQL::INT_TYPE.to_list_type
33
33
 
34
- # Expose a list of values and perform operations
35
- ValuesType = GraphQL::ObjectType.define do
36
- field :values, ListOfInts do
37
- resolve -> (obj, _args, _ctx) { obj }
38
- end
34
+ # Expose a list of values and perform operations
35
+ ValuesType = GraphQL::ObjectType.define do
36
+ field :values, ListOfInts do
37
+ resolve -> (obj, _args, _ctx) { obj }
38
+ end
39
39
 
40
- # Get a single value based on the values in this list
41
- field :reduce, types.Int do
42
- argument :operation, !ReducerEnum
43
- resolve -> (obj, args, ctx) {
44
- reduce_name = args[:operation]
45
- reduce_fn = REDUCERS[reduce_name]
46
- reduce_fn.call(obj)
47
- }
48
- end
40
+ # Get a single value based on the values in this list
41
+ field :reduce, types.Int do
42
+ argument :operation, !ReducerEnum
43
+ resolve -> (obj, args, ctx) {
44
+ reduce_name = args[:operation]
45
+ reduce_fn = REDUCERS[reduce_name]
46
+ reduce_fn.call(obj)
47
+ }
48
+ end
49
49
 
50
- # Handle self-referential fields by wrapping the type in a proc.
51
- # It will be lazy-eval'ed
52
- field :map, -> { ValuesType } do
53
- argument :operation, !MapperEnum
54
- argument :argument, !types.Int
55
- resolve -> (obj, args, ctx) {
56
- op_arg = args[:argument]
57
- op_name = args[:operation]
58
- op_func = MAPPERS[op_name]
59
- obj.map { |item| op_func.call(item, op_arg) }
60
- }
50
+ # Handle self-referential fields by wrapping the type in a proc.
51
+ # It will be lazy-eval'ed
52
+ field :map, -> { ValuesType } do
53
+ argument :operation, !MapperEnum
54
+ argument :argument, !types.Int
55
+ resolve -> (obj, args, ctx) {
56
+ op_arg = args[:argument]
57
+ op_name = args[:operation]
58
+ op_func = MAPPERS[op_name]
59
+ obj.map { |item| op_func.call(item, op_arg) }
60
+ }
61
+ end
61
62
  end
62
- end
63
63
 
64
- QueryType = GraphQL::ObjectType.define do
65
- name("Query")
64
+ QueryType = GraphQL::ObjectType.define do
65
+ name("Query")
66
66
 
67
- field :perform, ValuesType do
68
- argument :initial, !ListOfInts
69
- resolve -> (obj, args, ctx) { args[:initial] }
67
+ field :perform, ValuesType do
68
+ argument :initial, !ListOfInts
69
+ resolve -> (obj, args, ctx) { args[:initial] }
70
+ end
70
71
  end
71
- end
72
72
 
73
- CalculatorSchema = GraphQL::Schema.new(query: QueryType)
73
+ Schema = GraphQL::Schema.new(query: QueryType)
74
+ end
@@ -219,5 +219,16 @@ MutationType = GraphQL::ObjectType.define do
219
219
  end
220
220
  end
221
221
 
222
- DummySchema = GraphQL::Schema.new(query: QueryType, mutation: MutationType)
222
+ SubscriptionType = GraphQL::ObjectType.define do
223
+ name "Subscription"
224
+ field :test, types.String do
225
+ resolve -> (o, a, c) { "Test" }
226
+ end
227
+ end
228
+
229
+ DummySchema = GraphQL::Schema.new(
230
+ query: QueryType,
231
+ mutation: MutationType,
232
+ subscription: SubscriptionType,
233
+ )
223
234
  DummySchema.rescue_from(NoSuchDairyError) { |err| err.message }
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.10.2
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet