GraphQL-java:错误:内省结果缺少接口

时间:2019-04-30 17:08:10

标签: graphql-java

我刚开始使用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();
    }
}

2 个答案:

答案 0 :(得分:0)

我在jackson中拥有忽略非空列表的属性,这使GraphiQL和Altair抛出异常。

答案 1 :(得分:0)

当响应中没有GraphiQL期望的 interfaces 属性时,就会发生此问题。

使用 graphql-java-servlet 时-通过适当的配置定义 GraphQLObjectMapper 有助于避免将序列化属性设置为 JsonInclude.Include.NON_NULL ,因此存在 interfaces 属性。

   @Bean
   public GraphQLObjectMapper graphQLObjectMapper() {
       return GraphQLObjectMapper.newBuilder()
               .withObjectMapperProvider(ObjectMapper::new)
               .build();
   }