{"id":13879255,"url":"https://github.com/samesystem/graphql_rails","last_synced_at":"2025-10-08T18:11:18.070Z","repository":{"id":31474980,"uuid":"128008322","full_name":"samesystem/graphql_rails","owner":"samesystem","description":"GraphQL on Rails. Write GraphQL server side in rails way","archived":false,"fork":false,"pushed_at":"2024-10-09T06:38:43.000Z","size":577,"stargazers_count":153,"open_issues_count":8,"forks_count":12,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-10-29T17:13:24.274Z","etag":null,"topics":["graphql","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://samesystem.github.io/graphql_rails","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samesystem.png","metadata":{"files":{"readme":"docs/README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-04T04:47:59.000Z","updated_at":"2024-10-09T06:38:46.000Z","dependencies_parsed_at":"2024-03-27T08:32:43.638Z","dependency_job_id":"6349bfb6-71b8-44cf-a8d7-0a97b0fe6597","html_url":"https://github.com/samesystem/graphql_rails","commit_stats":{"total_commits":258,"total_committers":22,"mean_commits":"11.727272727272727","dds":0.3682170542635659,"last_synced_commit":"027cd3ff18d58aa984c881380d14d44b4f650766"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samesystem%2Fgraphql_rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samesystem%2Fgraphql_rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samesystem%2Fgraphql_rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samesystem%2Fgraphql_rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samesystem","download_url":"https://codeload.github.com/samesystem/graphql_rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694872,"owners_count":20980733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","ruby","ruby-on-rails"],"created_at":"2024-08-06T08:02:15.368Z","updated_at":"2025-10-08T18:11:13.033Z","avatar_url":"https://github.com/samesystem.png","language":"Ruby","readme":"# GraphqlRails\n\n![Build Status](https://github.com/samesystem/graphql_rails/workflows/Ruby/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/samesystem/graphql_rails/branch/master/graph/badge.svg)](https://codecov.io/gh/samesystem/graphql_rails)\n[![Documentation](https://readthedocs.org/projects/ansicolortags/badge/?version=latest)](https://samesystem.github.io/graphql_rails)\n\nRails style structure for GraphQL API.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'graphql_rails'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install graphql_rails\n\n## Getting started\n\nExecute:\n\n    $ bundle exec rails g graphql_rails:install\n\nThis will generate code which will let you start your graphql faster\n\n## Usage\n\n### Define GraphQL schema as RoR routes\n\n```ruby\n# config/graphql/routes.rb\nGraphqlRails::Router.draw do\n  # will create createUser, updateUser, destroyUser mutations and user, users queries.\n  # expects that UsersController class exist\n  resources :users\n\n  # if you want custom queries or mutation\n  query 'searchLogs', to: 'logs#search' # action is handled by LogsController#search\nend\n```\n\nSee [Routes docs](components/routes.md) for more info.\n\n### Define your Graphql model\n\n```ruby\n# app/models/user.rb\nclass User # works with any class including ActiveRecord\n  include GraphqlRails::Model\n\n  graphql do |c|\n    # most common attributes, like :id, :name, :title has default type, so you don't have to specify it (but you can!)\n    c.attribute(:id)\n\n    c.attribute(:email).type('String')\n    c.attribute(:surname).type('String')\n  end\nend\n```\n\nSee [Model docs](components/model.md) for more info.\n\n### Define controller\n\n```ruby\n# app/controllers/graphql/users_controller.rb\nclass Graphql::UsersController \u003c GraphqlApplicationController\n  model('User') # specify that all actions returns User by default\n\n  # DRUD actions description\n  action(:index).permit(id: 'ID!').returns_many\n  action(:show).permit(id: 'ID!').returns_single\n  action(:create).permit(email: 'String!').returns_single\n  action(:update).permit(id: 'ID!', email: 'String!').returns_single\n  action(:destroy).permit(id: 'ID!').returns_single\n\n  def index\n    User.all\n  end\n\n  def show\n    User.find(params[:id])\n  end\n  # ... code for create / update / destroy is skipped ...\nend\n```\n\nSee [Controller docs](components/controller.md) for more info.\n\n## Testing your GraphqlRails::Controller in RSpec\n\n### Setup\n\nAdd those lines in your `spec/spec_helper.rb` file\n\n```ruby\n# spec/spec_helper.rb\nrequire 'graphql_rails/rspec_controller_helpers'\n\nRSpec.configure do |config|\n  config.include(GraphqlRails::RSpecControllerHelpers, type: :graphql_controller)\n  # ... your other configuration ...\nend\n```\n\nSee [Testing docs](testing/testing.md) for more info.\n\n### Helper methods\n\nThere are 3 helper methods:\n\n* `mutation(:your_controller_action_name, params: {}, context: {})`. `params` and `context` are optional\n* `query(:your_controller_action_name, params: {}, context: {})`. `params` and `context` are optional\n* `response`. Response is set only after you call `mutation` or `query`\n\n### Test examples\n\n```ruby\nclass MyGraphqlController\n  action(:create_user).permit(:full_name, :email).returns(User)\n  action(:index).returns('String')\n\n  def index\n    \"Called from index: #{params[:message]}\"\n  end\n\n  def create_user\n    User.create!(params)\n  end\nend\n\nRSpec.describe MyGraphqlController, type: :graphql_controller do\n  describe '#index' do\n    it 'is successful' do\n      query(:index)\n      expect(response).to be_successful\n    end\n\n    it 'returns correct message' do\n      query(:index, params: { message: 'Hello world!' })\n      expect(response.result).to eq \"Called from index: Hello world!\"\n    end\n  end\n\n  describe '#create_user' do\n    context 'when bad email is given' do\n      it 'fails' do\n        mutation(:create_user, params { email: 'bad' })\n        expect(response).to be_failure\n      end\n\n      it 'contains errors' do\n        mutation(:create_user, params { email: 'bad' })\n        expect(response.errors).not_to be_empty\n      end\n    end\n  end\nend\n```\n\n### Integrating GraphqlRails with other tools\n\nIn order to make GraphqlRails work with tools such as lograge or sentry, you need to enable them. In Ruby on Rails, you can add initializer:\n\n```ruby\n# config/initializers/graphql_rails.rb\nGraphqlRails::Integrations.enable(:lograge, :sentry)\n```\n\nAt the moment, GraphqlRails supports following integrations:\n\n* lograge\n* sentry\n\nIf you need to build something custom, check [logging_and_monitoring documentation](logging_and_monitoring/logging_and_monitoring.md) for more details.\n\n## Detailed documentation\n\nCheck https://samesystem.github.io/graphql_rails for more details\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/samesystem/graphql_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the GraphqlRails project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/samesystem/graphql_rails/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamesystem%2Fgraphql_rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamesystem%2Fgraphql_rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamesystem%2Fgraphql_rails/lists"}