On server start (node index.js
) I am getting the following error with my GraphQL NodeJS server:
Error: Query.payment(data:) argument type mus
If you want use Object as an argument, you should use GraphQLInputObjectType
instead of GraphQLObjectType
. And keep in mind that GraphQL is strongly type based, so you're not allowed to use a generic GraphQLObjectType
as arg type and then dynamically query args. You have to explicitly define all possible fields in this input object (and choose which of them would be mandatory and which not)
Try use this approach:
// your arg input object
var inputType = new GraphQLInputObjectType({
name: 'paymentInput',
fields: {
user: {
type: new GraphQLNonNull(GraphQLString)
},
order: {
type: GraphQLString
},
...another fields
}
});
var Query = new graphQL.GraphQLObjectType({
name: 'Query',
fields: {
payment: {
type: graphQL.GraphQLString,
args: {
data: { type: new GraphQLNonNull(inputType) }
},
resolve: function (_, args) {
// There will be more data here,
// but ultimately I want to return a string
return 'success!';
}
}
}
});