{"id":13879727,"url":"https://github.com/rzane/graphql-extras","last_synced_at":"2025-04-07T16:18:33.288Z","repository":{"id":44908731,"uuid":"193383482","full_name":"rzane/graphql-extras","owner":"rzane","description":"Custom scalars, file uploads, and testing tools for building GraphQL APIs in Ruby","archived":false,"fork":false,"pushed_at":"2025-03-21T23:39:07.000Z","size":88,"stargazers_count":22,"open_issues_count":4,"forks_count":7,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-31T14:13:10.670Z","etag":null,"topics":["activestorage","associations","date","datetime","files","graphql","rspec","ruby","upload"],"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/rzane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"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":"2019-06-23T18:42:41.000Z","updated_at":"2025-03-25T17:52:51.000Z","dependencies_parsed_at":"2025-02-16T06:11:18.681Z","dependency_job_id":"b5eeb9aa-4f65-44e9-b7b5-a8ff0ccd5ab9","html_url":"https://github.com/rzane/graphql-extras","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fgraphql-extras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fgraphql-extras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fgraphql-extras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Fgraphql-extras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rzane","download_url":"https://codeload.github.com/rzane/graphql-extras/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247685628,"owners_count":20979085,"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":["activestorage","associations","date","datetime","files","graphql","rspec","ruby","upload"],"created_at":"2024-08-06T08:02:30.470Z","updated_at":"2025-04-07T16:18:33.268Z","avatar_url":"https://github.com/rzane.png","language":"Ruby","readme":"\u003ch1 align=\"center\"\u003eGraphQL::Extras\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n![Build](https://github.com/rzane/graphql-extras/workflows/Build/badge.svg)\n![Version](https://img.shields.io/gem/v/graphql-extras)\n\n\u003c/div\u003e\n\nA collection of utilities for building GraphQL APIs.\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [GraphQL::Extras::Controller](#graphqlextrascontroller)\n  - [GraphQL::Extras::Preload](#graphqlextraspreload)\n  - [GraphQL::Extras::PreloadSource](#graphqlextraspreloadsource)\n  - [GraphQL::Extras::Types](#graphqlextrastypes)\n    - [Date](#date)\n    - [DateTime](#datetime)\n    - [Decimal](#decimal)\n    - [Upload](#upload)\n  - [GraphQL::Extras::Test](#graphqlextrastest)\n- [Development](#development)\n- [Contributing](#contributing)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'graphql-extras'\n```\n\nAnd then execute:\n\n    $ bundle\n\n## Usage\n\n### GraphQL::Extras::Controller\n\nThe [`graphql` gem](https://github.com/rmosolgo/graphql-ruby) will generate a controller for you with a bunch of boilerplate. This module will encapsulate that boilerplate:\n\n```ruby\nclass GraphqlController \u003c ApplicationController\n  include GraphQL::Extras::Controller\n\n  def execute\n    graphql(schema: MySchema, context: { current_user: current_user })\n  end\nend\n```\n\n### GraphQL::Extras::Preload\n\nThis allows you to preload associations before resolving fields.\n\n```ruby\nclass Schema \u003c GraphQL::Schema\n  use GraphQL::Dataloader\nend\n\nclass BaseField \u003c GraphQL::Schema::Field\n  prepend GraphQL::Extras::Preload\nend\n\nclass BaseObject \u003c GraphQL::Schema::Object\n  field_class BaseField\nend\n\nclass PostType \u003c BaseObject\n  field :author, AuthorType, preload: :author, null: false\n  field :author_posts, [PostType], preload: {author: :posts}, null: false\n  field :depends_on_author, Integer, preload: :author, null: false\n\n  def author_posts\n    object.author.posts\n  end\nend\n```\n\n### GraphQL::Extras::PreloadSource\n\nThis is a subclass of [`GraphQL::Dataloader::Source`](https://graphql-ruby.org/dataloader/overview.html) that performs eager loading of Active Record associations.\n\n```ruby\nloader = dataloader.with(GraphQL::Extras::PreloadSource, :blog)\nloader.load(Post.first)\nloader.load_many(Post.all)\n```\n\n### GraphQL::Extras::Types\n\nIn your base classes, you should include the `GraphQL::Extras::Types`.\n\n```ruby\nclass BaseObject \u003c GraphQL::Schema::Object\n  include GraphQL::Extras::Types\nend\n\nclass BaseInputObject \u003c GraphQL::Schema::InputObject\n  include GraphQL::Extras::Types\nend\n```\n\n#### Date\n\nThis scalar takes a `Date` and transmits it as a string, using ISO 8601 format.\n\n```ruby\nfield :birthday, Date, required: true\n```\n\n#### DateTime\n\nThis scalar takes a `DateTime` and transmits it as a string, using ISO 8601 format.\n\n```ruby\nfield :created_at, DateTime, required: true\n```\n\n_Note: This is just an alias for the `ISO8601DateTime` type that is included in the `graphql` gem._\n\n#### Decimal\n\nThis scalar takes a `BigDecimal` and transmits it as a string.\n\n```ruby\nfield :weight, BigDecimal, required: true\n```\n\n#### Upload\n\nThis scalar is used for accepting file uploads.\n\n```ruby\nfield :image, Upload, required: true\n```\n\nIt achieves this by passing in all file upload parameters through context. This will work out of the box if you're using `GraphQL::Extras::Controller`.\n\nHere's an example using CURL:\n\n    $ curl -X POST \\\n        -F query='mutation { uploadFile(image: \"image\") }' \\\n        -F image=@cats.png \\\n        localhost:3000/graphql\n\nTake note of the correspondence between the value `\"image\"` and the additional HTTP parameter called `-F image=@cats.png`.\n\nSee [apollo-link-upload](https://github.com/rzane/apollo-link-upload) for the client-side implementation.\n\n### GraphQL::Extras::Test\n\nThis module makes it really easy to test your schema.\n\nFirst, create a test schema:\n\n```ruby\n# spec/support/test_schema.rb\nrequire \"graphql/extras/test\"\n\nclass TestSchema \u003c GraphQL::Extras::Test::Schema\n  configure schema: Schema, queries: \"spec/**/*.graphql\"\nend\n```\n\nNow, you can run tests like so:\n\n```ruby\nrequire \"support/test_schema\"\n\nRSpec.describe \"hello\" do\n  let(:context) { { name: \"Ray\" } }\n  let(:schema)  { TestSchema.new(context) }\n\n  it \"allows easily executing queries\" do\n    query = schema.hello\n\n    expect(query).to be_successful\n    expect(query.data[\"hello\"]).to eq(\"world\")\n  end\n\n  it \"parses errors\" do\n    query = schema.kaboom\n\n    expect(query).not_to be_successful\n    expect(query.errors[0].message).to eq(\"Invalid\")\n    expect(query.errors[0].code).to eq(\"VALIDATION_ERROR\")\n  end\nend\n```\n\n## Development\n\nTo install dependencies:\n\n    $ bundle install\n\nTo run the test suite:\n\n    $ bundle exec rspec\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/rzane/graphql-extras.\n\n\n## License\n\nGraphQL::Extras is released under the [MIT License](MIT-LICENSE).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Fgraphql-extras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frzane%2Fgraphql-extras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Fgraphql-extras/lists"}