Name | py-graphql-mapper JSON |
Version |
1.1.1
JSON |
| download |
home_page | https://github.com/dapalex/py-graphql-mapper/ |
Summary | A python library to call GraphQL APIs without using hardcoded strings |
upload_time | 2023-07-02 14:10:22 |
maintainer | |
docs_url | None |
author | Alex Dap |
requires_python | >=3.10 |
license | MIT License Copyright (c) 2022 dapalex Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
python
graphql
mapping
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![Python package](https://github.com/dapalex/py-graphql-mapper/actions/workflows/python-package.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/python-package.yml)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/280533e425784f7da9ecb0f6e529886b)](https://www.codacy.com/gh/dapalex/py-graphql-mapper/dashboard?utm_source=github.com&utm_medium=referral&utm_content=dapalex/py-graphql-mapper&utm_campaign=Badge_Grade)
--------------------------------------------------------------------------------
# py-graphql-mapper
[![Code Generation Test](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-codegen.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-codegen.yml)
[![Pyhon-GraphQL Mapping Test](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-map.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-map.yml)
A python library to interact with GraphQL APIs with no need of hardcoded strings.
## Introduction
This library acts as a mapper between python and GraphQL languages for GraphQL clients, allowing a code-first approach when calling a GraphQL API server.
It translates GraphQL entities into python objects and viceversa in order to avoid working with massive "copy&paste"s.
This document contains a quick overview of the functionalities, for more details and options you can read here:
* [Code Generation](https://github.com/dapalex/py-graphql-mapper/blob/develop/codegen/README.MD)
* [Core Mapper](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD)
* [Use Cases](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/README.MD)
The package does not use any third-party libraries, it relies only on python 3 (3.10+) standard libraries.
## Usage in a nutshell
### Installation
Available in PyPI, the following command will install the library:
```
pip install py-graphql-mapper
```
### Generate python code from schema
To generate the code execute the following command:
```
pgmcodegen generate ./pathToOutputFolder -apiArgs ./<pathToArgsFile>/generatorArgs.json
```
This command requires a json file containing the parameters needed to get the GraphQL schema
![image](https://github.com/dapalex/py-graphql-mapper/blob/develop/docs/cli_args_nutshell.png)
A sample is available in the main folder ['cli_args.json'](https://github.com/dapalex/py-graphql-mapper/blob/develop/cli_args.json).
The following python files will be generated:
* enums.py
* scalars.py
* gql_simple_types.py
* gql_types.py
* type_refs.py
* queries.py
* mutations.py
These links show code generated using the library [Github GraphQL API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/github), [Rapid GraphQL API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/rapidapi) and [GeoDBCities API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/gdbc)
More command options are available [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/codegen/README.MD#usage-via-command-line)
### Execution of a query
Choose the query class you want to use from the generated file queries.py (or a mutation from mutations.py):
Instantiate it adding GraphQL arguments if needed:
```python
from .output.gdbc.queries import currencies
my_currencies = currencies(last=7, before='MTE=')
```
or add them using the field _args_
```python
my_currencies._args.last = 7
my_currencies._args.before = 'MTE='
```
Then call _export_gql_source_ property to pass the payload to the HTTP request:
(example using _requests_ library)
```python
import requests
response = requests.request('POST', url='https://geodb-cities-graphql.p.rapidapi.com/',
json= { "query": my_currencies.export_gql_source },
headers={
"content-type": "application/json",
"X-RapidAPI-Key": '123402mmri02fni230iif32jr420',
"X-RapidAPI-Host": "geodb-cities-graphql.p.rapidapi.com"
}
)
```
More details on how to set a query [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD#creation-of-an-operation)
### Retrieval of a response
Obtained the response from the GraphQL API the following code will map the received json payload into the python object
```python
from pygqlmap.network import GQLResponse
gqlResponse = GQLResponse(response)
gqlResponse.map_gqldata_to_obj(myCurrenciesQuery.type)
print('Result object: ' + str(gqlResponse.result_obj))
```
The mapped response from the GraphQL server will be available within _gqlResponse_ object: `_gqlResponse.result_obj_`
More details [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD#parsing-of-a-response)
A suite of use cases [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/README.MD)
Raw data
{
"_id": null,
"home_page": "https://github.com/dapalex/py-graphql-mapper/",
"name": "py-graphql-mapper",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "python,graphql,mapping",
"author": "Alex Dap",
"author_email": "Alex Dap <shlisi2017@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a8/be/489db24db1385c136a3c2b77e952c66225642769b57bbc09434e7d6c092a/py-graphql-mapper-1.1.1.tar.gz",
"platform": null,
"description": "[![Python package](https://github.com/dapalex/py-graphql-mapper/actions/workflows/python-package.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/python-package.yml)\r\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/280533e425784f7da9ecb0f6e529886b)](https://www.codacy.com/gh/dapalex/py-graphql-mapper/dashboard?utm_source=github.com&utm_medium=referral&utm_content=dapalex/py-graphql-mapper&utm_campaign=Badge_Grade)\r\n--------------------------------------------------------------------------------\r\n# py-graphql-mapper\r\n[![Code Generation Test](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-codegen.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-codegen.yml)\r\n[![Pyhon-GraphQL Mapping Test](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-map.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-map.yml)\r\n\r\nA python library to interact with GraphQL APIs with no need of hardcoded strings.\r\n\r\n## Introduction\r\n\r\nThis library acts as a mapper between python and GraphQL languages for GraphQL clients, allowing a code-first approach when calling a GraphQL API server.\r\nIt translates GraphQL entities into python objects and viceversa in order to avoid working with massive \"copy&paste\"s.\r\n\r\nThis document contains a quick overview of the functionalities, for more details and options you can read here:\r\n\r\n* [Code Generation](https://github.com/dapalex/py-graphql-mapper/blob/develop/codegen/README.MD)\r\n* [Core Mapper](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD)\r\n* [Use Cases](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/README.MD)\r\n\r\n\r\nThe package does not use any third-party libraries, it relies only on python 3 (3.10+) standard libraries.\r\n\r\n\r\n## Usage in a nutshell\r\n\r\n### Installation\r\n\r\nAvailable in PyPI, the following command will install the library:\r\n\r\n```\r\npip install py-graphql-mapper\r\n```\r\n\r\n\r\n### Generate python code from schema\r\n\r\nTo generate the code execute the following command:\r\n\r\n```\r\npgmcodegen generate ./pathToOutputFolder -apiArgs ./<pathToArgsFile>/generatorArgs.json\r\n```\r\n\r\nThis command requires a json file containing the parameters needed to get the GraphQL schema\r\n\r\n![image](https://github.com/dapalex/py-graphql-mapper/blob/develop/docs/cli_args_nutshell.png)\r\n\r\nA sample is available in the main folder ['cli_args.json'](https://github.com/dapalex/py-graphql-mapper/blob/develop/cli_args.json).\r\n\r\nThe following python files will be generated:\r\n\r\n* enums.py\r\n* scalars.py\r\n* gql_simple_types.py\r\n* gql_types.py\r\n* type_refs.py\r\n* queries.py\r\n* mutations.py\r\n\r\nThese links show code generated using the library [Github GraphQL API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/github), [Rapid GraphQL API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/rapidapi) and [GeoDBCities API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/gdbc)\r\n\r\nMore command options are available [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/codegen/README.MD#usage-via-command-line)\r\n\r\n\r\n### Execution of a query\r\n\r\nChoose the query class you want to use from the generated file queries.py (or a mutation from mutations.py):\r\n\r\nInstantiate it adding GraphQL arguments if needed:\r\n```python\r\nfrom .output.gdbc.queries import currencies\r\n\r\nmy_currencies = currencies(last=7, before='MTE=')\r\n```\r\nor add them using the field _args_\r\n\r\n```python\r\nmy_currencies._args.last = 7\r\nmy_currencies._args.before = 'MTE='\r\n```\r\nThen call _export_gql_source_ property to pass the payload to the HTTP request:\r\n\r\n(example using _requests_ library)\r\n```python\r\nimport requests\r\n\r\nresponse = requests.request('POST', url='https://geodb-cities-graphql.p.rapidapi.com/',\r\n json= { \"query\": my_currencies.export_gql_source },\r\n headers={\r\n \"content-type\": \"application/json\",\r\n \"X-RapidAPI-Key\": '123402mmri02fni230iif32jr420',\r\n \"X-RapidAPI-Host\": \"geodb-cities-graphql.p.rapidapi.com\"\r\n }\r\n )\r\n```\r\n\r\nMore details on how to set a query [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD#creation-of-an-operation)\r\n\r\n\r\n### Retrieval of a response\r\n\r\nObtained the response from the GraphQL API the following code will map the received json payload into the python object\r\n\r\n```python\r\nfrom pygqlmap.network import GQLResponse\r\n\r\ngqlResponse = GQLResponse(response)\r\n\r\ngqlResponse.map_gqldata_to_obj(myCurrenciesQuery.type)\r\n\r\nprint('Result object: ' + str(gqlResponse.result_obj))\r\n```\r\n\r\nThe mapped response from the GraphQL server will be available within _gqlResponse_ object: `_gqlResponse.result_obj_`\r\n\r\nMore details [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD#parsing-of-a-response)\r\n\r\n\r\nA suite of use cases [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/README.MD)\r\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2022 dapalex Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "A python library to call GraphQL APIs without using hardcoded strings",
"version": "1.1.1",
"project_urls": {
"Bug Tracker": "https://github.com/dapalex/py-graphql-mapper/issues",
"Homepage": "https://github.com/dapalex/py-graphql-mapper/",
"Release Notes": "https://github.com/dapalex/py-graphql-mapper/blob/develop/RELEASE_NOTES.MD",
"Source Code": "https://github.com/dapalex/py-graphql-mapper/"
},
"split_keywords": [
"python",
"graphql",
"mapping"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2b8292f18e0f9a3184db0b94f03d00d9bc4fef4799e028e26e48ad126b506bf8",
"md5": "263526d9a8516ec135891f62e79abbf2",
"sha256": "f3a50a826248a410882f64b5e94c425d25d6245c23296d246e685ec3c6160117"
},
"downloads": -1,
"filename": "py_graphql_mapper-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "263526d9a8516ec135891f62e79abbf2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 43239,
"upload_time": "2023-07-02T14:10:20",
"upload_time_iso_8601": "2023-07-02T14:10:20.732333Z",
"url": "https://files.pythonhosted.org/packages/2b/82/92f18e0f9a3184db0b94f03d00d9bc4fef4799e028e26e48ad126b506bf8/py_graphql_mapper-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a8be489db24db1385c136a3c2b77e952c66225642769b57bbc09434e7d6c092a",
"md5": "dea9e3035cc8a2fc3f976e7571ccf76e",
"sha256": "f4ffbfe5d3280f563a7c45f35be62680cfb519e2806e102a0dda038f4e7ac910"
},
"downloads": -1,
"filename": "py-graphql-mapper-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "dea9e3035cc8a2fc3f976e7571ccf76e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 37572,
"upload_time": "2023-07-02T14:10:22",
"upload_time_iso_8601": "2023-07-02T14:10:22.337390Z",
"url": "https://files.pythonhosted.org/packages/a8/be/489db24db1385c136a3c2b77e952c66225642769b57bbc09434e7d6c092a/py-graphql-mapper-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-02 14:10:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dapalex",
"github_project": "py-graphql-mapper",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "py-graphql-mapper"
}