7

I am getting the following and cant seem to find an answer.

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'}]

My Code.

Query

@GraphQLQuery(name = "find_by_id")
public Event findById(@GraphQLArgument(name = "id") Long id) {

Schema Gen

@EJB
private EventFacade eventFacade; // Normal stateless bean 

GraphQLSchema guestSchema = new GraphQLSchemaGenerator()
            .withOperationsFromSingleton(eventFacade)
            .withValueMapperFactory(new JacksonValueMapperFactory())
            .withDefaults()
            .generate();

GraphQL graphQL = GraphQL.newGraphQL(guestSchema).build();

Code to Execute

String query = "{find_by_id (id: 1){eventName}}";
ExecutionResult result = graphQL.execute(query);

Using the SPQR lib

Event POJO is basic with eventName as a String and an id from the abstract (Parent) class. Entity class is in a different jar (Entity Jar). Code to execute Query and build schema are in the EJB Jar.

Any help / indication where i went wrong will be appreciated.

UPDATE Created a git issue to help solve Git Issue

4

3 回答 3

5

我在这里找到了这个解决方案: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();
于 2018-05-10T08:55:24.673 回答
1

我相信您必须更改此 String query = "{find_by_id (id: 1){eventName}}"; to String query = "\"query\": {find_by_id (id: 1){eventName}}";

于 2018-04-26T23:09:57.210 回答
1

您可以添加偶数类详细信息吗,我猜这就是您的问题所在,因为您的 URL 中的作者将一个类传递给查询,但是您只传递了 ID(find_by_id) 后跟 {eventName} 我认为应该更改至

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

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

于 2018-05-03T03:06:20.320 回答