0

我正在寻找 Laravel Lighthouse 的文档,我看到了两种类型的突变。

mutation {
  createPost(input: { # <-- the "input:" I'm talking about
    title: "My new Post"
    author: {
      connect: 123
    }
  }){
    id
    author {
      name
    }
  }
}

还有另一个没有(在这里找到)的突变input:

mutation CreateTaskWithNotes {
  createTask( # <-- no "input:" here
    id: 45
    name: "Do something"
    notes: [
      {
        content: "Foo bar",
        link: "http://foo.bar"
      },
      {
        content: "Awesome note"
      }
    ]
  ) {
    id
  }
}

我的问题是:如何在不input:工作的情况下获得突变?

我尝试从文档中复制(修改)示例。但是如果我写一个这样的突变:

type Mutation {
    createTask(input: CreateTaskInput! @spread): Task! @create
}

当我尝试省略input:时,graphql-playground 抱怨:“需要CreateTaskInput类型的字段createTask参数输入,但未提供”

现在我尝试将架构更改为:

type Mutation {
    createTask(CreateTaskInput! @spread): Task! @create
}

但随后服务器给出了一个ParseException.

我确实更喜欢没有的语法,input:因为它的重复性要少得多。有人可以帮忙吗?

4

1 回答 1

1

如果你想写一个没有 的突变input,也可以省略该@spread指令。所以:

type Mutation {
    createTask(
        id: ID
        name: String
    ): Task! @create
}

但我认为将其包含在input. 当然你可以做任何你想做的事。

于 2020-01-25T12:46:45.573 回答