【发布时间】:2019-07-20 13:57:30
【问题描述】:
我在 Spring Boot 2+ 和 GraphQL 中使用以下示例,但在加载 graphiql 时出现以下错误,架构未加载。
https://github.com/TechPrimers/spring-boot-graphql-query-example
代码通过来自邮递员但来自 Graphiql 的 POST 调用运行。
@RestController
public class GraphQLController {
private GraphQLService graphQLService;
public GraphQLController(GraphQLService graphQLService) {
this.graphQLService = graphQLService;
}
@PostMapping("/graphql")
public ExecutionResult graphQl(@RequestBody String query) {
ExecutionResult result = graphQLService.getGraphQL().execute(query);
return result;
}
}
{
"data": null,
"errors": [
{
"message": "Invalid Syntax : offending token '\"query\"' at line 1 column 1",
"sourcePreview": "{\"query\":\"\\n query IntrospectionQuery {\\n __schema {\\n queryType { name }\\n mutationType { name }\\n types {\\n ...FullType\\n }\\n directives {\\n name\\n description\\n locations\\n args {\\n ...InputValue\\n }\\n }\\n }\\n }\\n\\n fragment FullType on __Type {\\n kind\\n name\\n description\\n fields(includeDeprecated: true) {\\n name\\n description\\n args {\\n ...InputValue\\n }\\n type {\\n ...TypeRef\\n }\\n isDeprecated\\n deprecationReason\\n }\\n inputFields {\\n ...InputValue\\n }\\n interfaces {\\n ...TypeRef\\n }\\n enumValues(includeDeprecated: true) {\\n name\\n description\\n isDeprecated\\n deprecationReason\\n }\\n possibleTypes {\\n ...TypeRef\\n }\\n }\\n\\n fragment InputValue on __InputValue {\\n name\\n description\\n type { ...TypeRef }\\n defaultValue\\n }\\n\\n fragment TypeRef on __Type {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n ofType {\\n kind\\n name\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n\"}\n",
"offendingToken": "\"query\"",
"locations": [
{
"line": 1,
"column": 1,
"sourceName": null
}
],
"errorType": "InvalidSyntax",
"path": null,
"extensions": null
}
],
"dataPresent": false,
"extensions": null
}
【问题讨论】:
-
在我的回答中添加了更多详细信息
标签: java spring-boot graphql graphql-java