Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

graphQL - type must be Output Type

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"
like image 785
nha Avatar asked Oct 19 '15 08:10

nha


People also ask

What is a type in GraphQL?

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.

What is scalar type in GraphQL?

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.

What other types can be used in a GraphQL schema?

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.

How do I set the default value in a GraphQL schema?

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.


1 Answers

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 ?).

like image 189
nha Avatar answered Sep 28 '22 07:09

nha