【发布时间】:2019-09-19 09:35:18
【问题描述】:
我刚开始使用 GraphQL,但在使用它时遇到了一些问题。
不管我有什么样的架构,我都会得到Error: Introspection result missing interfaces。
架构:
schema {
query: Query
}
type Query {
dd: String
}
GraphiQL 的结果:
Error: Introspection result missing interfaces: {"kind":"OBJECT","name":"Query","fields":[{"name":"dd","type":{"kind":"SCALAR","name":"String"},"isDeprecated":false}]}
at E (file:///C:/Program%20Files/GraphiQL/resources/app.asar/dist/bundle.js:32:22809)
at _ (file:///C:/Program%20Files/GraphiQL/resources/app.asar/dist/bundle.js:32:22340)
at r (file:///C:/Program%20Files/GraphiQL/resources/app.asar/dist/bundle.js:32:21822)
at file:///C:/Program%20Files/GraphiQL/resources/app.asar/dist/bundle.js:32:25249
at Array.map (native)
at i (file:///C:/Program%20Files/GraphiQL/resources/app.asar/dist/bundle.js:32:25226)
at file:///C:/Program%20Files/GraphiQL/resources/app.asar/dist/bundle.js:26:30839
at process._tickCallback (internal/process/next_tick.js:103:7)
无论我更改什么,我仍然会遇到这个错误,除了当我更改变量名时它引用了不同的地方。 是不是我误解了什么?
我在 Spring Boot 中使用 graphql-java,而且设置相当基本:
@RestController
public class GraphQLEndpoint {
@Autowired
private GraphQL graphQL;
@PostMapping(path = "/graphql", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
Map<String, Object> graphql(@RequestBody GraphQLRequest request, WebRequest webRequest) throws ExecutionException, InterruptedException, JsonProcessingException {
val query = nonNull(request.getQuery()) ? request.getQuery() : "";
val variables = (Map<String, Object>) (nonNull(request.getVariables()) ? request.getVariables() : emptyMap());
val executionInput = ExecutionInput.newExecutionInput()
.query(query)
.operationName(request.getOperationName())
.variables(variables)
.build();
return graphQL.execute(executionInput).toSpecification();
}
}
@Configuration
public class GraphQLConfig {
@Bean
GraphQL graphQL(@Value("${classpath:schemas/pdl.graphqls}") ClassPathResource schemaFile) throws IOException {
val typeRegistry = new SchemaParser().parse(schemaFile.getFile());
val runtimeWiring = RuntimeWiring.newRuntimeWiring()
.type(typeRuntimeWiring())
.build();
val schema = new SchemaGenerator().makeExecutableSchema(typeRegistry, runtimeWiring);
return GraphQL.newGraphQL(schema).build();
}
private TypeRuntimeWiring typeRuntimeWiring() {
return TypeRuntimeWiring.newTypeWiring("Query")
.dataFetcher("dd", environment -> "test")
.build();
}
}
【问题讨论】:
标签: graphql-java