# GQLSpection
CLI tool and Python 2.7+ compatible library for parsing GraphQL introspection query and automatic query generation.
![License](https://img.shields.io/github/license/doyensec/gqlspection?style=for-the-badge)
![Python Versions](https://img.shields.io/pypi/pyversions/gqlspection?style=for-the-badge)
![Jython Version](https://img.shields.io/badge/Jython%20%28lib%20only%29-2.7.3-success?style=for-the-badge)
![Main branch](https://img.shields.io/github/actions/workflow/status/doyensec/gqlspection/Release.yml?style=for-the-badge&label=main%20branch)
![Dev branch](https://img.shields.io/github/actions/workflow/status/doyensec/gqlspection/QA.yml?branch=dev&style=for-the-badge&label=dev%20branch)
![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/doyensec/GQLSpection/coverage-badge/coverage.json&style=for-the-badge)
## Installation
GQLSpection is available on PyPI (Python 2.7 and Python 3+ versions are supported).
Regular installation:
```bash
$ pip install gqlspection[cli]
```
## Usage of the CLI tool
Load schema from file and print all query and mutation names in the schema:
```bash
$ gqlspection -f schema.json -l all
```
Send introspection query and generate queries & mutations for everything:
```bash
$ gqlspection -u https://.../graphql
```
Generate a single query:
```bash
$ gqlspection -u https://.../graphql -q something
```
Generate a number of mutations:
```bash
$ 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:
```python
>>> from gqlspection import GQLSchema
```
Send introspection query and print a single query:
```python
>>> 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:
```python
>>> 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:
```bash
$ 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:
```commandline
$ 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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/doyensec/gqlspection",
"name": "gqlspection",
"maintainer": "",
"docs_url": null,
"requires_python": ">=2.7",
"maintainer_email": "",
"keywords": "graphql,introspection",
"author": "Andrew Konstantinov",
"author_email": "andrew@doyensec.com",
"download_url": "https://files.pythonhosted.org/packages/95/08/b8b3cafed7d3d80befc8e57038ddb1445d0b34907b43c897d2a900c6e4fb/gqlspection-0.2.3.tar.gz",
"platform": null,
"description": "# GQLSpection\n\nCLI tool and Python 2.7+ compatible library for parsing GraphQL introspection query and automatic query generation.\n\n![License](https://img.shields.io/github/license/doyensec/gqlspection?style=for-the-badge)\n![Python Versions](https://img.shields.io/pypi/pyversions/gqlspection?style=for-the-badge)\n![Jython Version](https://img.shields.io/badge/Jython%20%28lib%20only%29-2.7.3-success?style=for-the-badge)\n\n\n![Main branch](https://img.shields.io/github/actions/workflow/status/doyensec/gqlspection/Release.yml?style=for-the-badge&label=main%20branch)\n![Dev branch](https://img.shields.io/github/actions/workflow/status/doyensec/gqlspection/QA.yml?branch=dev&style=for-the-badge&label=dev%20branch)\n![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/doyensec/GQLSpection/coverage-badge/coverage.json&style=for-the-badge)\n\n## Installation\n\nGQLSpection is available on PyPI (Python 2.7 and Python 3+ versions are supported).\n\nRegular installation:\n\n```bash\n$ pip install gqlspection[cli]\n```\n\n## Usage of the CLI tool\n\nLoad schema from file and print all query and mutation names in the schema:\n\n```bash\n$ gqlspection -f schema.json -l all\n```\n\nSend introspection query and generate queries & mutations for everything:\n\n```bash\n$ gqlspection -u https://.../graphql\n```\n\nGenerate a single query:\n\n```bash\n$ gqlspection -u https://.../graphql -q something\n```\n\nGenerate a number of mutations:\n\n```bash\n$ gqlspection -f schema.json -m one,two,three\n```\n\n### Full help\n\n```\n$ ./gqlspection -h\nUsage: gqlspection [OPTIONS]\n\nOptions:\n -f, --file TEXT File with the GraphQL schema (introspection JSON).\n -u, --url TEXT URL of the GraphQL endpoint with enabled introspection.\n\n -l, --list TEXT Parse GraphQL schema and list queries, mutations or\n both of them (valid values are: 'queries', 'mutations'\n or 'all').\n\n -q, --query TEXT Only print named queries (argument is a comma-separated\n list of query names).\n\n -m, --mutation TEXT Only print named mutations (argument is a comma-\n separated list of mutation names).\n\n -Q, --all-queries Only print queries (by default both queries and\n mutations are printed).\n\n -M, --all-mutations Only print mutations (by default both queries and\n mutations are printed).\n\n -h, --help Show this message and exit.\n```\n\n## Usage of the Python library\n\nImport the library:\n\n```python\n>>> from gqlspection import GQLSchema\n```\n\nSend introspection query and print a single query:\n\n```python\n>>> schema = GQLSchema(url='https://.../graphql')\n>>> query = schema.generate_query('SOME_TYPE')\n>>> print(query.str)\n```\n\nParse introspection schema from a JSON file and print all mutations:\n\n```python\n>>> from pathlib import Path\n>>> import json\n>>> data = json.loads(Path(FILE_NAME).read_text())\n>>> schema = GQLSchema(json=data)\n>>> for field in schema.mutation.fields:\n>>> print(schema.generate_mutation(field).str())\n```\n\n## Contributing\n\nInstallation with development dependencies from git repo:\n\n```bash\n$ git clone https://github.com/doyensec/GQLSpection.git\n$ cd GQLSpection\n$ virtualenv venv\n$ . ./venv/bin/activate\n$ pip install -e \".[dev]\"\n$ # Only needed in ZSH to locate newly added binaries:\n$ rehash\n$ pre-commit install\n```\n\n### Using runme\n\nInstall `runme` from https://github.com/sigoden/runme (through `cargo install --force runme` or by grabbing a binary\nrelease). Get a list of preinstalled development commands by running `runme` in the source dir:\n\n```commandline\n$ runme\nUSAGE: Runmefile.sh <COMMAND>\n\nCOMMANDS:\n deps Install development dependencies\n test Run tests\n jython.install Install Jython to jython/\n jython.clean Cleanup after Jython\n jython.test Run tests to check Jython compatibility [aliases: jython]\n lint Run linters\n clean Cleanup bytecode and cache files\n coverage.calculate Run pytest with coverage calculation [aliases: coverage]\n coverage.github_action Generate comment body with coverage for Github Action\n build Build the python release (files go to dist/)\n publish.pypi Publish release to PyPI\n publish.github Publish release to Github\n release Make a new release\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "GraphQL Introspection parsing and query generation",
"version": "0.2.3",
"split_keywords": [
"graphql",
"introspection"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c335eaa607660d4d23796dfe446ff667d3a2bf85489449bdd88aac99f76b6788",
"md5": "8c458732c51708e6f0fc8b1b2a7d7a80",
"sha256": "3b4fbad4d6e349888c57f8187aa71d2c71eb703cd25315613341999266d9eb72"
},
"downloads": -1,
"filename": "gqlspection-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8c458732c51708e6f0fc8b1b2a7d7a80",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=2.7",
"size": 23045,
"upload_time": "2023-01-22T15:47:43",
"upload_time_iso_8601": "2023-01-22T15:47:43.290766Z",
"url": "https://files.pythonhosted.org/packages/c3/35/eaa607660d4d23796dfe446ff667d3a2bf85489449bdd88aac99f76b6788/gqlspection-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9508b8b3cafed7d3d80befc8e57038ddb1445d0b34907b43c897d2a900c6e4fb",
"md5": "23780820fee5c7afe982b79e2d53081a",
"sha256": "d10f5bc20c35180735996c4a04f5204e2b411ade0c6df71b1852607e1400ca30"
},
"downloads": -1,
"filename": "gqlspection-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "23780820fee5c7afe982b79e2d53081a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7",
"size": 28488,
"upload_time": "2023-01-22T15:47:44",
"upload_time_iso_8601": "2023-01-22T15:47:44.416368Z",
"url": "https://files.pythonhosted.org/packages/95/08/b8b3cafed7d3d80befc8e57038ddb1445d0b34907b43c897d2a900c6e4fb/gqlspection-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-22 15:47:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "doyensec",
"github_project": "gqlspection",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "gqlspection"
}