New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to generate schema.json #2501
Comments
See here https://graphql-ruby.org/api-doc/1.9.12/GraphQL/RakeTask Create a file
You can also customize the
I don't load the schema by name, because it needs the Rails environment and I didn't want to load the whole env just when the rake task was required. I also set a custom context with a dummy admin user, because of some masking that looks for this kind of user. |
I looked and looked and somehow missed this page in the docs. Thanks! |
I had to add the proc for I kind of wish the rake task was already loaded by the gem and ran with environment included. Generating a dump could be a lot more automatic. I had to dig around quite a bit. |
Thanks for the feedback, @jhirn ! I think automatic loading could be accomplished with a Railtie but I haven't had a chance to look into it. If you're interested in taking a try, I'd be happy to review a PR with that feature! |
Hey you’re a busy guy. Couldn’t be more satisfied with this library overall. It’s fantastic! Maybe spitting something out with the generator would be nice? It seems people’s needs are different and the schema class is app specific, so generating a working base in Thoughts? I’d be happy to take a swag at it if you agree with the approach. |
👍 to generator, love it! |
If anyone runs into the following error in the console:
Then you can just run the following and they should all return true: require 'rake/dsl_definition'
require 'rake'
require "graphql/rake_task" And if you are creating a custom rake task you can do something like: namespace :graphql do
task dump_schema: :environment do
require "graphql/rake_task"
GraphQL::RakeTask.new(
load_schema: ->(_task) {
require File.expand_path("../../app/graphql/api_schema", __dir__)
ApiSchema
},
directory: "./config"
)
Rake::Task["graphql:schema:idl"].invoke
end
end |
I've seen that there's a SchemaPrinter class. I also see that there are some rake tasks we can include.
However, I am unable to figure out exactly how to print a schema.json from the command line in a vanilla rails app. Are there any instructions for this?
The text was updated successfully, but these errors were encountered: