How to query all the GraphQL type fields without writing a long query?(如何在不编写长查询的情况下查询所有 GraphQL 类型字段?)
问题描述
假设您有一个 GraphQL 类型并且它包含许多字段.如何在不写下包含所有字段名称的长查询的情况下查询所有字段?
Assume you have a GraphQL type and it includes many fields. How to query all the fields without writing down a long query that includes the names of all the fields?
例如,如果我有这些字段:
For example, If I have these fields :
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'
]
];
}
要查询所有字段,通常查询是这样的:
To query all the fields usually the query is something like this:
FetchUsers{users(id:"2"){id,username,count}}
但我想要一种无需编写所有字段即可获得相同结果的方法,如下所示:
But I want a way to have the same results without writing all the fields, something like this:
FetchUsers{users(id:"2"){*}}
//or
FetchUsers{users(id:"2")}
有没有办法在 GraphQL 中做到这一点??
Is there a way to do this in GraphQL ??
我正在使用 Folkloreatelier/laravel-graphql 库.
推荐答案
不幸的是,您想要做的事情是不可能的.GraphQL 要求您明确指定您希望从查询中返回哪些字段.
Unfortunately what you'd like to do is not possible. GraphQL requires you to be explicit about specifying which fields you would like returned from your query.
这篇关于如何在不编写长查询的情况下查询所有 GraphQL 类型字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在不编写长查询的情况下查询所有 GraphQL 类型字段?


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01