I am getting following error. when trying to run a mutation via graphiql. Please help me resolve this issue or point to a link where I can find react relay mutations example.
mutation {
createUser(input: {username: "Hamza Khan", clientMutationId: ""}) {
user {
id
username
}
}
}
{
"data": {
"createUser": null
},
"errors": [
{
"message": "Cannot set property 'clientMutationId' of undefined",
"locations": [
{
"line": 17,
"column": 2
}
]
}
]
}
Here is the mutation definition
import {
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLList,
GraphQLObjectType,
GraphQLID,
GraphQLNonNull
} from 'graphql';
import {
connectionArgs,
connectionDefinitions,
connectionFromArray,
fromGlobalId,
globalIdField,
mutationWithClientMutationId,
nodeDefinitions,
} from 'graphql-relay';
import {User} from './usermodel';
import {UserType} from './usertype';
export const UserMutations = {};
UserMutations.createUser = mutationWithClientMutationId({
name: 'CreateUser',
inputFields: {
username: {type: new GraphQLNonNull(GraphQLString)}
},
outputFields: {
user: {
type: UserType,
resolve: (payload) => {
return User.getUserById(payload.userId);
}
}
},
mutateAndGetPayload: (args) => {
let newUser = new User({ username: args.username });
newUser.save().then((user) => {
return {userId: user.id};
}).error((err) => {return null;});
}
});
You have to return something from mutateAndGetPayload
– in your case, a promise.
mutateAndGetPayload: ({username}) => {
const newUser = new User({username});
return newUser.save().then(user => ({userId: user.id}));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With