Skip to content

Instantly share code, notes, and snippets.

@grantspeelman
Last active December 6, 2021 23:23
Show Gist options
  • Save grantspeelman/cfcb8553a47c3d2a0bf55ac2f2358c9a to your computer and use it in GitHub Desktop.
Save grantspeelman/cfcb8553a47c3d2a0bf55ac2f2358c9a to your computer and use it in GitHub Desktop.
Rake tasks to dump ruby graphql for use with graphql code generators
namespace :graphql do
def write_update_file(filename, content)
return puts("-- #{filename}") if File.exist?(filename) && File.read(filename) == content
puts "Updating #{filename}"
File.open(filename, 'w') { |file| file << content }
end
task dump_schema: :environment do
system 'mkdir -p tmp/graphql'
file_name = Rails.root.join('tmp/graphql/schema.gql')
write_update_file(file_name, GraphQL::Schema::Printer.print_schema(YourSchema))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment