Tool to Autogenerate Apollo Queries


I find myself just rewriting the same queries over and over again by just copying what’s on the playground, has anyone made a tool or will graphql make a tool which just exports a JS file based on your graphcool schema which has all the graphQL queries from the playground already setup?


We already have the Generate Code button in the playground. This currently only works for Lokka and Fetch, but we should definitely add support for Apollo and Relay.

Do you think that approach would be helpful, or is there something else you have in mind?


Oh yeah that sounds like a great start. I was thinking of a file that exported all of your mutations at once using gql, etc. so they can be easily imported.


Not all mutations change all fields of the type they are mutating or need to return the same set of data.

I guess this kind of thing could work if it exported a generator function rather than a hardcoded mutation, including fields in the mutation based on what variables it is passed, perhaps with some options for what data should be returned.


yeah what I usually do is I just list all the fields but make them optional so I’m only using what I pass in. A function that lets you specify what data is returned would be great though.


yeah we need it. need generate code for apollo.


Here’s another interesting approach for generating GraphQL queries:


I created code that does an introspection query and then builds queries and mutations with a recursive function, that traverses the nodes from the introspection data.

It took me a day or two to figure out, but it’s much faster than writing out queries and mutations for the app since there are hundreds.