首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GraphQL-java: Error:内省结果缺少接口

GraphQL-java: Error:内省结果缺少接口
EN

Stack Overflow用户
提问于 2019-04-30 17:08:10
回答 2查看 864关注 0票数 1

我刚刚开始使用GraphQL,我在让它工作时遇到了一些问题。无论我有什么样的模式,我都会得到Error: Introspection result missing interfaces

模式:

代码语言:javascript
复制
schema {
    query: Query
}

type Query {
    dd: String
}

GraphiQL的结果:

代码语言:javascript
复制
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,设置非常基本:

代码语言:javascript
复制
@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();
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-06 15:38:50

我在杰克逊的属性中忽略了non_empty列表,这使得GraphiQL和牛市抛出和异常。

票数 1
EN

Stack Overflow用户

发布于 2019-08-01 16:06:35

当响应中缺少GraphiQL所期望的接口属性时,就会出现此问题。

当使用具有适当配置的graphql-java-servlet定义GraphQLObjectMapper时,可以帮助避免将序列化属性设置为JsonInclude.Include.NON_NULL,从而存在接口属性。

代码语言:javascript
复制
   @Bean
   public GraphQLObjectMapper graphQLObjectMapper() {
       return GraphQLObjectMapper.newBuilder()
               .withObjectMapperProvider(ObjectMapper::new)
               .build();
   }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55925747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档