我有一个想要更改上下文的突变。 简化的突变如下所示:
const UserType = new GraphQLObjectType({
name: 'User',
fields: () => ({
someData: {
type: GraphQLList(GraphQLString),
resolve: (user, args, context) => getUserData(context.location) // here context is { location: oldLocation }
},
})
})
const someMutation = mutationWithClientMutationId({
name: 'someMutation',
inputFields: {
location: { type: GraphQLString },
},
outputFields: {
user: {
type: UserType,
resolve: (source, args, context) => getUser(context.location),
},
},
mutateAndGetPayload: async (data, context) => {
// I have tried this but it's not working.
console.log('TCL: context, before', context) // here context = { location: oldLocation }
context = { location: data.location }
console.log('TCL: context, after', context) // here context = { location: newLocation }
return { }
},
})
现在,在UserType中,我有一个使用上下文的字段,并且希望它包含newLocation,但是在登录时,我看到的是oldLocation。如何为该突变及其内部的每个字段更新上下文,以使这种情况得以解决?