修改操作

拦截 GraphQL 突变。

你可以通过定义一个 graphql.mutation() 处理程序并通过操作名称匹配来拦截 GraphQL 突变:

¥You can intercept a GraphQL mutation by defining a graphql.mutation() handler for it and matching it by the operation name:

graphql.mutation('CreateUser', ({ variables }) => {
  return HttpResponse.json({
    data: {
      createUser: {
        id: 'abc-123',
        name: variables.name,
      },
    },
  })
})

上面的请求处理程序将匹配你应用中的以下 GraphQL 变更:

¥The request handler above will match the following GraphQL mutation made in your application:

mutation CreateUser($name: String!) {
  createUser(name: $name) {
    id
    name
  }
}