我有以下突變在服務器端(的NodeJS)(RequiredDataType進口):使用GQLObject作爲arg進行突變?
mutationA: {
type: MutationResponseType,
args: {
id: {
type: new GraphQLNonNull(GraphQLString)
},
name: {
type: new GraphQLNonNull(GraphQLString)
},
requiredData: {
type: new GraphQLNonNull(new GraphQLList(RequiredDataType))
}
},
async resolve(parentValue, {
id,
name,
requiredData
}, req) {
// Some Magic Code
}
},
的RequiredDataType編碼如下(所有GraphQL東西都是進口的:)):
const RequiredDataType = new GraphQLObjectType({
name: 'RequiredDataType',
fields: {
name: {
type: GraphQLString
},
value: {
type: GraphQLString
},
required: {
type: GraphQLBoolean
}
}
});
module.exports = RequiredDataType;
當我使用此代碼我得到以下錯誤:「模塊初始化錯誤:錯誤」
如果我將突變中的RequiredDataType更改爲GraphQLString它沒有任何錯誤,但我不能使用我需要的對象:)
最後我會發送和處理數據結構如下:
{
"name": "Hallo"
"id": "a54de3d0-a0a6-11e7-bf70-7b64ae72d2b6",
"requiredData": [
{
"name": "givenName",
"value": null,
"required": true
},
{
"name": "familyName",
"value": null,
"required": false
}
]
}
在客戶端(reactJS與阿波羅的客戶端)我用下面的GQL標籤代碼:
export default gql`
mutation MutationA($id: String!, $name: String!, $requiredData: [RequiredDataType]!){
mutationA(id: $id, name: $name, requiredData: $requiredData) {
id,
somethingElse
}
}
`;
但首先它在服務器上的突變聲明上崩潰。那麼是不是可以使用GQLObject作爲變量的參數,或者在代碼中出現錯誤?
謝謝你的幫助!
最佳,
的Fabian
嗨,感謝你的工作! – Developer94
@ Developer94如果它準確回答您的問題,請將答案標記爲已接受:) –