
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
GraphQL Analyzer is a GraphQL extension for tracking datastore queries.
Add this line to your application's Gemfile:
gem 'graphql-analyzer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install graphql-analyzer
Add an instance of GraphQL::Analyzer to your schema, instantiate it with a list of instrumentations to capture different datastore queries.
Add 'GraphQL::Analyzer' to your schema:
require 'graphql/analyzer'
Schema = GraphQL::Schema.define do
query QueryType
use(
GraphQL::Analyzer.new(
GraphQL::Analyzer::Instrumentation::Mysql.new,
GraphQL::Analyzer::Instrumentation::Postgresql.new
)
)
end
The GraphQL specification allows servers to include additional information as part of the response under an extensions
key:
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.
GraphQL Analyzer exposes datastore query data for an individual request under a analyzer
key in extensions
:
{
"data": <>,
"errors": <>,
"extensions": {
"analyzer": {
"version": 1,
"execution": {
"resolvers": [
{
"path": [
"node"
],
"adapter": "sqlite3",
"parentType": "Query",
"fieldName": "node",
"returnType": "Node",
"details": {
"root": "EXPLAIN for: SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = ? LIMIT ? [[\"id\", 7], [\"LIMIT\", 1]",
"explained_queries": [
{
"select_id": "0",
"order": "0",
"from": "0",
"details": "SEARCH TABLE users USING INTEGER PRIMARY KEY (rowid=?)"
}
]
}
}
]
}
}
}
}
There are some common instruments already implemented that should work right away.
Sqlite3
Mysql
Postgresql
Check lib/graphql/analyzer/instrumentation
for the full list.
To 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
.
module GraphQL
class Analyzer
module Instrumentation
class MyCustomInstrumentation < Base
def instrument(type, field)
->(obj, args, ctx) do
### OMITTED ###
ctx['graphql-analyzer']['resolvers'] << {
'adapter' => 'My Custom Adapter',
'path' => ctx.path,
'parentType' => type.name,
'fieldName' => field.name,
'returnType' => field.type.to_s,
'details' => 'My Adapter Specific Information'
}
### OMITTED ###
end
end
end
end
end
end
After 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.
Bug 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 code of conduct.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that graphql-analyzer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.