Skip to content

Instantly share code, notes, and snippets.

@ewalk153
Last active June 27, 2024 01:30
Show Gist options
  • Save ewalk153/4c4e11808736014edad0c3b4c790c7aa to your computer and use it in GitHub Desktop.
Save ewalk153/4c4e11808736014edad0c3b4c790c7aa to your computer and use it in GitHub Desktop.
fast create rails graphql API

Setup instructions

rails new demo-rails-gql --api
bundle add graphql
rails generate graphql:install
rails g model product title description options
rails g model variant title option1 option2 option3 sku product:references
rails db:migrate
rails g graphql:object product
rails g graphql:object variant
rails g graphql:input product
rails g graphql:mutation_create product

Resources

bundle add graphiql-rails
bundle add sprockets-rails
mkdir -p app/assets/config
printf "//= link graphiql/rails/application.css\n//= link graphiql/rails/application.js" > app/assets/config/manifest.js
# add graphiql to routes.
# add to class QueryType < Types::BaseObject
field :product, Types::ProductType, null: false do
argument :id, ID, required: true, description: "ID of the object."
end
def product(id:)
Product.find(id)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment