为什么返回 null 的字符串为 java.lang.Object@.?
Why is a String that is null returned as java.lang.Object@.?
我的理解是 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
}
}
有人有什么想法吗?
进口有问题。
当我将 Eclipse 更改为 import graphql.GraphQL;
时,Eclipse 添加了 import graphql.nextgen.GraphQL;
一切正常。
我的理解是 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
}
}
有人有什么想法吗?
进口有问题。
当我将 Eclipse 更改为 import graphql.GraphQL;
时,Eclipse 添加了 import graphql.nextgen.GraphQL;
一切正常。