【发布时间】:2021-06-26 16:02:38
【问题描述】:
目前我正在使用 com.graphql-java-kickstart 库和 spring boot 来运行 graphql 服务器。现在对于合同测试,我希望能够生成 json 模式,就像我在执行请求“/graphql/schema.json”时那样。但是没有运行服务器,只基于 .graphqls 文件。
是否有任何基于 jvm(首选)的工具可以帮助我。
【问题讨论】:
标签: graphql graphql-java
目前我正在使用 com.graphql-java-kickstart 库和 spring boot 来运行 graphql 服务器。现在对于合同测试,我希望能够生成 json 模式,就像我在执行请求“/graphql/schema.json”时那样。但是没有运行服务器,只基于 .graphqls 文件。
是否有任何基于 jvm(首选)的工具可以帮助我。
【问题讨论】:
标签: graphql graphql-java
我找到了使用 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);
【讨论】: