graphql-relay 0.3.2 → 0.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7709418477addd6a542573bfb2ca6861ed0093be
|
4
|
+
data.tar.gz: 5fe37c3e4d40d45352ad55b48f3d7416b0ffd546
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e0a3e2ac87606e638d121e95c988978c00d9e980d2ec18c1727c4b31d130f79f4da107f5657fe02869745de9ae4b1ea66857bf01170072889b184b9202ed99e
|
7
|
+
data.tar.gz: f9786c72c9adc564dfa69fdc4fc6c30eec02a18a5120e59b241503ac3f4cd87ebf2ad4a80030d7e3c875e2fbdd547d9705f8bc9a16a8574d5c8d210554e5ef7c
|
@@ -1,42 +1,38 @@
|
|
1
|
-
module GraphQL
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
fields[name.to_s] = connection_field
|
30
|
-
end
|
1
|
+
module GraphQL::DefinitionHelpers::DefinedByConfig
|
2
|
+
class DefinitionConfig
|
3
|
+
# Wraps a field definition with a ConnectionField
|
4
|
+
# - applies default fields
|
5
|
+
# - wraps the resolve proc to make a connection
|
6
|
+
#
|
7
|
+
def connection(name, type = nil, desc = nil, property: nil, &block)
|
8
|
+
# Wrap the given block to define the default args
|
9
|
+
definition_block = -> (config) {
|
10
|
+
argument :first, types.Int
|
11
|
+
argument :after, types.String
|
12
|
+
argument :last, types.Int
|
13
|
+
argument :before, types.String
|
14
|
+
argument :order, types.String
|
15
|
+
self.instance_eval(&block)
|
16
|
+
}
|
17
|
+
connection_field = field(name, type, desc, property: property, &definition_block)
|
18
|
+
# Wrap the defined resolve proc
|
19
|
+
# TODO: make a public API on GraphQL::Field to expose this proc
|
20
|
+
original_resolve = connection_field.instance_variable_get(:@resolve_proc)
|
21
|
+
connection_resolve = -> (obj, args, ctx) {
|
22
|
+
items = original_resolve.call(obj, args, ctx)
|
23
|
+
connection_class = GraphQL::Relay::BaseConnection.connection_for_items(items)
|
24
|
+
connection_class.new(items, args)
|
25
|
+
}
|
26
|
+
connection_field.resolve = connection_resolve
|
27
|
+
fields[name.to_s] = connection_field
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
alias :return_field :field
|
31
|
+
alias :return_fields :fields
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
33
|
+
def global_id_field(field_name)
|
34
|
+
name || raise("You must define the type's name before creating a GlobalIdField")
|
35
|
+
field(name, field: GraphQL::Relay::GlobalIdField.new(name))
|
40
36
|
end
|
41
37
|
end
|
42
38
|
end
|