Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphiQL: How to populate all fields

Is there a way (or a shortcut) to populate all fields of a Query?

Let's take https://graphql.org/swapi-graphql/ as an example.

I know that by ctrl + space I can invoke the autosuggest. enter image description here

But what if I wanted to populate all of the fields (name, height etc..) without having to manually type them out?

like image 216
Dimo Avatar asked Sep 24 '18 07:09

Dimo


People also ask

How do you use GraphiQL?

To access the GraphiQL interface, type the URL or IP address for SL1 in a browser, add /gql to the end of the URL or IP address, and press Enter. GraphiQL is not maintained by ScienceLogic. You can access its documentation at https://github.com/graphql/graphiql.

What is __ Typename in GraphQL?

The __typename field returns the object type's name as a String (e.g., Book or Author ). GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return multiple types (i.e., a union or interface).

How do you pass parameters in GraphQL query?

When you're passing arguments in code, it's generally better to avoid constructing the whole query string yourself. Instead, you can use $ syntax to define variables in your query, and pass the variables as a separate map. . then(data => console.

What is introspection query?

Introspection is the ability to query which resources are available in the current API schema. Given the API, via introspection, we can see the queries, types, fields, and directives it supports.


1 Answers

Execute the query without specifying the child fields

graphiql will kindly fill in each field for you. In your case:

{
    person(personID: 1)
}

will autocomplete to

{
  person(personID: 1) {
    name
    birthYear
    eyeColor
    gender
    hairColor
    height
    mass
    # etc...
  }
}
like image 138
bryce Avatar answered Sep 25 '22 00:09

bryce