简体   繁体   中英

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"

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM