Tin*_*son 6 java graphql graphql-java graphql-spqr
我得到以下内容,似乎无法找到答案.
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'}]
Run Code Online (Sandbox Code Playgroud)
我的守则.
询问
@GraphQLQuery(name = "find_by_id")
public Event findById(@GraphQLArgument(name = "id") Long id) {
Run Code Online (Sandbox Code Playgroud)
架构
@EJB
private EventFacade eventFacade; // Normal stateless bean
GraphQLSchema guestSchema = new GraphQLSchemaGenerator()
.withOperationsFromSingleton(eventFacade)
.withValueMapperFactory(new JacksonValueMapperFactory())
.withDefaults()
.generate();
GraphQL graphQL = GraphQL.newGraphQL(guestSchema).build();
Run Code Online (Sandbox Code Playgroud)
要执行的代码
String query = "{find_by_id (id: 1){eventName}}";
ExecutionResult result = graphQL.execute(query);
Run Code Online (Sandbox Code Playgroud)
使用SPQR lib
事件POJO是基本的,eventName为String,抽象(Parent)类为id.实体类位于不同的jar(Entity Jar)中.执行查询和构建模式的代码位于EJB Jar中.
任何我出错的帮助/指示将不胜感激.
UPDATE 创建了一个git问题来帮助解决Git问题
小智 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();
Run Code Online (Sandbox Code Playgroud)