GraphQL 突变不适用于 RuntimeWiring.newRuntimeWiring()
GraphQL Mutation not working with RuntimeWiring.newRuntimeWiring()
我在 GraphQL Java 中定义了一个简单的模式来添加 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();
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
}
通过Postman的变异是:
{
newBook(
isn:"1",
title: "test title",
publisher: "test publisher",
authors:"test author",
publishedDate: "2 Nov 2018"
) {
title
}
}
请帮帮我。它没有选择 Mutation Type,但 Query 工作得非常好。我错过了什么吗?
我不确定错误指的是什么,但您确实需要在执行突变时包括操作(query
与 mutation
)。也就是说,您的请求应该更像这样:
mutation ArbitraryOperationName {
newBook(
isn:"1",
title: "test title",
publisher: "test publisher",
authors:"test author",
publishedDate: "2 Nov 2018"
) {
title
}
}
在编写查询时,您可以使用 shorthand 符号并省略 query
关键字,但突变必须始终包含 mutation
以表明您正在进行突变而不是查询。
我在 GraphQL Java 中定义了一个简单的模式来添加 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();
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
}
通过Postman的变异是:
{
newBook(
isn:"1",
title: "test title",
publisher: "test publisher",
authors:"test author",
publishedDate: "2 Nov 2018"
) {
title
}
}
请帮帮我。它没有选择 Mutation Type,但 Query 工作得非常好。我错过了什么吗?
我不确定错误指的是什么,但您确实需要在执行突变时包括操作(query
与 mutation
)。也就是说,您的请求应该更像这样:
mutation ArbitraryOperationName {
newBook(
isn:"1",
title: "test title",
publisher: "test publisher",
authors:"test author",
publishedDate: "2 Nov 2018"
) {
title
}
}
在编写查询时,您可以使用 shorthand 符号并省略 query
关键字,但突变必须始终包含 mutation
以表明您正在进行突变而不是查询。