【问题标题】:Introspect graphql schema using *.graphqls files使用 *.graphqls 文件内省 graphql 架构
【发布时间】:2021-06-26 16:02:38
【问题描述】:

目前我正在使用 com.graphql-java-kickstart 库和 spring boot 来运行 graphql 服务器。现在对于合同测试,我希望能够生成 json 模式,就像我在执行请求“/graphql/schema.json”时那样。但是没有运行服务器,只基于 .graphqls 文件。

是否有任何基于 jvm(首选)的工具可以帮助我。

【问题讨论】:

    标签: graphql graphql-java


    【解决方案1】:

    我找到了使用 graphql-java 库的解决方案。也许它对我以外的人有用。

        ObjectMapper mapper= new ObjectMapper()
        Collection<File> files = FileUtils.listFiles(inputDir, new String[]{"graphqls"}, true);
    
        SchemaParser schemaParser = new SchemaParser();
        TypeDefinitionRegistry mergedDefinitoionRegistry = new TypeDefinitionRegistry();
        files.forEach(file -> {
            TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(file);
            mergedDefinitoionRegistry.merge(typeDefinitionRegistry);
        });
    
        SchemaGenerator schemaGenerator = new SchemaGenerator();
        GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(mergedDefinitoionRegistry, RuntimeWiring.MOCKED_WIRING);
    
        GraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();
        ExecutionResult executionResult = graphQL.execute(IntrospectionQuery.INTROSPECTION_QUERY);
    
        return mapper.writeValueAsString(executionResult);
    

    【讨论】:

      猜你喜欢
      • 2019-02-05
      • 2021-05-18
      • 2017-05-11
      • 2017-07-24
      • 2018-09-13
      • 2017-08-22
      • 2018-11-18
      • 2021-06-02
      • 2019-11-06
      相关资源
      最近更新 更多