沃梦达 / 编程问答 / php问题 / 正文

如何在不编写长查询的情况下查询所有 GraphQL 类型字段?

How to query all the GraphQL type fields without writing a long query?(如何在不编写长查询的情况下查询所有 GraphQL 类型字段?)

本文介绍了如何在不编写长查询的情况下查询所有 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 类型字段?

基础教程推荐