Skip to content

Releases: pavelprokhorenko/graphql-requests

0.3.1

13 Aug 09:50
f257abb
Compare
Choose a tag to compare

What's Changed

Full Changelog: 0.3.0...0.3.1

0.3.0

13 Aug 09:38
eb2431e
Compare
Choose a tag to compare

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 to Client
  • rename GraphQLBaseClient to BaseClient

What's Changed

Full Changelog: 0.2.0...0.3.0

0.2.0

08 Aug 09:54
67c13d6
Compare
Choose a tag to compare

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

Full Changelog: 0.1.3...0.2.0

0.1.3

06 Aug 09:27
8e07d22
Compare
Choose a tag to compare

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

Full Changelog: 0.1.1...0.1.3

0.1.1

06 Aug 07:31
8fad4c5
Compare
Choose a tag to compare

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

Full Changelog: 0.1.0...0.1.1

0.1.0

25 Jul 15:41
24b8435
Compare
Choose a tag to compare

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

Full Changelog: https://github.com/pavelprokhorenko/graphql-requests/commits/0.1.0