graphql-relay 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/graphql/relay.rb +2 -1
- data/lib/graphql/relay/base_connection.rb +1 -1
- data/lib/graphql/relay/connection_field.rb +45 -0
- data/lib/graphql/relay/monkey_patches/{object_type.rb → base_type.rb} +5 -1
- data/lib/graphql/relay/monkey_patches/definition_config.rb +2 -24
- data/lib/graphql/relay/version.rb +1 -1
- data/spec/graphql/relay/array_connection_spec.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 921751eabb371fef7f064ff0bbefccf2cd77569b
|
4
|
+
data.tar.gz: 19273e08230559f7d181ade786556b831925bc2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0871b958af3b912827669e9dbf1d4e2952edb035bcc676104223797c7116480bc1ad63205d72ef51b90429b5ee6e7bc1f1efb08546a4ea6f09c7e276c7d0fa11
|
7
|
+
data.tar.gz: 2f0b46a36b0843e662f164d7de45b36c51a9a938f0d81e45fa5d786b9c327b92e1ebad019339a8aa24b19e8c6078b5f7096382b674c33f2e289726e628594c53
|
data/README.md
CHANGED
@@ -74,6 +74,6 @@ Examples:
|
|
74
74
|
|
75
75
|
## More Resources
|
76
76
|
|
77
|
-
- [GraphQL Slack](graphql-slack.herokuapp.com), come join us in the `#ruby` channel!
|
77
|
+
- [GraphQL Slack](http://graphql-slack.herokuapp.com), come join us in the `#ruby` channel!
|
78
78
|
- [`graphql`](https://github.com/rmosolgo/graphql-ruby) Ruby gem
|
79
79
|
- [`graphql-relay-js`](https://github.com/graphql/graphql-relay-js) JavaScript helpers for GraphQL and Relay
|
data/lib/graphql/relay.rb
CHANGED
@@ -2,7 +2,7 @@ require 'base64'
|
|
2
2
|
require 'graphql'
|
3
3
|
# MONKEY PATCHES 😬
|
4
4
|
require 'graphql/relay/monkey_patches/definition_config'
|
5
|
-
require 'graphql/relay/monkey_patches/
|
5
|
+
require 'graphql/relay/monkey_patches/base_type'
|
6
6
|
|
7
7
|
require 'graphql/relay/global_node_identification'
|
8
8
|
require 'graphql/relay/page_info'
|
@@ -12,3 +12,4 @@ require 'graphql/relay/array_connection'
|
|
12
12
|
require 'graphql/relay/relation_connection'
|
13
13
|
require 'graphql/relay/global_id_field'
|
14
14
|
require 'graphql/relay/mutation'
|
15
|
+
require 'graphql/relay/connection_field'
|
@@ -19,7 +19,7 @@ module GraphQL
|
|
19
19
|
|
20
20
|
# Create a connection which exposes edges of this type
|
21
21
|
def self.create_type(wrapped_type, &block)
|
22
|
-
edge_type =
|
22
|
+
edge_type = wrapped_type.edge_type
|
23
23
|
|
24
24
|
connection_type = ObjectType.define do
|
25
25
|
name("#{wrapped_type.name}Connection")
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module GraphQL
|
2
|
+
module Relay
|
3
|
+
class ConnectionField
|
4
|
+
ARGUMENT_DEFINITIONS = [
|
5
|
+
[:first, GraphQL::INT_TYPE],
|
6
|
+
[:after, GraphQL::STRING_TYPE],
|
7
|
+
[:last, GraphQL::INT_TYPE],
|
8
|
+
[:before, GraphQL::STRING_TYPE],
|
9
|
+
[:order, GraphQL::STRING_TYPE],
|
10
|
+
]
|
11
|
+
|
12
|
+
DEFAULT_ARGUMENTS = ARGUMENT_DEFINITIONS.reduce({}) do |memo, arg_defn|
|
13
|
+
argument = GraphQL::Argument.new
|
14
|
+
argument.name = arg_defn[0]
|
15
|
+
argument.type = arg_defn[1]
|
16
|
+
memo[argument.name.to_s] = argument
|
17
|
+
memo
|
18
|
+
end
|
19
|
+
|
20
|
+
# Turn A GraphQL::Field into a connection by:
|
21
|
+
# - Merging in the default argument
|
22
|
+
# - Transforming its resolve function to return a connection object
|
23
|
+
def self.create(underlying_field)
|
24
|
+
underlying_field.arguments = underlying_field.arguments.merge(DEFAULT_ARGUMENTS)
|
25
|
+
# TODO: make a public API on GraphQL::Field to expose this proc
|
26
|
+
original_resolve = underlying_field.instance_variable_get(:@resolve_proc)
|
27
|
+
underlying_field.resolve = get_connection_resolve(original_resolve)
|
28
|
+
underlying_field
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.get_connection_resolve(underlying_resolve)
|
34
|
+
-> (obj, args, ctx) {
|
35
|
+
items = underlying_resolve.call(obj, args, ctx)
|
36
|
+
if items == GraphQL::Query::DEFAULT_RESOLVE
|
37
|
+
items = obj.public_send(name)
|
38
|
+
end
|
39
|
+
connection_class = GraphQL::Relay::BaseConnection.connection_for_items(items)
|
40
|
+
connection_class.new(items, args)
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -4,30 +4,8 @@ class GraphQL::DefinitionHelpers::DefinedByConfig::DefinitionConfig
|
|
4
4
|
# - wraps the resolve proc to make a connection
|
5
5
|
#
|
6
6
|
def connection(name, type = nil, desc = nil, property: nil, &block)
|
7
|
-
|
8
|
-
|
9
|
-
argument :first, types.Int
|
10
|
-
argument :after, types.String
|
11
|
-
argument :last, types.Int
|
12
|
-
argument :before, types.String
|
13
|
-
argument :order, types.String
|
14
|
-
self.instance_eval(&block) if block_given?
|
15
|
-
}
|
16
|
-
connection_field = field(name, type, desc, property: property, &definition_block)
|
17
|
-
# Wrap the defined resolve proc
|
18
|
-
# TODO: make a public API on GraphQL::Field to expose this proc
|
19
|
-
original_resolve = connection_field.instance_variable_get(:@resolve_proc)
|
20
|
-
connection_resolve = -> (obj, args, ctx) {
|
21
|
-
items = original_resolve.call(obj, args, ctx)
|
22
|
-
if items == GraphQL::Query::DEFAULT_RESOLVE
|
23
|
-
method_name = property || name
|
24
|
-
p "Obj: #{obj} ##{method_name}"
|
25
|
-
items = obj.public_send(method_name)
|
26
|
-
end
|
27
|
-
connection_class = GraphQL::Relay::BaseConnection.connection_for_items(items)
|
28
|
-
connection_class.new(items, args)
|
29
|
-
}
|
30
|
-
connection_field.resolve = connection_resolve
|
7
|
+
underlying_field = field(name, type, desc, property: property, &block)
|
8
|
+
connection_field = GraphQL::Relay::ConnectionField.create(underlying_field)
|
31
9
|
fields[name.to_s] = connection_field
|
32
10
|
end
|
33
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-relay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
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-09-
|
11
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -190,11 +190,12 @@ files:
|
|
190
190
|
- lib/graphql/relay.rb
|
191
191
|
- lib/graphql/relay/array_connection.rb
|
192
192
|
- lib/graphql/relay/base_connection.rb
|
193
|
+
- lib/graphql/relay/connection_field.rb
|
193
194
|
- lib/graphql/relay/edge.rb
|
194
195
|
- lib/graphql/relay/global_id_field.rb
|
195
196
|
- lib/graphql/relay/global_node_identification.rb
|
197
|
+
- lib/graphql/relay/monkey_patches/base_type.rb
|
196
198
|
- lib/graphql/relay/monkey_patches/definition_config.rb
|
197
|
-
- lib/graphql/relay/monkey_patches/object_type.rb
|
198
199
|
- lib/graphql/relay/mutation.rb
|
199
200
|
- lib/graphql/relay/page_info.rb
|
200
201
|
- lib/graphql/relay/relation_connection.rb
|