javascript - GraphQL Args error: argument type must be Input Type but got: function GraphQLObjectType(config) { -
on server start (node index.js
) getting following error graphql nodejs server:
error: query.payment(data:) argument type must input type got: function graphqlobjecttype(config) { _classcallcheck(this, graphqlobjecttype);
this error happened when changed original args string
args: { data: { type: graphql.graphqlstring } },
to object type:
args: { data: { type: graphql.graphqlobjecttype } },
i need object type need send several fields params.
graphql server:
var query = new graphql.graphqlobjecttype({ name: 'query', fields: { payment: { type: graphql.graphqlstring, args: { data: { type: graphql.graphqlobjecttype } }, resolve: function (_, args) { // there more data here, // want return string return 'success!'; } } } });
how can allow accept object?
frontend (if needed. error happening before send this):
var userquery = encodeuricomponent('{ payment ( data: { user : "test" } )}'); $.get('http://localhost:4000/graphql?query=' + userquery, function (res) { //stuff });
if want use object argument, should use graphqlinputobjecttype
instead of graphqlobjecttype
. , keep in mind graphql type based, you're not allowed use generic graphqlobjecttype
arg type , dynamically query args. have explicitly define possible fields in input object (and choose of them mandatory , not)
try use approach:
// 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 more data here, // want return string return 'success!'; } } } });
Comments
Post a Comment