How to query all the GraphQL type fields without writing a long query?
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.
How to define schema in graphql query for unknown or dynamic response
In general you should avoid "generic" key-value pairs in your graphql schema, because you than loose the typesafety. I think this is one of the reasons, why there is no Map type in GraphQL.
In your case, you may could use a union type for your result instead.
If you really need something more generic, you could use an array with a tuple-like object inside, like so:
type Tuple {
name: String!
value: String!
}
type StudentDetails {
# ...
additionalValues: [Tuple!]
}
(See also this discussion: https://github.com/graphql/graphql-spec/issues/101#issuecomment-170170967.)
Another option: specify all possible returned fields from all different student types and mark them as optional (nullable):
type StudentResponse {
# common for ALL students (required, non-nullable)
chemistry: String!
maths: String!
# optional, returned only for some students
language: String
physics: String
}
Hope that helps!
Related Topics
Insert Query Check If Record Exists - If Not, Insert It
How to Count Same Values in an Array and Store It to a Variable
Using Value of a Column as Index in Results Using Pdo
Mysqli_Stmt::Execute() Expects Exactly 0 Parameters, 1 Given
Whats the Easiest Way to Determine If a User Is Online? (Php/Mysql)
How to Parse a CSV File to Grab the Column Names First Then the Rows That Relate to It
Download a File from Ftp Using Curl and PHP
Explode() into $Key=>$Value Pair
Executing a Powershell Script from PHP
Using Variables in MySQL Update (Php/Mysql)
What Does the B in Front of String Literals Do
Permission Denied with Bash.Sh to Run Cron
Codeigniter Sessions Not Working After Migration
How to Execute PHP Code Within JavaScript