0
我目前正在嘗試爲rootQuery繼承模式,以獲得更多的模塊化。設置目前看起來如下:GraphQL:錯誤:模式查詢必須是對象類型,但得到:[對象對象]
invoiceSchema.js
import {
GraphQLObjectType,
GraphQLInt,
} from 'graphql';
export default new GraphQLObjectType({
name: 'Invoice',
description: 'A monthly billing invoice for an organization',
fields:() => ({
amountDue: {
type: GraphQLInt,
description: 'The amount the card will be charged (total + startingBalance with a min value of 0)'
},
})
});
rootQuery.js
import {
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLList,
GraphQLID
} from 'graphql';
import Invoice from './invoiceSchema';
export default {
Invoice: {
type: Invoice,
resolve(parentValue, args){
return 'Hello world';
}
}
};
schema.js
import query from './rootQuery';
import {GraphQLSchema} from 'graphql';
export default new GraphQLSchema({query});
當試圖做到以下幾點錯誤,並希望有一些他LP和洞察力,因爲我在invoiceSchema.js中導出的顯然是ObjectType而不是對象Object。
C:\project\node_modules\graphql\jsutils\invariant.js:19
throw new Error(message);
^
Error: Schema query must be Object Type but got: [object Object].
at invariant (C:\project\node_modules\graphql\jsutils\invariant.js:19:11)
at new GraphQLSchema (C:\project\node_modules\graphql\type\schema.js:72:88)
at Object.<anonymous> (C:/project/api/schema/schema.js:6:16)
at Module._compile (module.js:573:30)
at loader (C:\project\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\project\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
[nodemon] app crashed - waiting for file changes before starting...
其實從here上心,我想知道爲什麼它不工作...
謝謝!現在使用它:'導出默認的新GraphQLObjectType({0} {0}名稱:'RootQuery', 字段:()=>({}; });'然後導致錯誤'錯誤:RootQuery .name字段配置必須是一個對象 - 這是奇怪的,因爲它引用了查詢的名稱字符串。也許你也知道如何解決這個問題。 – schlumpfpirat
這裏的擴展運算符是不合適的,你基本上把字段設置爲你的Invoice類型,這是行不通的,'fields'需要是一個對象或者返回該對象的函數,無論哪種情況,該對象都會將每個字段名映射到另一個對象,該對象包含該字段的詳細信息類型','args','解析'等) –
哪個傳播運算符? – schlumpfpirat