Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GraphQL突变不能与RuntimeWiring一起使用。newRuntimeWiring()_Graphql_Graphql Java - Fatal编程技术网

GraphQL突变不能与RuntimeWiring一起使用。newRuntimeWiring()

GraphQL突变不能与RuntimeWiring一起使用。newRuntimeWiring(),graphql,graphql-java,Graphql,Graphql Java,我在GraphQLJava中定义了一个简单的模式来添加Book并获取[Book]。我的模式如下: schema { query: Query mutation : Mutation } type Query { allBooks: [Book] book(id: String): Book } type Book { isn: String title: String publisher: String author: String publishedDate:

我在GraphQLJava中定义了一个简单的模式来添加
Book
并获取
[Book]
。我的模式如下:

schema {
 query: Query
 mutation : Mutation
}

type Query {
 allBooks: [Book]
 book(id: String): Book
}

type Book {
  isn: String
  title: String
  publisher: String
  author: String
  publishedDate: String
}

input BookType {
  isn: String
  title: String
  publisher: String
  author: String
  publishedDate: String
}

type Mutation {
  newBook(
      isn: String!,
      title: String!,
      publisher: String!,
      authors:String!,
      publishedDate: String!
  ): Book
}
我创建了如下的运行时连接:

RuntimeWiring.newRuntimeWiring()
  .type("Query", typeWiring ->
    typeWiring.dataFetcher("allBooks", allBooksDataFetcher))
  .type("Mutation", typeWiring ->
    typeWiring.dataFetcher("newBook", addBooksDataFetcher))
  .build();
mutation ArbitraryOperationName {
  newBook(
    isn:"1",
    title: "test title",
    publisher: "test publisher",
    authors:"test author",
    publishedDate: "2 Nov 2018"
  ) {
    title
  }
}
allBooks
查询工作正常,但
newBook
变异不工作,并出现以下错误:

"errors": [
  {
    "validationErrorType": "FieldUndefined",
    "message": "Validation error of type FieldUndefined: Field oneBook is undefined",
    "locations": [
      {
        "line": 3,
        "column": 3
      }
    ],
    "errorType": "ValidationError"
  }
],
  "data": null,
  "extensions": null
}
邮递员的变异是:

{
  newBook(
    isn:"1",
    title: "test title",
    publisher: "test publisher",
    authors:"test author",
    publishedDate: "2 Nov 2018"
  ) {
    title
  }
}

请帮帮我。它并没有选择突变类型,但查询工作绝对正常。我遗漏了什么吗?

我不确定错误指的是什么,但在执行变异时确实需要包含操作(
query
vs
mutation
)。也就是说,您的请求应该更像这样:

RuntimeWiring.newRuntimeWiring()
  .type("Query", typeWiring ->
    typeWiring.dataFetcher("allBooks", allBooksDataFetcher))
  .type("Mutation", typeWiring ->
    typeWiring.dataFetcher("newBook", addBooksDataFetcher))
  .build();
mutation ArbitraryOperationName {
  newBook(
    isn:"1",
    title: "test title",
    publisher: "test publisher",
    authors:"test author",
    publishedDate: "2 Nov 2018"
  ) {
    title
  }
}
编写查询时,您可以使用简写符号并省略
query
关键字,但突变必须始终包含
mutation
,以表明您正在进行突变而不是查询。

谢谢Daniel,它起到了作用:)我没有包含突变关键字。非常感谢:)