ValidationError FieldUndefined SPQR GraphQL

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

Event POJO 是基本的,eventName 是一个字符串和一个来自抽象(父)的 id class。实体 class 在不同的 jar (Entity Jar) 中。执行查询和构建模式的代码在 EJB Jar 中。

如有任何帮助/指出我出错的地方,我们将不胜感激。

更新 创建了一个 git 问题来帮助解决 Git Issue

我相信你必须改变这个 String query = "{find_by_id (id: 1){eventName}}"; 到 字符串查询 = "\"query\": {find_by_id (id: 1){eventName}}";

您能否添加 Even Class 详细信息,我猜这就是您的问题所在,因为您 URL 中的作者将 class 传递给查询,但您仅传递 ID(find_by_id) 后跟 {eventName} 我认为它应该更改为

"{Event(id: 1){eventName}}"

作者在下面的供应商示例中给出了有关如何使用 findByID 的示例 Class,他以与您不同的格式调用它,也许可以试一试 :) https://github.com/leangen/graphql-spqr-samples

我在这里找到了这个解决方案:https://github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type

Reference: To treat all missing type arguments as Object or apply custom type transformation logic, supply a TypeTransformer:

这应该适合你。

    GraphQLSchema schema = new GraphQLSchemaGenerator()
           .withBasePackages(basePackages)
           .withTypeTransformer(new DefaultTypeTransformer(true, true))
           .withOperationsFromSingleton(eventFacade).generate();