graphqljs在输出字段的突变中更新上下文

我有一个想要更改上下文的突变。 简化的突变如下所示:

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,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。如何为该突变及其内部的每个字段更新上下文,以使这种情况得以解决?

michaelkid 回答:graphqljs在输出字段的突变中更新上下文

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2953506.html

大家都在问