{"id":16487529,"url":"https://github.com/sikanhe/apollo-tracing-elixir","last_synced_at":"2025-04-05T21:08:44.468Z","repository":{"id":57478902,"uuid":"99018990","full_name":"sikanhe/apollo-tracing-elixir","owner":"sikanhe","description":"Apollo Tracing middleware for Absinthe","archived":false,"fork":false,"pushed_at":"2020-08-30T15:33:45.000Z","size":35,"stargazers_count":114,"open_issues_count":4,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-05-01T15:04:22.647Z","etag":null,"topics":["absinthe","absinthe-graphql","apollo","apollo-tracing","elixir","graphql","optics"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/sikanhe.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}},"created_at":"2017-08-01T15:57:29.000Z","updated_at":"2024-02-08T14:22:16.000Z","dependencies_parsed_at":"2022-09-17T04:31:40.030Z","dependency_job_id":null,"html_url":"https://github.com/sikanhe/apollo-tracing-elixir","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/sikanhe%2Fapollo-tracing-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Fapollo-tracing-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Fapollo-tracing-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Fapollo-tracing-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sikanhe","download_url":"https://codeload.github.com/sikanhe/apollo-tracing-elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399877,"owners_count":20932876,"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":["absinthe","absinthe-graphql","apollo","apollo-tracing","elixir","graphql","optics"],"created_at":"2024-10-11T13:35:08.829Z","updated_at":"2025-04-05T21:08:44.448Z","avatar_url":"https://github.com/sikanhe.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ApolloTracing (for Elixir)\n\nApolloTracing adds data to your GraphQL query response so that an Apollo Engine can provide insights into your [Absinthe](http://absinthe-graphql.org)-based GraphQL service.\n\n## Supported Apollo Features\n\n- [Performance Tracing](https://www.apollographql.com/docs/platform/performance/#traces)\n- [Response Caching](https://www.apollographql.com/docs/references/engine-proxy/#2-add-cache-hints-to-your-responses)\n\n## Installation\n\nAdd `:apollo_tracing` to your deps\n```elixir\ndef deps do\n  [\n    {:apollo_tracing, \"~\u003e 0.4.0\"}\n  ]\nend\n```\n\n## Usage\n\n### Register the Middlewares\n\n*ApolloTracing uses the Absinthe's middleware functionality to track field-level resolution times. In order to register our custom middleware, you have a few options:*\n\n**Add `use ApolloTracing` to your schema file:**\n\n```elixir\ndef MyApp.Schema do\n  use Absinthe.Schema\n  use ApolloTracing\nend\n```\n\n**If you have a custom middleware stack, add the apollo tracing middlewares to the beginning of your middleware stack:**\n\n```elixir\ndef middleware(middleware, _field, _object),\n  do: [ApolloTracing.Middleware.Tracing, ApolloTracing.Middleware.Caching] ++ [...your other middlewares]\n```\n\n**If you prefer to only add tracing to some fields, you can selectively add tracing information:**\n\n```elixir\nfield :selected_field, :string do\n  middleware ApolloTracing.Middleware # Has to be the first middleware\n  resolve fn _, _ -\u003e {:ok, \"this field is now added to be traced\"} end\nend\n```\n\n### Register the Pipeline\n\n*ApolloTracing currently requires you to use a custom Pipeline in order to register 'Phases' in the correct order during resolution. Phases are used for measuring overall query times as well as appending the custom data to the response (including cache hints).*\n\n**Specify the pipeline in your Absinthe.Plug endpoint:**\n\n```elixir\nforward \"/graphql\", Absinthe.Plug,\n  schema: MyApp.Schema,\n  pipeline: {ApolloTracing.Pipeline, :plug}\n```\n\n**If you have your own pipeline function, you can add the phases directly:**\n\n```elixir\ndef my_pipeline_creator(config, pipeline_opts) do\n  config.schema_mod\n  |\u003e Absinthe.Pipeline.for_document(pipeline_opts)\n  |\u003e add_my_phases() # w.e your custom phases are\n  |\u003e ApolloTracing.Pipeline.add_phases() # Add apollo at the end\nend\n```\n\n**When you want to just call run a query with tracing, but without going through a Plug endpoint:**\n\n```elixir\ndef custom_absinthe_runner(query, opts \\\\ []) do\n  pipeline = ApolloTracing.Pipeline.default(YourSchema, opts)\n  case Absinthe.Pipeline.run(query, pipeline) do\n    {:ok, %{result: result}, _} -\u003e {:ok, result}\n    {:error, err, _} -\u003e {:ok, err}\n  end\nend\n\n\"\"\"\n  query {\n    fielda\n    fieldb\n  }\n\"\"\"\n|\u003e custom_absinthe_runner()\n```\n\n### Add Cache Metadata\n\n**You can configure caching by adding metadata to your Absinthe objects:**\n\n```elixir\nobject :user do\n  meta :cache, max_age: 30\nend\n\n# or\n\nobject :user, meta: [cache: [max_age: 30]] do\n  # ...\nend\n```\n\n**To ensure that the object is not cached across users, you can mark it as private:**\n\n```elixir\nobject :user do\n  meta :cache, max_age: 30, scope: :private\nend\n```\n\nSee the [Apollo docs](https://www.apollographql.com/docs/apollo-server/features/caching/#defining-cache-hints) for more information about cache scope.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsikanhe%2Fapollo-tracing-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsikanhe%2Fapollo-tracing-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsikanhe%2Fapollo-tracing-elixir/lists"}