@@ -22,13 +22,13 @@ You must provide a function for generating UUIDs and fetching objects with them.
22
22
23
23
``` ruby
24
24
MySchema = GraphQL ::Schema .define do
25
- id_from_object -> (object, type_definition, query_ctx) {
25
+ id_from_object -> (object, type_definition, query_ctx) {
26
26
# Call your application's UUID method here
27
27
# It should return a string
28
28
MyApp ::GlobalId .encrypt(object.class .name, object.id)
29
29
}
30
30
31
- object_from_id -> (id, query_ctx) {
31
+ object_from_id -> (id, query_ctx) {
32
32
class_name, item_id = MyApp ::GlobalId .decrypt(id)
33
33
# "Post" => Post.find(id)
34
34
Object .const_get(class_name).find(item_id)
@@ -41,11 +41,11 @@ An unencrypted ID generator is provided in the gem. It uses `Base64` to encode v
41
41
``` ruby
42
42
MySchema = GraphQL ::Schema .define do
43
43
# Create UUIDs by joining the type name & ID, then base64-encoding it
44
- id_from_object -> (object, type_definition, query_ctx) {
44
+ id_from_object -> (object, type_definition, query_ctx) {
45
45
GraphQL ::Schema ::UniqueWithinType .encode(type_definition.name, object.id)
46
46
}
47
47
48
- object_from_id -> (id, query_ctx) {
48
+ object_from_id -> (id, query_ctx) {
49
49
type_name, item_id = GraphQL ::Schema ::UniqueWithinType .decode(id)
50
50
# Now, based on `type_name` and `id`
51
51
# find an object in your application
@@ -129,7 +129,7 @@ connection :featured_comments, CommentType.connection_type do
129
129
argument :since , types.String
130
130
131
131
# Return an Array or ActiveRecord::Relation
132
- resolve -> (post, args, ctx) {
132
+ resolve -> (post, args, ctx) {
133
133
comments = post.comments.featured
134
134
135
135
if args[:since ]
@@ -158,7 +158,7 @@ PostConnectionWithTotalCountType = PostType.define_connection do
158
158
field :totalCount do
159
159
type types.Int
160
160
# `obj` is the Connection, `obj.object` is the collection of Posts
161
- resolve -> (obj, args, ctx) { obj.object.count }
161
+ resolve -> (obj, args, ctx) { obj.object.count }
162
162
end
163
163
end
164
164
@@ -182,7 +182,7 @@ If you need custom fields on `edge`s, you can define an edge type and pass it to
182
182
MembershipSinceEdgeType = TeamType .define_edge do
183
183
name " MembershipSinceEdge"
184
184
field :memberSince , types.Int , " The date that this person joined this team" do
185
- resolve -> (obj, args, ctx) {
185
+ resolve -> (obj, args, ctx) {
186
186
obj # => GraphQL::Relay::Edge instance
187
187
person = obj.parent
188
188
team = obj.node
@@ -398,7 +398,7 @@ To define a mutation, use `GraphQL::Relay::Mutation.define`. Inside the block, y
398
398
- ` name ` , which will name the mutation field & derived types
399
399
- ` input_field ` s, which will be applied to the derived ` InputObjectType `
400
400
- ` return_field ` s, which will be applied to the derived ` ObjectType `
401
- - ` resolve(-> (obj, inputs, ctx) { ... }) ` , the mutation which will actually happen
401
+ - ` resolve(->(obj, inputs, ctx) { ... }) ` , the mutation which will actually happen
402
402
403
403
404
404
For example:
@@ -420,7 +420,7 @@ AddCommentMutation = GraphQL::Relay::Mutation.define do
420
420
421
421
# The resolve proc is where you alter the system state.
422
422
# `object` is the `root_value:` passed to `Schema.execute`.
423
- resolve -> (object, inputs, ctx) {
423
+ resolve -> (object, inputs, ctx) {
424
424
post = Post .find(inputs[:postId ])
425
425
comment = post.comments.create!(author_id: inputs[:authorId ], content: inputs[:content ])
426
426
@@ -448,7 +448,7 @@ Instead of specifying `return_field`s, you can specify a `return_type` for a mut
448
448
CreateUser = GraphQL ::Relay ::Mutation .define do
449
449
return_type UserMutationResultType
450
450
# ...
451
- resolve -> (obj, input, ctx) {
451
+ resolve -> (obj, input, ctx) {
452
452
user = User .create(input)
453
453
# this object will be treated as `UserMutationResultType`
454
454
UserMutationResult .new (user, client_mutation_id: input[:clientMutationId ])
0 commit comments