graphql-js icon indicating copy to clipboard operation
graphql-js copied to clipboard

Add a case to detect for GraphQLList/GraphQLNonNull that's not being instantiated properly

Open OverclockedTim opened this issue 11 years ago • 7 comments

When attempting to use GraphQLList as an input type, an error is generated:

Error: field type must be Input Type but got: function GraphQLList(type) {...

This appears to be caused by isInputType in definitions.js not including GraphQLList as a valid type. https://github.com/graphql/graphql-js/blob/b14766205951f4fe6f712c9e24d47c0d117cc3bf/src/type/definition.js#L62-L69

My reading of the spec as well as the GraphQLInputType definition immediately above that includes GraphQLList as a valid type leads me to believe that this is an error.

OverclockedTim avatar Nov 21 '15 00:11 OverclockedTim

getNamedType will pull out the underlying wrapped type. So it should still work. Can you paste the code that is leading to this error?

jhgg avatar Nov 21 '15 16:11 jhgg

Sure, names changed to protect proprietary info, but it's basically:

var GraphQLCarAddWheelsMutation = mutationWithClientMutationId({ name: 'CarAddWheels', inputFields: { carId: { type: GraphQLInt}, wheelIds: {type: GraphQLList, kindOf: GraphQLInt} }, outputFields: { }, mutateAndGetPayload: (carId, wheelIds) => { addWheelstoCar(carId, wheelIds); return {}; } });

OverclockedTim avatar Nov 23 '15 18:11 OverclockedTim

{type: new GraphQLList(GraphQLString)}

Sent from my iPhone

On Nov 23, 2015, at 1:11 PM, OverclockedTim [email protected] wrote:

Sure, names changed to protect proprietary info, but it's basically:

var GraphQLCarAddWheelsMutation = mutationWithClientMutationId({ name: 'CarAddWheels', inputFields: { carId: { type: GraphQLInt}, wheelIds: {type: GraphQLList, kindOf: GraphQLInt} }, outputFields: { }, mutateAndGetPayload: (carId, wheelIds) => { addWheelstoCar(carId, wheelIds); return {}; } });

— Reply to this email directly or view it on GitHub.

jhgg avatar Nov 23 '15 18:11 jhgg

Well whatdya know, that works perfectly, thanks!

Would it be worth adding an example of List mutations to the Relay Mutation page? https://facebook.github.io/relay/docs/guides-mutations.html

Also, would it be worth clarifying the schema building message?

OverclockedTim avatar Nov 23 '15 18:11 OverclockedTim

Would it be worth adding an example of List mutations to the Relay Mutation page? https://facebook.github.io/relay/docs/guides-mutations.html

Not sure how that's related. Perhaps another issue on the Relay issue tracker?

Also, would it be worth clarifying the schema building message? I think that'd be a good idea. Right now it's just stringifying anything that's passed to type in the error message. Could add a case to detect for GraphQLList/GraphQLNonNull that's not being instantiated properly though.

jhgg avatar Nov 23 '15 19:11 jhgg

Sounds good, title change as per suggestion!

OverclockedTim avatar Nov 23 '15 19:11 OverclockedTim

Closing this aging issue.

However this case will be kept in mind as documentation improves.

leebyron avatar Apr 07 '16 07:04 leebyron