CLI tool and Python 2.7+ compatible library for parsing GraphQL introspection query and automatic query generation.
GQLSpection is available on PyPI (Python 2.7 and Python 3+ versions are supported).
Regular installation:
$ pip install gqlspection[cli]Load schema from file and print all query and mutation names in the schema:
$ gqlspection -f schema.json -l allSend introspection query and generate queries & mutations for everything:
$ gqlspection -u https://.../graphqlGenerate a single query:
$ gqlspection -u https://.../graphql -q somethingGenerate a number of mutations:
$ gqlspection -f schema.json -m one,two,threeUsage: gqlspection [OPTIONS]
CLI interface for GraphQL schema introspection tool.
Options:
-f, --file TEXT File with the GraphQL schema (introspection
JSON).
-u, --url TEXT URL of the GraphQL endpoint with enabled
introspection.
-l, --list TEXT Parse GraphQL schema and list queries, mutations
or both of them (valid values are: 'queries',
'mutations' or 'all').
-q, --query TEXT Only print named queries (argument is a comma-
separated list of query names).
-m, --mutation TEXT Only print named mutations (argument is a comma-
separated list of mutation names).
-Q, --all-queries Only print queries (by default both queries and
mutations are printed).
-M, --all-mutations Only print mutations (by default both queries and
mutations are printed).
-d, --depth INTEGER Query depth, limits recursion (default: 4).
-p, --poi Enable 'Points of Interest' reporting.
-P, --poi-categories TEXT A list of enabled PoI categories: auth,custom_sca
larsdatabase,debugging,deprecated,files,payment,p
ii,privileged
--poi-depth INTEGER How deep in the schema to look for PoI (default:
2).
-c, --cycles Enable cycle detection.
--cycles-depth INTEGER How deep in the schema to look for cycles
(default: 100).
-k, --keywords TEXT Custom keywords for 'Points of Interest'
reporting (comma-separated list).
-K, --keywords-file TEXT Custom keywords for 'Points of Interest'
reporting (read from a file).
-v, --verbose Enable verbose logging.
-g, --debug Enable debug logging.
-h, --help Show this message and exit.
Import the library:
>>> from gqlspection import GQLSchemaSend introspection query and print a single query:
>>> schema = GQLSchema(url='https://.../graphql')
>>> query = schema.generate_query('SOME_TYPE')
>>> print(query.str)Parse introspection schema from a JSON file and print all mutations:
>>> from pathlib import Path
>>> import json
>>> data = json.loads(Path(FILE_NAME).read_text())
>>> schema = GQLSchema(json=data)
>>> for field in schema.mutation.fields:
>>> print(schema.generate_mutation(field).to_string())Installation with development dependencies from git repo:
$ git clone https://github.com/doyensec/GQLSpection.git
$ cd GQLSpection
$ virtualenv venv
$ . ./venv/bin/activate
$ pip install -e ".[dev]"
$ # Only needed in ZSH to locate newly added binaries:
$ rehash
$ pre-commit installInstall runme from https://github.com/sigoden/runme (through cargo install --force runme or by grabbing a binary
release). Get a list of preinstalled development commands by running runme in the source dir:
$ runme
USAGE: Runmefile.sh <COMMAND>
COMMANDS:
deps Install development dependencies
test Run tests
jython.install Install Jython to jython/
jython.clean Cleanup after Jython
jython.test Run tests to check Jython compatibility [aliases: jython]
lint Run linters
clean Cleanup bytecode and cache files
coverage.calculate Run pytest with coverage calculation [aliases: coverage]
coverage.github_action Generate comment body with coverage for Github Action
build Build the python release (files go to dist/)
publish.pypi Publish release to PyPI
publish.github Publish release to Github
release Make a new release