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 类型字段?
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
