{"id":13879749,"url":"https://github.com/exAspArk/graphql-errors","last_synced_at":"2025-07-16T15:33:00.461Z","repository":{"id":56875192,"uuid":"101773790","full_name":"exAspArk/graphql-errors","owner":"exAspArk","description":"Simple error handler for GraphQL Ruby :exclamation:","archived":true,"fork":false,"pushed_at":"2020-04-07T20:39:27.000Z","size":61,"stargazers_count":168,"open_issues_count":0,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-15T12:07:41.034Z","etag":null,"topics":["error","error-handling","exception-handling","graphql","graphql-ruby","ruby"],"latest_commit_sha":null,"homepage":"","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/exAspArk.png","metadata":{"files":{"readme":"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}},"created_at":"2017-08-29T14:58:45.000Z","updated_at":"2024-10-31T02:02:51.000Z","dependencies_parsed_at":"2022-08-20T22:00:41.113Z","dependency_job_id":null,"html_url":"https://github.com/exAspArk/graphql-errors","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exAspArk%2Fgraphql-errors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exAspArk%2Fgraphql-errors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exAspArk%2Fgraphql-errors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exAspArk%2Fgraphql-errors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exAspArk","download_url":"https://codeload.github.com/exAspArk/graphql-errors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226143895,"owners_count":17580245,"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":["error","error-handling","exception-handling","graphql","graphql-ruby","ruby"],"created_at":"2024-08-06T08:02:31.458Z","updated_at":"2024-11-24T08:31:44.461Z","avatar_url":"https://github.com/exAspArk.png","language":"Ruby","readme":"# graphql-errors\n\n:warning: This gem is **deprecated** in favor of the new `GraphQL::Execution::Errors` in the `graphql` gem. See more details [rmosolgo/graphql-ruby#2458](https://github.com/rmosolgo/graphql-ruby/pull/2458).\n\n---\n\n[![Build Status](https://travis-ci.org/exAspArk/graphql-errors.svg?branch=master)](https://travis-ci.org/exAspArk/graphql-errors)\n[![Coverage Status](https://coveralls.io/repos/github/exAspArk/graphql-errors/badge.svg?branch=master)](https://coveralls.io/github/exAspArk/graphql-errors?branch=master)\n[![Downloads](https://img.shields.io/gem/dt/graphql-errors.svg)](https://rubygems.org/gems/graphql-errors)\n[![Latest Version](https://img.shields.io/gem/v/graphql-errors.svg)](https://rubygems.org/gems/graphql-errors)\n\nThis gem provides a simple error handling for [graphql-ruby](https://github.com/rmosolgo/graphql-ruby).\n\n## Highlights\n\n* Error handling for each field.\n* Logic inside the `rescue_from` block, similarly to Rails.\n* Catching exceptions by ancestors, e.g. `CustomError` with `rescue_from StandardError`.\n* Per schema configuration.\n* No dependencies.\n\n## Usage\n\nOnce you defined your GraphQL schema:\n\n```ruby\nSchema = GraphQL::Schema.define do\n  query QueryType\nend\n```\n\nYou can add `rescue_from` error handlers with `GraphQL::Errors`. For example:\n\n```ruby\nGraphQL::Errors.configure(Schema) do\n  rescue_from ActiveRecord::RecordNotFound do |exception|\n    nil\n  end\n\n  rescue_from ActiveRecord::RecordInvalid do |exception|\n    GraphQL::ExecutionError.new(exception.record.errors.full_messages.join(\"\\n\"))\n  end\n\n  # uses Module to handle several similar errors with single rescue_from\n  rescue_from MyNetworkErrors do |_|\n    GraphQL::ExecutionError.new(\"Don't mind, just retry the mutation\")\n  end\n\n  rescue_from StandardError do |exception|\n    GraphQL::ExecutionError.new(\"Please try to execute the query for this field later\")\n  end\n\n  rescue_from CustomError do |exception, object, arguments, context|\n    error = GraphQL::ExecutionError.new(\"Error found!\")\n    firstError.path = context.path + [\"myError\"]\n    context.add_error(firstError)\n  end\nend\n```\n\nIt'll handle exceptions raised from each resolver in the schema:\n\n```ruby\nQueryType = GraphQL::ObjectType.define do\n  name \"Query\"\n\n  field :post, PostType do\n    argument :id, !types.ID\n    resolve -\u003e(obj, args, ctx) { Post.find(args['id']) } # \u003c= will raise ActiveRecord::RecordNotFound\n  end\nend\n\nSchema.execute('query { post(id: \"1\") { title } }') # handles the error without failing the whole query\n# =\u003e { data: { post: nil } }\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'graphql-errors'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install graphql-errors\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/exAspArk/graphql-errors. 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](http://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Graphql::Errors project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/exAspArk/graphql-errors/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FexAspArk%2Fgraphql-errors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FexAspArk%2Fgraphql-errors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FexAspArk%2Fgraphql-errors/lists"}