Releases: pavelprokhorenko/graphql-requests
Releases · pavelprokhorenko/graphql-requests
0.3.1
0.3.0
Features
- add
AsyncClient
:import asyncio from graphql_requests import AsyncClient async def main(): async with AsyncClient(...) as client: response_data = await client.send(...) return response_data loop = asyncio.get_event_loop() loop.run_until_complete(main)
Updates
- rename
GraphQLClient
toClient
- rename
GraphQLBaseClient
toBaseClient
What's Changed
- Async client by @pavelprokhorenko in #8
Full Changelog: 0.2.0...0.3.0
0.2.0
Features
-
Auto conversion JSON keys from client response data to snake_case:
- before:
>>> users = client.send(query=query, operation_name=operation_name, variables=variables) >>> users {'getUsers': [{'id': 1, 'firstName': 'Jack'}, {'id': 2, 'firstName': 'Emma'}, {'id': 3, 'firstName': 'Liam'}]
- now:
>>> users = client.send(query=query, operation_name="getUsers", variables=variables) >>> users {'get_users': [{'id': 1, 'first_name': 'Jack'}, {'id': 2, 'first_name': 'Emma'}, {'id': 3, 'first_name': 'Liam'}]
But if your response data contains some abbreviations (or any strings with multiple consecutive capital letters) like "getHTTPResponse", you should specify
snake_case_serializer
on your client:>>> from graphql_requests.utils import to_snake_case_safe >>> client = GraphQLClient(url, headers=headers, snake_case_serializer=to_snake_case_safe) ... >>> client.send(query=query, operation_name="getHTTPResponse", variables=variables) {'get_http_response': {...}}
Instead you'll get something like that:
{'get_h_t_t_p_response': {...}}
Warning! Conversion is not reversible anymore. You cannot get "getHTTPResponse" from "get_http_response". Don't change
snake_case_serializer
parameter unnecessarily.Also, you can turn this off like:
>>> client = GraphQLClient(url, auto_snake_case=False)
What's Changed
- Auto convert response data to snake case by @pavelprokhorenko in #7
Full Changelog: 0.1.3...0.2.0
0.1.3
Fixes
-
Adapt package code for python3.7 or greater:
- before:
>>> from graphql_requests import GraphQLClient Traceback (most recent call last): .... TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
- now:
>>> from graphql_requests import GraphQLClient >>> GraphQLClient <class 'graphql_requests.client.sync_client.GraphQLClient'>
What's Changed
- Adapt package for >= python3.7 by @pavelprokhorenko in #6
Full Changelog: 0.1.1...0.1.3
0.1.1
Fixes - Breaking Changes
- Fix assignment variables to GraphQLRequest:
- before:
>>> from graphql_requests import GraphQLRequest >>> variables = {"user_id": 10, "car_id": 1} >>> request = GraphQLRequest(variables=variables) >>> request.variables {'user_id': 10, 'car_id': 1}
- after:
>>> from graphql_requests import GraphQLRequest >>> variables = {"user_id": 10, "car_id": 1} >>> request = GraphQLRequest(variables=variables) >>> request.variables {'userId': 10, 'carId': 1}
What's Changed
- Fix graphql request by @pavelprokhorenko in #5
Full Changelog: 0.1.0...0.1.1
0.1.0
Features
- add GraphQL request builder:
>>> from graphql_requests import GraphQLRequest
>>> scheme = """
... query getUsersQuery(userIds: [Int!]!) {
... getUsers(userIds: $userIds) {
... id
... username
... }
... }
... """
>>> variables = {"user_ids": [1, 2, 3]}
>>> request = GraphQLRequest(body=scheme)
>>> request.set_variables(variables)
>>> request.variables
{'userIds': [1, 2, 3]}
- add synchronous GraphQL client:
>>> from graphql_requests import GraphQLClient
>>> client = GraphQLClient("http://127.0.0.1:8000/graphql")
>>> query = """
... query getUsersQuery(userIds: [Int!]!) {
... getUsers(userIds: $userIds) {
... id
... username
... }
... }
... """
>>> variables = {"user_ids": [1, 2, 3]}
>>> users = client.send(query=query, operation_name="getUsers", variables=variables)
>>> users
[{'id': 1, username: 'username 1'}, {'id': 2, username: 'username 2'}, {'id': 3, username: 'username 3'}]
- add read scheme from file:
# getUsersQuery.graphql
query getUsersQuery(userIds: [Int!]!) {
getUsers(userIds: $userIds) {
id
username
}
}
>>> from graphql_requests import GraphQLRequest
>>> request = GraphQLRequest(body="", variables={"user_ids": [1, 2, 3]})
>>> path_to_scheme = "queries/getUsersQuery.graphql"
>>> request.set_body_from_file(file_path=path_to_scheme, encoding="utf-8")
>>> request.body
'query getUsersQuery(userIds: [Int!]!) { getUsers(userIds: $userIds) { id username }\n}'
What's Changed
- Init package by @pavelprokhorenko in #1
- Sync client by @pavelprokhorenko in #2
- GraphQL request by @pavelprokhorenko in #3
- Release by @pavelprokhorenko in #4
Full Changelog: https://github.com/pavelprokhorenko/graphql-requests/commits/0.1.0