{"id":23082472,"url":"https://github.com/apartmenttherapy/grapher","last_synced_at":"2025-08-16T00:31:27.671Z","repository":{"id":57503153,"uuid":"112252725","full_name":"apartmenttherapy/grapher","owner":"apartmenttherapy","description":"Elixir GraphQL Client","archived":true,"fork":false,"pushed_at":"2018-08-27T22:09:51.000Z","size":65,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-22T20:02:39.091Z","etag":null,"topics":["elixir","graphql-client"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apartmenttherapy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-27T21:50:52.000Z","updated_at":"2025-01-31T14:50:37.000Z","dependencies_parsed_at":"2022-08-31T08:02:03.468Z","dependency_job_id":null,"html_url":"https://github.com/apartmenttherapy/grapher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/apartmenttherapy/grapher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apartmenttherapy%2Fgrapher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apartmenttherapy%2Fgrapher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apartmenttherapy%2Fgrapher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apartmenttherapy%2Fgrapher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apartmenttherapy","download_url":"https://codeload.github.com/apartmenttherapy/grapher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apartmenttherapy%2Fgrapher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270651054,"owners_count":24622436,"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","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["elixir","graphql-client"],"created_at":"2024-12-16T14:52:49.957Z","updated_at":"2025-08-16T00:31:27.385Z","avatar_url":"https://github.com/apartmenttherapy.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grapher\n\n[![Coverage Status](https://coveralls.io/repos/github/apartmenttherapy/grapher/badge.svg?branch=master)](https://coveralls.io/github/apartmenttherapy/grapher?branch=master)\n\nGrapher is a GraphQL Client for Elixir.  It allows you to manage multiple \"schemas\" as well as providing for a simple Document storage.\n\nGrapher is probably better suited for use in an application that needs to consume one or more GraphQL APIs than it is for quick discovery/exploration of an API.  Although nothing prevents you from using it to run queries from an `iex` session.\n\n## Installation\n\n[Available in Hex](https://hex.pm/packages/grapher), the package can be installed\nby adding `grapher` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:grapher, \"~\u003e 0.9.0\"}\n  ]\nend\n```\n\n## Usage\n\nThere are three main steps to executing a Query or Mutation with Grapher:\n\n1. Registering a Context for the requests\n2. Registering one or more Documents to use in requests\n3. Executing a Document against a Schema\n\n### Context Registration\n\nGrapher uses what it calls a `SchemaContext` to identify where a Schema lives and any headers that should be used in requests.  There is nothing preventing the definition of multiple contexts for the same schema, you just need to give each context a unique name.\n\n```elixir\niex\u003e context = SchemaContext.new(\"http://www.example.com/graphql\", [\"Authentication\": \"bearer 88\"])\niex\u003e Grapher.SchemaContext.Store.add_context(:example, context)\n:ok\n```\n\nOnce a Context has been registered it can be retireved and/or updated\n\n```elixir\niex\u003e Grapher.SchemaContext.Store.get(:example)\n%SchemaContext{url: \"http://www.example.com/graphql\", headers: [\"Authentication\": \"bearer 88\"]}\n\niex\u003e new_context = SchemaContext.new(\"http://axiom.atmedia.xyz/graphql\")\niex\u003e Grapher.SchemaContext.Store.update_context(:example, new_context)\n:ok\n```\n\n### Document Registration\n\nA Document in Grapher is nothing more than the literal query document and a function to be used to translate it to an acceptable payload.  Currently the only supported transport layer is HTTP.\n\n```elixir\niex\u003e doc = Document.new(\"query { allListings { id } }\", :query)\n%Document{document: \"query { allListings { id } }\", transport_formatter: \u0026Request.query/2}\n```\n\nIn order to use a document you currently need to put it into the store first.\n\n```elixir\niex\u003e Grapher.Document.Store.add_document(:listings, doc)\n:ok\n```\n\nOnce you have stored a query you can always update it\n\n```elixir\niex\u003e Grapher.Document.Store.update_document(:listings, doc)\n:ok\n```\n\n### Document Execution\n\nOnce you have one or more contexts and one or more documents you can start executing documents in a given context.\n\n```elixir\niex\u003e Grapher.Executor.run(:listings, :example)\n%Grapher.GraphQL.Response{data: %{allListings: [%{id: 8}, %{id: 9}]}, errors: :empty, status_code: 200, transport_error: :empty}\n```\n\nIf your document allows for variables you can always add them when you run it\n\n```elixir\niex\u003e doc = Document.new(\"query user($userId: ID!){ user(userId: $userID) { name } }\", :query)\niex\u003e Grapher.Document.Store.add_document(:flexible, doc)\niex\u003e Grapher.Executor.run(:flexible, :example, %{userId: \"bob\"})\n%Grapher.GraphQL.Response{data: %{user: %{name: \"Bob Jones\"}}, errors: :empty, status_code: 200, transport_error: :empty}\n```\n\n### Loading Context and Document data at application start\n\nIf you want to have your default documents and contexts ready and waiting when your application starts up you just need to add a module to your application which implements the `Grapher.SetupBehaviour` and then set the `:setup_module` config value for `grapher`\n\n```elixir\nconfig :grapher,\n  setup_module: MySetupModule\n```\n\n### Saving/Sharing data between requests\n\nAt AT Media our Marketplace API really consists of three services, two of which live behind the main public API.  Unfortunately this complicates our logging process.  It is not easy to determine which service requests were spawned by a particular public API request.  For this reason we have introduced a new Context which is scoped to the life of a process.\n\nTo start tracking/sharing data with calls from the current thread simply initialize a `Grapher.Context` struct with the data you wish to share across requests:\n\n```\niex\u003e context = Grapher.Context.new(headers: [\"request-id\": \"38bdkhg348thgdk\"])\niex\u003e State.update(context)\n:ok\n```\n\nWhenever you execute a call with `grapher` it will check for a context belonging to the current process (`pid`) and merge the data in the context with any data provided to the query.\n\n*NOTE*: Each call to `State.update/1` will replace any saved context with the context provided.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapartmenttherapy%2Fgrapher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapartmenttherapy%2Fgrapher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapartmenttherapy%2Fgrapher/lists"}