2015-10-19 16 views
6

Tôi đang cố gắng thiết lập tuyến đường đồ thị bằng cách sử dụng graffiti với tốc độ và mongoose.graphQL - loại phải là Loại đầu ra

Tuy nhiên tôi nhận được lỗi sau:

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 

Trong giản đồ cầy mangut, loại là: type : Schema.Types.ObjectId. Nó có nên được thay đổi cho cái gì khác không?

Tôi nên lưu ý rằng các phiên bản là:

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

mã mà ném lỗi là gì? –

Trả lời

2

Hóa ra tôi đã không nhập khẩu một mô hình tôi tham chiếu. Tôi đã có đoạn mã sau:

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

Và tôi đã không nhập khẩu 'myRef' vào danh sách các mô hình mongoose mà sử dụng graphQL. Rất đơn giản thực sự; mặc dù thông báo lỗi có thể được cải thiện (loại đầu ra này là gì? Cái gì không xác định?).

0

Các lỗi

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

trung bình, bạn gặp rắc rối với GraphQLFieldConfig.

GraphQLFieldConfig cần loại trường. Nếu trường này bị thiếu hoặc loại-ref là xấu (undefined etc.) thì lỗi này xuất hiện.

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

Các vấn đề liên quan