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"
Character is a GraphQL Object Type, meaning it's a type with some fields. Most of the types in your schema will be object types. name and appearsIn are fields on the Character type. That means that name and appearsIn are the only fields that can appear in any part of a GraphQL query that operates on the Character type.
The GraphQL specification includes default scalar types Int , Float , String , Boolean , and ID . Although these scalars cover the majority of use cases, some applications need to support other atomic data types (such as Date ) or add validation to an existing type. To enable this, you can define custom scalar types.
The GraphQL schema language supports the scalar types of String , Int , Float , Boolean , and ID , so you can use these directly in the schema you pass to buildSchema . By default, every type is nullable - it's legitimate to return null as any of the scalar types.
In GraphQL you can assign Default values to the variables. It's done by by adding the default value after the type declaration in your query. If Default values are provided for all variables, you can call the query without passing any variables.
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 ?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With