我刚刚开始使用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中使用graphql,设置非常基本:
@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();
}
}发布于 2019-05-06 15:38:50
我在杰克逊的属性中忽略了non_empty列表,这使得GraphiQL和牛市抛出和异常。
发布于 2019-08-01 16:06:35
当响应中缺少GraphiQL所期望的接口属性时,就会出现此问题。
当使用具有适当配置的graphql-java-servlet定义GraphQLObjectMapper时,可以帮助避免将序列化属性设置为JsonInclude.Include.NON_NULL,从而存在接口属性。
@Bean
public GraphQLObjectMapper graphQLObjectMapper() {
return GraphQLObjectMapper.newBuilder()
.withObjectMapperProvider(ObjectMapper::new)
.build();
}https://stackoverflow.com/questions/55925747
复制相似问题