{"id":13879259,"url":"https://github.com/GraphQL-Query-Planner/graphql-analyzer","last_synced_at":"2025-07-16T15:31:52.763Z","repository":{"id":56875182,"uuid":"111833289","full_name":"GraphQL-Query-Planner/graphql-analyzer","owner":"GraphQL-Query-Planner","description":"A GraphQL extension for tracking datastore queries.","archived":false,"fork":false,"pushed_at":"2018-12-07T16:03:08.000Z","size":49,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-29T06:41:17.253Z","etag":null,"topics":["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/GraphQL-Query-Planner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-23T16:59:17.000Z","updated_at":"2020-11-04T10:56:30.000Z","dependencies_parsed_at":"2022-08-20T22:00:42.660Z","dependency_job_id":null,"html_url":"https://github.com/GraphQL-Query-Planner/graphql-analyzer","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/GraphQL-Query-Planner%2Fgraphql-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQL-Query-Planner%2Fgraphql-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQL-Query-Planner%2Fgraphql-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQL-Query-Planner%2Fgraphql-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GraphQL-Query-Planner","download_url":"https://codeload.github.com/GraphQL-Query-Planner/graphql-analyzer/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":["graphql","graphql-ruby","ruby"],"created_at":"2024-08-06T08:02:15.527Z","updated_at":"2024-11-24T08:31:08.884Z","avatar_url":"https://github.com/GraphQL-Query-Planner.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# GraphQL::Analyzer\n\n[![Build Status](https://travis-ci.org/GraphQL-Query-Planner/graphql-analyzer.svg?branch=master)](https://travis-ci.org/GraphQL-Query-Planner/graphql-analyzer)\n[![Gem Version](https://badge.fury.io/rb/graphql-analyzer.svg)](https://rubygems.org/gems/graphql-analyzer)\n\n\nGraphQL Analyzer is a [GraphQL](https://github.com/rmosolgo/graphql-ruby) extension for tracking datastore queries.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'graphql-analyzer'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install graphql-analyzer\n\n## Usage\n\nAdd an instance of GraphQL::Analyzer to your schema, instantiate it with a list of instrumentations to capture different datastore queries.\n\n### Analyzer\n\nAdd 'GraphQL::Analyzer' to your schema:\n\n```ruby\nrequire 'graphql/analyzer'\n\nSchema = GraphQL::Schema.define do\n  query QueryType\n  use(\n      GraphQL::Analyzer.new(\n        GraphQL::Analyzer::Instrumentation::Mysql.new,\n        GraphQL::Analyzer::Instrumentation::Postgresql.new\n      )\n  )\nend\n```\n\n### Response Format\n\nThe GraphQL specification allows servers to [include additional information as part of the response under an `extensions` key](https://facebook.github.io/graphql/#sec-Response-Format):\n\n\u003e The response map may also contain an entry with key `extensions`. This entry, if set, must have a map as its value. This entry is reserved for implementors to extend the protocol however they see fit, and hence there are no additional restrictions on its contents.\n\nGraphQL Analyzer exposes datastore query data for an individual request under a `analyzer` key in `extensions`:\n\n```json\n{\n  \"data\": \u003c\u003e,\n  \"errors\": \u003c\u003e,\n  \"extensions\": {\n    \"analyzer\": {\n      \"version\": 1,\n      \"execution\": {\n        \"resolvers\": [\n          {\n            \"path\": [\n              \"node\"\n            ],\n            \"adapter\": \"sqlite3\",\n            \"parentType\": \"Query\",\n            \"fieldName\": \"node\",\n            \"returnType\": \"Node\",\n            \"details\": {\n              \"root\": \"EXPLAIN for: SELECT  \\\"users\\\".* FROM \\\"users\\\" WHERE \\\"users\\\".\\\"id\\\" = ? LIMIT ? [[\\\"id\\\", 7], [\\\"LIMIT\\\", 1]\",\n              \"explained_queries\": [\n                {\n                  \"select_id\": \"0\",\n                  \"order\": \"0\",\n                  \"from\": \"0\",\n                  \"details\": \"SEARCH TABLE users USING INTEGER PRIMARY KEY (rowid=?)\"\n                }\n              ]\n            }\n          }\n        ]\n      }\n    }\n  }\n}\n```\n\n### Instrumentation\n\nThere are some common instruments already implemented that should work right away.\n\n- `Sqlite3`\n- `Mysql`\n- `Postgresql`\n\nCheck [`lib/graphql/analyzer/instrumentation`](https://github.com/GraphQL-Query-Planner/graphql-analyzer/tree/master/lib/graphql/analyzer/instrumentation) for the full list.\n\nTo write your own custom instrumentation, your object needs to respond to `#instrument(type, field)` and return a lambda that accepts three parameters, `object`, `arguments`, and `context`, and returns the original field value. It should also add any queries captured to the `context`.\n\n```ruby\nmodule GraphQL\n  class Analyzer\n    module Instrumentation\n      class MyCustomInstrumentation \u003c Base\n        def instrument(type, field)\n          -\u003e(obj, args, ctx) do\n            ### OMITTED ###\n              ctx['graphql-analyzer']['resolvers'] \u003c\u003c {\n                'adapter' =\u003e 'My Custom Adapter',\n                'path' =\u003e ctx.path,\n                'parentType' =\u003e type.name,\n                'fieldName' =\u003e field.name,\n                'returnType' =\u003e field.type.to_s,\n                'details' =\u003e 'My Adapter Specific Information'\n              }\n              ### OMITTED ###\n          end\n        end\n      end\n    end\n  end\nend\n```\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\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/GraphQL-Query-Planner/graphql-analyzer. 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](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGraphQL-Query-Planner%2Fgraphql-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGraphQL-Query-Planner%2Fgraphql-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGraphQL-Query-Planner%2Fgraphql-analyzer/lists"}