【发布时间】:2019-06-21 22:24:48
【问题描述】:
我有以下简单的模式/查询示例,其中包含 Java 中的编程模式创建。在这里,我正在尝试创建以下架构:
query{
board {
name: string
}
}
代码:
GraphQLObjectType queryType = GraphQLObjectType.newObject()
.name("BoardQuery")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("board")
.type(GraphQLObjectType.newObject().name("boardType")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("name")
.type(GraphQLString).build()))
.build())
.build();
GraphQLCodeRegistry graphQLCodeRegistry = GraphQLCodeRegistry.newCodeRegistry()
.dataFetcher(FieldCoordinates.coordinates("boardType","name"),
new StaticDataFetcher("hello")).build();
GraphQLSchema graphQLSchema = GraphQLSchema.newSchema()
.query(queryType)
.codeRegistry(graphQLCodeRegistry)
.build();
GraphQL graphQl = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult executionResult = graphQl.execute("query { board { name } }");
System.out.println(executionResult.getData().toString());
预期输出:
{name:hello}
实际输出:
{name:null}
我错过了什么吗?
【问题讨论】:
标签: java graphql-java