Graphql-查询返回null
我正在使用java的GraphQLJava注释库从spring后端检索数据Graphql-查询返回null,graphql,graphql-java,Graphql,Graphql Java,我正在使用java的GraphQLJava注释库从spring后端检索数据 <dependency> <groupId>io.github.graphql-java</groupId> <artifactId>graphql-java-annotations</artifactId> <version>7.1</version> </dependency> 以下是查
<dependency>
<groupId>io.github.graphql-java</groupId>
<artifactId>graphql-java-annotations</artifactId>
<version>7.1</version>
</dependency>
以下是查询:
@GraphQLName("queryTest")
public class QueryTest {
@GraphQLField
public static Test byId(final DataFetchingEnvironment env, @GraphQLName("id") Long id) {
return new Test();
}
}
最后是Test.class
@GraphQLName("Test")
public class Test {
private String id;
private String name;
public Test() {
this("0");
}
public Test(String id) {
this.setName("Name" + id);
this.setId(id);
}
@GraphQLField
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@GraphQLField
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
这是我的电话:
{
"query" : "query queryTest { byId(id: 2) { getId } }",
"operationName" : "queryTest"
}
这就是我得到的结果:
{
"data": {
"byId": null
}
}
我调试到graphql执行中,发现模式包含TestClass和Test。所以类型和查询是已知的。使用此配置,我没有获取程序或解析程序。找到了解决方案:
为了通过AnnotationsSchemaCreator生成器正确创建架构,我必须更改我的提供程序类:
GraphQLSchema graphQLSchema = AnnotationsSchemaCreator.newAnnotationsSchema()
.query(QueryTest.class)
.typeFunction(new ZonedDateTimeFunction())
.build();
this.graphQL = GraphQL.newGraphQL(graphQLSchema).build();
GraphQLSchema graphQLSchema = AnnotationsSchemaCreator.newAnnotationsSchema()
.query(QueryTest.class)
.typeFunction(new ZonedDateTimeFunction())
.build();
this.graphQL = GraphQL.newGraphQL(graphQLSchema).build();