[英]ValidationError FieldUndefined SPQR GraphQL
我得到以下内容,似乎无法找到答案。
Error [ValidationError{validationErrorType=FieldUndefined, queryPath=[find_by_id], message=Validation error of type FieldUndefined: Field 'find_by_id' in type 'Query' is undefined @ 'find_by_id', locations=[SourceLocation{line=1, column=2}], description='Field 'find_by_id' in type 'Query' is undefined'}]
我的守则。
询问
@GraphQLQuery(name = "find_by_id")
public Event findById(@GraphQLArgument(name = "id") Long id) {
架构
@EJB
private EventFacade eventFacade; // Normal stateless bean
GraphQLSchema guestSchema = new GraphQLSchemaGenerator()
.withOperationsFromSingleton(eventFacade)
.withValueMapperFactory(new JacksonValueMapperFactory())
.withDefaults()
.generate();
GraphQL graphQL = GraphQL.newGraphQL(guestSchema).build();
要执行的代码
String query = "{find_by_id (id: 1){eventName}}";
ExecutionResult result = graphQL.execute(query);
使用SPQR lib
事件POJO是基本的,eventName为String,抽象(Parent)类为id。 实体类位于不同的jar(Entity Jar)中。 执行查询和构建模式的代码位于EJB Jar中。
任何我出错的帮助/指示将不胜感激。
UPDATE创建了一个git问题来帮助解决Git问题
我在这里找到了这个解决方案: https : //github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type
参考:要将所有缺少的类型参数视为Object或应用自定义类型转换逻辑,请提供TypeTransformer:
这应该适合你。
GraphQLSchema schema = new GraphQLSchemaGenerator()
.withBasePackages(basePackages)
.withTypeTransformer(new DefaultTypeTransformer(true, true))
.withOperationsFromSingleton(eventFacade).generate();
我相信你必须改变这个String query =“{find_by_id(id:1){eventName}}”; to String query =“\\”query \\“:{find_by_id(id:1){eventName}}”;
你可以添加偶数类详细信息吗,我猜你的问题就在于你的问题所在,因为你的URL中的作者将一个类传递给查询,但是你只传递了ID(find_by_id),后面是{eventName}我想它应该被改变至
"{Event(id: 1){eventName}}"
作者给出了一个关于如何在以下示例中为供应商类使用findByID的示例,他以与您的格式不同的格式调用它,也许给它一个镜头:) https://github.com/leangen/graphql-spqr -samples
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.