微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

解析类型 'Query' [@6:1] 时,字段输入类型 'Long' 不存在

如何解决解析类型 'Query' [@6:1] 时,字段输入类型 'Long' 不存在

在初始化 graphql 模式时,我遇到了错误堆栈跟踪。

调用init方法失败;嵌套异常是 SchemaProblem{errors=[解析类型 'Query' [@6:1] 时不存在字段输入类型 'Long',解析类型 'ObjectRef' 时不存在字段类型 'Long' [@17: 1]]} 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) 在 org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessproperties(AutowiredAnnotationBeanPostProcessor.java:397) 在

其中 ObjectRef 是我的对象。

type ObjectRef{
id:Long
qualifier : String
}

我正在使用以下一组 jar 来编译我的项目。

compile files('libs/latest/graphql-java-servlet-6.1.3.jar')
compile files('libs/latest/graphql-java-16.2.jar')
compile files('libs/latest/graphql-java-tools-5.2.4.jar')
compile files('libs/latest/graphql-spring-boot-autoconfigure-5.0.2.jar')
compile files('libs/latest/graphql-spring-boot-starter-5.0.2.jar')
compile files('libs/latest/antlr4-runtime-4.9.2.jar')
compile files('libs/lombok-1.16.18.jar')
compile files('libs/latest/graphql-java-extended-scalars-16.0.1.jar')

这是我的架构加载器。

@postconstruct
private void loadSchema() throws IOException {
// get the schema
File schemaFile = schemaResource.getFile();
System.out.println(schemaFile.getAbsolutePath());
// parse schema
TypeDeFinitionRegistry typeRegistry = new SchemaParser().parse(schemaFile);
System.out.println("type Registry..."+typeRegistry);
RuntimeWiring wiring = buildruntimeWiring();
System.out.println("wiring..."+wiring);
GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(typeRegistry,wiring);
System.out.println("schema..."+schema);
graphQL = GraphQL.newGraphQL(schema).build();
}

private RuntimeWiring buildruntimeWiring() {
System.out.println("buildruntimeWiring...");
return RuntimeWiring.newRuntimeWiring().type("Query",typeWiring -> typeWiring
.dataFetcher("a",customDataFetcher)
).build();
}

问候 库沙格拉

解决方法

我能够使用标量解决上述问题。我创建了一个名为 Long 的新标量,并在 .graphqls 中使用以下方式使用相同的标量。标量 Long return RuntimeWiring.newRuntimeWiring().type("Query",typeWiring -> typeWiring .dataFetcher("a",customDataFetcher).scalar(ExtendedScalars.GraphQLLong)).build();它还需要创建一个 ScalarType 实现以按预期方式运行。如果有人需要完整代码,请随时 ping 这张票。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。