【问题标题】:Can we change/alter nested mutation using Laravel events?我们可以使用 Laravel 事件更改/更改嵌套突变吗?
【发布时间】:2020-11-07 01:52:01
【问题描述】:

我想使用 Laravel 创建事件来改变突变。我想从来自前端的键中获取任务 ID。然后我想添加这个 ID 来代替键,这样我的任务将使用灯塔结构自动创建。这是样本突变

mutation
{
  createUser(input: {
    firstname: "last"
    email: "abc@gmaiol.com"
    task:
    {
      create: { 
         key: 'reminder'
      }
    }
  })
  {
    id
  }
}

【问题讨论】:

    标签: graphql lighthouse laravel-lighthouse graphql-mutation


    【解决方案1】:

    我的建议是为您的具体情况创建一个解析器:

    mutation
    {
      createUser(input: {firstname: "last", email: "abc@gmaiol.com", key: "reminder"})
      {
        id
      }
    }
    

    记住一定要用双引号“”,千万不要用单引号''

    在您的 schema.graphql

    input newUser {
        firstname: String!
        email: String!
        key: String!
    }
    
    type newUserResponse {
        ID: ID!
    }
    
    createUser(data: newUser): newUserResponse @field(resolver: "App\\GraphQL\\Mutations\\createUser")
    
    

    这是解析器的示例:Resolver example

    同时查看文档:https://lighthouse-php.com/4.9/api-reference/resolvers.html

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 1970-01-01
      • 2011-06-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-05
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      相关资源
      最近更新 更多