Reputation: 18005
I am trying to set-up a graphQL route using graffiti
with express and mongoose.
However I get the following error :
Error: myColl.myField field type must be Output Type but got: undefined.
at invariant (/Users/nha/.../node_modules/graphql/jsutils/invariant.js:20:11)
at /Users/nha/.../node_modules/graphql/type/definition.js:299:39
In the mongoose schema, the type is : type : Schema.Types.ObjectId
. Should it be changed for something else ?
I should note that the versions are :
"@risingstack/graffiti": "^1.0.2"
"@risingstack/graffiti-mongoose": "^3.1.1"
"mongoose": "~3.6.20"
Upvotes: 7
Views: 5999
Reputation: 2603
The error
Error: ... field type must be Output Type but got: undefined.
mean, you have a problem with GraphQLFieldConfig.
GraphQLFieldConfig need the type-field. If this field is missing or type-ref is bad (undefined etc.) this error appear.
class GraphQLObjectType {
constructor(config: GraphQLObjectTypeConfig)
}
type GraphQLObjectTypeConfig = {
name: string;
interfaces?: GraphQLInterfacesThunk | Array<GraphQLInterfaceType>;
fields: GraphQLFieldConfigMapThunk | GraphQLFieldConfigMap;
isTypeOf?: (value: any, info?: GraphQLResolveInfo) => boolean;
description?: ?string
}
type GraphQLInterfacesThunk = () => Array<GraphQLInterfaceType>;
type GraphQLFieldConfigMapThunk = () => GraphQLFieldConfigMap;
...
type GraphQLFieldConfig = {
type: GraphQLOutputType;
args?: GraphQLFieldConfigArgumentMap;
resolve?: GraphQLFieldResolveFn;
deprecationReason?: string;
description?: ?string;
}
http://graphql.org/graphql-js/type/#graphqlobjecttyp
Upvotes: 1
Reputation: 18005
Turns out I did not import another model I referenced. I had the following code :
myField : {
type : Schema.Types.ObjectId,
ref : 'myRef'
}
And I was not importing 'myRef'
into the list of the mongoose models for which to use graphQL. Quite simple indeed; although the error message could probably be improved (what is this Output type ? What was undefined ?).
Upvotes: 3