Errore di inseguimento. quando si tenta di eseguire una mutazione tramite graphiql. Per favore aiutami a risolvere questo problema o indicare un collegamento dove posso trovare esempio di mutazioni a relè di reazione.Impossibile impostare la proprietà "clientMutationId" di indefinito
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
}
]
}
]
}
Ecco la definizione di mutazione
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;});
}
});
L'errore è quasi certamente perché non si sta caricando un utente correttamente. Probabilmente perché stai solo inviando un nome utente come input. –
Posso console log nuovo utente in mutateAndGetPayload ma stranamente risolvere la funzione in outputFields non è in esecuzione. – user1762608
potrebbe non essere una query per l'utente. Se non si richiede un campo, la funzione di risoluzione del campo di output non viene chiamata. –