Last active
December 6, 2021 23:23
-
-
Save grantspeelman/cfcb8553a47c3d2a0bf55ac2f2358c9a to your computer and use it in GitHub Desktop.
Rake tasks to dump ruby graphql for use with graphql code generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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