我的理解是null在graphql响应中是可接受的值。 因此,我必须误解了某些东西,或者我做的是根本上错误的事情,因为现在我得到的是“ java.lang.Object@7deb1b9”而不是null。
schema {
query: Query
}
type Query {
greeting: String
}
Graphql看起来像这样:
final Builder vContextBuilder = new Builder()
.of("locale", mLocale)
.of("securityContext", mSecurityContext);
final ExecutionInput vExecutionInput = ExecutionInput
.newExecutionInput()
.query(mQuery)
.context(vContextBuilder)
.build();
final InputStream vSchemaInputStream = Thread
.currentThread()
.getContextClassLoader()
.getResourceAsStream(SCHEMA_FILE_URI);
final TypeDefinitionRegistry vTypeDefinitionRegistry = new SchemaParser()
.parse(new InputStreamReader(vSchemaInputStream));
final RuntimeWiring vRuntimeWiring = RuntimeWiring.newRuntimeWiring()
.type("Query", typeWiring -> typeWiring
.dataFetcher("greeting", new GreetingFetcher())
)
.build();
final GraphQLSchema vGraphQLSchema = new SchemaGenerator()
.makeExecutableSchema(vTypeDefinitionRegistry, vRuntimeWiring);
final GraphQL vGraphQL = GraphQL.newGraphQL(vGraphQLSchema)
.build();
final ExecutionResult vExecutionResult = vGraphQL.execute(vExecutionInput);
final Map<String, Object> toSpecificationResult = vExecutionResult.toSpecification();
和Greetingfetcher:
public class GreetingFetcher extends StaticDataFetcher {
public GreetingFetcher() {
super("Hello!");
//super(null);
}
}
查询:
query {
greeting
}
来自super("Hello!");
的回复:
{
"data": {
"greeting": "Hello!"
}
}
来自super(null);
的回复:
{
"data": {
"greeting": "java.lang.Object@7deb1b9"
}
}
应该不是:
{
"data": {
"greeting": null
}
}
有人有什么主意吗?
答案 0 :(得分:0)
问题与进口有关。
当我将其更改为import graphql.nextgen.GraphQL;
时,Eclipse已添加import graphql.GraphQL;
。