@rmosolgo in the graphql spec, its generally encouraged to have nested keys in your input objects.
e.g.
input CreatePostInput {
post: {
title: String;
description: String;
}
}
type CreatePostPayload {
post: {
id: Id;
title: String;
description: String;
createdAt: DateTime;
}
}
type Mutation {
createPost(input: CreatePostInput!): CreatePostPayload
}
how do I do the same within the graphql gem?
The easiest way is to use RelayClassicMutation, eg:
class Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation
Then, any argument ...s defined on mutations will be added to the *Input type, which is generated by the library.
If you want to do it by hand, you can create an input object, then use that input object as an argument type, for example:
class Types::CreatePostInput < Types::BaseInputObject
argument :title, String, required: true
argument :description, String, required: true
end
# ...
class Mutations::CreatePost < Mutations::BaseMutation
argument :input, Types::CreatePostInput, required: true
end
Then, it will be like the schema you posted in the example.
Most helpful comment
The easiest way is to use
RelayClassicMutation, eg:Then, any
argument ...s defined on mutations will be added to the*Inputtype, which is generated by the library.If you want to do it by hand, you can create an input object, then use that input object as an argument type, for example:
Then, it will be like the schema you posted in the example.