Thanks in advance for the awesome library.
I upgraded to graphql 1.8.4 and GraphQL::Relay::RangeAdd.new is always returning null.
I inspected the range_add object and it seems to be fine
#<GraphQL::Relay::RangeAdd:0x00007f0d70319bb8 @parent=nil, @connection=#<GraphQL::Relay::Connection @parent=nil @arguments={}>, @edge=#<GraphQL::Relay::Edge (nil => #<Post id: 11, name: "test", created_at: "2018-06-23 14:29:56", updated_at: "2018-06-23 14:29:56">)>>
Here's the relevant code
class Mutations::CreatePost < GraphQL::Schema::RelayClassicMutation
null true
field :postEdge, Types::PostType.edge_type, null: false
argument :name, String, required: true
def resolve(**inputs)
range_add = GraphQL::Relay::RangeAdd.new(
collection: Post.all,
item: Post.create!(name: inputs[:name]),
context: context
)
{
postEdge: range_add.edge
}
end
end
class Types::MutationType < Types::BaseObject
field :createPost, mutation: Mutations::CreatePost
end
md5-fe25a0e80b5e1b09029e61021f99c8d0
$ curl 'http://localhost:3000/graphql' \
-d 'query=mutation CreatePost($input: CreatePostInput!) { createPost(input: $input) { postEdge { node { name } } clientMutationId } }' \
-d 'variables={"input": {"name": "test"}}'
{"data":{"createPost":null},"errors":[{"message":"Cannot return null for non-nullable field CreatePostPayload.postEdge"}]}
Any ideas on what could be happening?
Figured it out, I needed to return post_edge instead of postEdge in my resolve function.
{
post_edge: range_add.edge
}
A bit confusing, since I defined the field as postEdge.
Side note: postEdge used to work before I moved to the Class-based API.
Relevant docs
Field and argument names should be underscored as a convention. They will be converted to camelCase in the underlying GraphQL type and be camelCase in the schema itself.
http://graphql-ruby.org/type_definitions/objects.html#object-classes
Glad you found the solution, thanks for following up!
Most helpful comment
Figured it out, I needed to return
post_edgeinstead ofpostEdgein my resolve function.A bit confusing, since I defined the field as
postEdge.Side note:
postEdgeused to work before I moved to the Class-based API.