問題:
Assume you have a GraphQL type and it includes many fields.假設您有一個 GraphQL 類型並且它包含許多字段。 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")}
Is there a way to do this in GraphQL ??有沒有辦法在 GraphQL 中做到這一點?
I'm using Folkloreatelier/laravel-graphql library.我正在使用Folkloreatelier/laravel-graphql庫。
解決方案:
參考一: https://en.stackoom.com/question/2JUyc參考二: https://stackoom.com/question/2JUyc