Reputation: 487
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.
But what if I wanted to populate all of the fields (name, height etc..) without having to manually type them out?
Upvotes: 10
Views: 6219
Reputation: 218
There is not a way to do that in the context you are hoping for. Graphql was designed with the idea that you know exactly what you're querying for. What you can do though, is write it down once and then save it on your notes so you have that query for the future.
Alternatively, if you're working with an autogenerated model schema based on schema.graphql (ex: aws amplify project), you can go into the schema files and copy their pre-generated queries, mutations, etc., based on your defined input types.
These are usually found in your backends' src/graphql/ folder. See example string for this arbitrary model:
Upvotes: 0
Reputation: 19
Generally, if you enter the base type without the paramaters like shown below the fields will populate when you "Ctrl-Enter or press the play button" directly after it. Strangely, I don't see it happening on that example url provided but it is functioning for me using a GraphpliQL interface that I am using through Prismic.
{
person
}
Upvotes: 0
Reputation: 706
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...
}
}
Upvotes: 4