您好我正在尝试创建一个返回 JSON 的解析器,我将此库与自定义标量一起使用https://github.com/mll-lab/graphql-php-scalars
我正在使用这样的 JSON 标量:
schema.graphql:
input CustomInput {
field1: String!
field2: String!
}
type Mutation {
getJson(data: CustomInput): JSON @field(resolver: "App\\GraphQL\\Mutations\\TestResolver@index")
}
测试解析器.php
public function index($rootValue, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
{
$data = array('msg'=>'hellow world', 'trueorfalse'=>true);
return \Safe\json_encode($data);
}
GraphQL 游乐场
mutation{
getJson(data: { field1: "foo", field2: "bar" })
}
------------ response------------
{
"data": {
"getJson": "\"{\\\"msg\\\":\\\"hello world\\\",\\\"trueorfalse\\\":true}\""
}
}
如您所见,它返回一个字符串,而不是 JSON ......我做错了什么?