graphql-relay 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4efd1cd2ad74d644082dec208d0f59fee5c43973
4
- data.tar.gz: 2c31b7d7c3f3661e54ec02103e622328f5c25a51
3
+ metadata.gz: 921751eabb371fef7f064ff0bbefccf2cd77569b
4
+ data.tar.gz: 19273e08230559f7d181ade786556b831925bc2f
5
5
  SHA512:
6
- metadata.gz: 7475507b89ca0adf9a061be156f06ce2a8ff96dc6b09a78f23cd1c796c862e8490feed2a0afa1a60802ded7d3384b7aedafd2a2f48a13990baafe18edc5b350d
7
- data.tar.gz: 9c38cc95c267429b0047b1ee140307cef4e08bde2abe832eff76cc29e3e867b7d6b5bffad51459671bebfcec0093dbc1e6cef3f99eaeeb27e0f1d194aeb37bd1
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/object_type'
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 = Edge.create_type(wrapped_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
@@ -1,5 +1,9 @@
1
- class GraphQL::ObjectType
1
+ class GraphQL::BaseType
2
2
  def connection_type
3
3
  @connection_type ||= GraphQL::Relay::BaseConnection.create_type(self)
4
4
  end
5
+
6
+ def edge_type
7
+ @edge_type ||= GraphQL::Relay::Edge.create_type(self)
8
+ end
5
9
  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
- # Wrap the given block to define the default args
8
- definition_block = -> (config) {
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
 
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Relay
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
@@ -27,6 +27,7 @@ describe GraphQL::Relay::ArrayConnection do
27
27
  }
28
28
  }
29
29
  |}
30
+
30
31
  it 'limits the result' do
31
32
  result = query(query_string, "first" => 2)
32
33
  number_of_ships = get_names(result).length
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.0
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-06 00:00:00.000000000 Z
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