Unable to set clientMutationId property from undefined

I get the following error. when trying to run a mutation via graphiql. Please help me solve this problem or provide a link where I can find an example of a relay mutation.

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 definition of mutation

 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;}); } }); 
+5
source share
1 answer

You need 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})); } 
+11
source

Source: https://habr.com/ru/post/1236455/


All Articles