我正在尝试使用 relay 添加用户,下面是我的架构文件
schema.graphql
createUser(input: CreateUserInput!): UserPayload
input CreateUserInput {
clientMutationId: String
data: CreateUserData!
}
type CreateUserData {
firstName: String!
lastName: String!
password: String!
email: String
}
type UserPayload {
clientMutationId: String
node: User
}
type User {
id: ID!
firstName: String!
lastName: String!
email: String
password: String
}
下面是我的变异文件,
AddUserMutation.js
const mutation = graphql`
mutation AddUserMutation($input: CreateUserInput!) {
createUser(input: $input) {
data {
firstName
lastName
email
password
}
}
}
`;
function commit(environment, node) {
var firstName = node.fName;
var lastName = node.lName;
var email = node.signupEmail;
var password = node.pwd;
return commitMutation(environment, {
mutation,
variables: {
input: {
firstName,
lastName,
email,
password
},
},onCompleted: (response, errors) => {
console.log('Response received from server.',response)
},
onError: err => console.error(err),
},
);
}
export default { commit };
但它给我这个错误
GraphQLParser:
data
类型上的未知字段UserPayload
。来源:文档AddUserMutation
文件:js/mutations/AddUserMutation.js
.
所以我在这里做错了什么,我搜索了许多网站仍然能够找到解决方案。有人可以帮助/澄清我吗?