Skip to main content

GraphQL Introspection parsing and query generation

Project description

GQLSpection

CLI tool and Python 2.7+ compatible library for parsing GraphQL introspection query and automatic query generation.

License Python Versions Jython Version

Main branch Dev branch Coverage

Installation

GQLSpection is available on PyPI (Python 2.7 and Python 3+ versions are supported).

Regular installation:

$ pip install gqlspection[cli]

Usage of the CLI tool

Load schema from file and print all query and mutation names in the schema:

$ gqlspection -f schema.json -l all

Send introspection query and generate queries & mutations for everything:

$ gqlspection -u https://.../graphql

Generate a single query:

$ gqlspection -u https://.../graphql -q something

Generate a number of mutations:

$ gqlspection -f schema.json -m one,two,three

Full help

$ ./gqlspection -h
Usage: gqlspection [OPTIONS]

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).

  -h, --help           Show this message and exit.

Usage of the Python library

Import the library:

>>> from gqlspection import GQLSchema

Send 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).str())

Contributing

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 install

Using runme

Install 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gqlspection-0.2.1.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gqlspection-0.2.1-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file gqlspection-0.2.1.tar.gz.

File metadata

  • Download URL: gqlspection-0.2.1.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for gqlspection-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5f2439d7fdd608a3745c214f515adeec00659b1d2c4bd22f51d613c6e053c795
MD5 4913c58919afc5b8d8279d9d47c04017
BLAKE2b-256 9d7fe56dae148673583574f5c08f184686c330d36048f74483955ef07a3d631d

See more details on using hashes here.

File details

Details for the file gqlspection-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: gqlspection-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for gqlspection-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b5317213cdf4352b9bb658a929fb585468a3482bd768d5f994852a5c071260
MD5 d62111e7cfb9274e478faef169fa585c
BLAKE2b-256 df0d9a9a93692f9dce00c917ee66056740c3ab2a3873bd820d1fc17ef990c53d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page