本文共 580 字,大约阅读时间需要 1 分钟。
假设你有一个GraphQL类型,它包含许多字段.
如何查询所有的字段,而不会写下包含所有字段名称的长查询?
例如,如果我有这些字段:
public function fields()
{
return [
'id' => [
'type' => Type::nonNull(Type::string()),
'description' => 'The id of the user'
],
'username' => [
'type' => Type::string(),
'description' => 'The email of user'
],
'count' => [
'type' => Type::int(),
'description' => 'login count for the user'
]
];
}
要查询所有的字段通常查询是这样的:
FetchUsers{users(id:"2"){id,username,count}}
但是,我想要一种方法来获得相同的结果,而无需编写所有的字段,就像这样:
FetchUsers{users(id:"2"){*}}
//or
FetchUsers{users(id:"2")}
有没有办法在GraphQL中这样做?
我使用Folkloreatelier / laravel-graphql库.
转载地址:http://wysdy.baihongyu.com/