Dump Ruby GraphQL Backend for use with code generators

Grant Petersen-Speelman
NEXL Engineering
Published in
1 min readDec 7, 2021

This post will help you dump your Ruby GraphQL schema so that you can use it with a GraphQL code generator.

We have built our backend service using Ruby on Rails and GraphQL ruby. The frontend is a Single Page React Application using Typescript.

GraphQL allows your frontend to not only ask for what it needs and it also has a strict type system built in, allowing you to know upfront what the types will be in the GraphQL response. We wanted take advantage of this on our frontend along with typescript to add extra type safety to the system.

First step is you have to dump the GraphQL schema from your Ruby. You can do this with a little rake task like this:

Now you can dump your schema by running bin/rails graphql:dump_schema

Next step is to add codegen by following the codegen installation steps : https://www.graphql-code-generator.com/docs/getting-started/installation

In the codegen.yml you can refer to the schema that was dumped by your rake task `schema: “../tmp/graphql/schema.json”` and start writing your GraphQL with all the goodness of type safety.

--

--

Grant Petersen-Speelman
NEXL Engineering
0 Followers
Editor for

Head if Engineering at NEXL and inspired to build technology solutions using GraphQL, Ruby and Rails and Typescript