{"id":13879022,"url":"https://github.com/graphiti-api/graphiti_graphql","last_synced_at":"2025-04-09T00:30:30.472Z","repository":{"id":96214756,"uuid":"343186745","full_name":"graphiti-api/graphiti_graphql","owner":"graphiti-api","description":"GraphQL support for Graphiti","archived":false,"fork":false,"pushed_at":"2023-09-28T19:24:51.000Z","size":117,"stargazers_count":5,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T19:44:28.075Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graphiti-api.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-02-28T18:50:37.000Z","updated_at":"2022-04-25T14:22:30.000Z","dependencies_parsed_at":"2023-07-06T08:47:30.621Z","dependency_job_id":null,"html_url":"https://github.com/graphiti-api/graphiti_graphql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphiti-api%2Fgraphiti_graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphiti-api%2Fgraphiti_graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphiti-api%2Fgraphiti_graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphiti-api%2Fgraphiti_graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphiti-api","download_url":"https://codeload.github.com/graphiti-api/graphiti_graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247949640,"owners_count":21023360,"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":[],"created_at":"2024-08-06T08:02:07.160Z","updated_at":"2025-04-09T00:30:30.043Z","avatar_url":"https://github.com/graphiti-api.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# GraphitiGraphql\n\nGraphQL (and Apollo Federation) support for Graphiti. Serve traditional Rails JSON, JSON:API or GraphQL with the same codebase.\n\nCurrently read-only, but you can add your own Mutations [manually](#blending-with-graphql-ruby).\n\nPre-alpha. Stay tuned.\n\n## Setup\n\nAdd to your `Gemfile`:\n\n```rb\ngem 'graphiti', \"\u003e= 1.2.33\"\ngem \"graphiti_graphql\"\n```\n\nMount the engine:\n\n```ruby\n# config/routes.rb\nRails.application.routes.draw do\n  scope path: ApplicationResource.endpoint_namespace, defaults: { format: :jsonapi } do\n    # ... normal graphiti stuff ...\n\n    mount GraphitiGraphQL::Engine, at: \"/gql\"\n  end\nend\n```\n\nFor a default Graphiti app, you can now serve GraphQL by POSTing to `/api/v1/gql`.\n\nThat's it 🎉!\n\n#### GraphiQL\n\nYou can add the GraphiQL editor to the project via [graphiql-rails](https://github.com/rmosolgo/graphiql-rails) as normal, but to save you the time here are the steps to make it work when Rails is running in API-only mode:\n\nAdd to the Gemfile:\n\n```ruby\ngem \"graphiql-rails\"\ngem 'sprockets', '~\u003e 3' # https://github.com/rmosolgo/graphiql-rails/issues/53\n```\n\nAnd then in `config/application.rb`:\n\n```ruby\n# *Uncomment* this line!\n# require \"sprockets/railtie\"\n```\n\nAlternatively, follow [this comment](https://github.com/rmosolgo/graphiql-rails/issues/53#issuecomment-877819958).\n\n## Usage\n\n#### Blending with graphql-ruby\n\nDefine your Schema and Type classes as normal. Then in an initializer:\n\n```ruby\n# config/initializers/graphiti.rb\nGraphitiGraphQL.schema_class = MySchema\n```\n\nAny pre-existing GraphQL endpoint will continue working as normal. But the GQL endpoint you mounted in `config/routes.rb` will now serve BOTH your low-level `graphql-ruby` schema AND your Graphiti-specific schema. Note these cannot (currently) be served side-by-side under `query` within the *same request*.\n\nBy default the GraphQL context will be `Graphiti.context[:object]`, which is the controller being called. You might want to customize this so your existing graphql-ruby code continues to expect the same context:\n\n```ruby\nGraphitiGraphQL.define_context do |controller|\n  { current_user: controller.current_user }\nend\n```\n\n#### Adding Federation Support\n\nAdd to the Gemfile\n\n```ruby\ngem \"apollo-federation\"\ngem \"graphql-batch\"\n```\n\nAnd change the way we require `graphiti_graphql`:\n\n```ruby\ngem \"graphiti_graphql\", require: \"graphiti_graphql/federation\"\n```\n\nTo create a federated relationship:\n\n```ruby\n# PositionResource\nfederated_belongs_to :employee\n```\n\nOr pass `type` and/or `foreign_key` to customize:\n\n```ruby\n# type here is the GraphQL Type\nfederated_belongs_to :employee, type: \"MyEmployee\", foreign_key: :emp_id\n```\n\nFor `has_many` it's a slightly different syntax because we're adding the relationship to the ***remote*** type:\n\n```ruby\nfederated_type(\"Employee\").has_many :positions # foreign_key: optional\n```\n\nFinally, `has_many` accepts the traditional `params` block that works as normal:\n\n```ruby\nfederated_type(\"Employee\").has_many :positions do\n  params do |hash|\n    hash[:filter][:active] = true\n    hash[:sort] = \"-title\"\n  end\nend\n```\n\nRemember that any time you make a change that affects the schema, you will have to bounce your federation gateway. This is how Apollo Federation works when not in \"managed\" mode and is unrelated to `graphiti_graphql`.\n\n## Configuration\n\n#### Entrypoints\n\nBy default all Graphiti resources will expose their `index` and `show` functionality. IOW `EmployeeResource` now serves a list at `Query#employees` and a single employee at `Query#employee(id: 123)`. To limit the entrypoints:\n\n```ruby\nGraphitiGraphQL::Schema.entrypoints = [\n  EmployeeResource\n]\n```\n\n#### Schema Reloading\n\nYou may want to automatically regenerate the GQL schema when when Rails reloads your classes, or you may not want to pay that performance penalty. To turn off the automatic reloading:\n\n```ruby\n# config/initializers/graphiti.rb\nGraphitiGraphQL.config.schema_reloading = false\n```\n\n#### `.graphql_entrypoint`\n\nIf the field you want on `Query` can't be inferred from the class name:\n\n```ruby\nclass EmployeeResource \u003c ApplicationResource\n  self.graphql_entrypoint = :workers\nend\n```\n\nYou can now\n\n```\nquery {\n  workers {\n    firstName\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphiti-api%2Fgraphiti_graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphiti-api%2Fgraphiti_graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphiti-api%2Fgraphiti_graphql/lists"}