Example project to demonstrate GraphQL codegen in a Ruby project.
Commands are defined in the Justfile and can be listed with just.
just graphql
The first step retrieves the GraphQL schema from the Peak Tracker backend and saves it in graphql.schema.json.
The main magic happens in graphql-codegen-peak-tracker.js which generates graphql_peak_tracker.rb. The generated Ruby classes are then used in the graphql folder for the GraphQL schema.
The Ruby query class of this project just defines one field:
field(
:peaks,
PeakTracker::Types::PeakConnection,
null: false,
description: PeakTracker::Types::PeakConnection.description
) do
PeakTracker::Types::Arguments.define_arguments(self, :ROOT_QUERY_TYPE, :peaks, %i[filter scaled_by_actor sort])
endBut the resulting GraphQL schema contains all arguments and sub-fields from the original schema.