graphQL – types必须是输出types

我正在尝试使用express和mongoose graffiti来设置graphQL路由。

但是,我得到以下错误:

 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 

type : Schema.Types.ObjectId模式中,types是: type : Schema.Types.ObjectId 。 是否应该改变其他的东西?

我应该注意的版本是:

 "@risingstack/graffiti": "^1.0.2" "@risingstack/graffiti-mongoose": "^3.1.1" "mongoose": "~3.6.20" 

原来我没有导入我引用的另一个模型。 我有以下代码:

 myField : { type : Schema.Types.ObjectId, ref : 'myRef' } 

而且我并没有将'myRef'导入到使用graphQL的mongoose模型列表中。 确实很简单; 尽pipe错误信息可能会有所改善(这是什么输出types?什么是未定义?)。

错误

 Error: ... field type must be Output Type but got: undefined. 

意思是说,你有一个GraphQLFieldConfig的问题。

GraphQLFieldConfig需要types字段。 如果这个字段丢失或者type-ref不好(undefined等),这个错误就会出现。

 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

Interesting Posts