GraphQL on Jets

I’m setting up a GraphQL API using jets and I would like to serve an instance of the GraphQL Playground at ‘/graphql-playground’

I’ve found this repository https://github.com/betaflag/graphql-playground-ruby but I have no idea how to translate the README instructions to jets routes syntax

# config/routes.rb
mount GraphQLPlayground, at: '/graphql-playground', endpoint: '/graphql'

I get the error ArgumentError: unknown keyword: endpoint I’m not sure what syntax to use in order to pass the endpoint value to the GraphQLPlayground app

I figured out the solution if anyone else runs into this issue. I needed to create a new instance of the GraphQLPlayground Rack Class and pass the endpoint argument to the initializer like this

# config/routes.rb
mount GraphQLPlayground.new(endpoint: '/graphql'), at: '/graphql-playground'
1 Like

YAS! Just wanted to say thanks a bunch for this. I’ve been digging into GraphQL and, more so, getting GraphQL up and running with RoJ but have been running into some hurdles - mostly just because I’m a GraphQL newb at the moment. This was one that I was hoping could improve my development and learning experience. I struggled with graphiql-rails primarily because of it’s tight coupling with Rails so this was a win. Thanks so much for posting and sharing your solution :slight_smile:

I don’t believe it will matter much once it’s deployed to AWS (unless Jets internals account for route “Mounting” somehow) but just to be safe I made sure to only enable graphql-playground in development with the following code in my routes.rb file.

if Jets.env.development?
  mount GraphQLPlayground.new(endpoint: '/graphql'), at: '/graphql-playground'  
end
1 Like