Skip to content

Commit 13f9e21

Browse files
authored
Merge pull request #28 from qlient-org/develop
Release 0.2.1-beta
2 parents 76c5ba4 + a761fa8 commit 13f9e21

40 files changed

+753
-256
lines changed

.deepsource.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version = 1
2+
3+
test_patterns = ["tests/**"]
4+
5+
[[analyzers]]
6+
name = "python"
7+
enabled = true
8+
9+
[analyzers.meta]
10+
max_line_length = 120
11+
runtime_version = "3.x.x"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Qlient: Python GraphQL Client
22

33
[![qlient-org](https://circleci.com/gh/qlient-org/python-qlient.svg?style=svg)](https://circleci.com/gh/qlient-org/python-qlient)
4+
[![DeepSource](https://deepsource.io/gh/qlient-org/python-qlient.svg/?label=resolved+issues&token=WQWScZui5Jy-cNg3fzvWxqhW)](https://deepsource.io/gh/qlient-org/python-qlient/?ref=repository-badge)
45
[![pypi](https://img.shields.io/pypi/v/qlient.svg)](https://pypi.python.org/pypi/qlient)
56
[![versions](https://img.shields.io/pypi/pyversions/qlient.svg)](https://github.com/qlient-org/python-qlient)
67
[![license](https://img.shields.io/github/license/qlient-org/python-qlient.svg)](https://github.com/qlient-org/python-qlient/blob/master/LICENSE)

docs/examples/full_settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import json
2+
13
from qlient import Settings, Client
24

35
my_settings = Settings(
46
introspect=True, # default, enable backend schema introspection
57
validate_fields=True, # default, enable query field selection validation
6-
validate_variables=True # default, enable query variable validation
8+
validate_variables=True, # default, enable query variable validation,
9+
json_dumps=json.dumps, # default, use python's builtin json.dumps for internal dumping
10+
json_loads=json.loads, # default, use python's builtin json.loads for internal loading
711
)
812

913
my_client = Client("https://...", settings=my_settings)

docs/examples/project_batches.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![qlient-org](https://circleci.com/gh/qlient-org/python-qlient.svg?style=svg)](https://circleci.com/gh/qlient-org/python-qlient)
2+
[![DeepSource](https://deepsource.io/gh/qlient-org/python-qlient.svg/?label=resolved+issues&token=WQWScZui5Jy-cNg3fzvWxqhW)](https://deepsource.io/gh/qlient-org/python-qlient/?ref=repository-badge)
23
[![pypi](https://img.shields.io/pypi/v/qlient.svg)](https://pypi.python.org/pypi/qlient)
34
[![versions](https://img.shields.io/pypi/pyversions/qlient.svg)](https://github.com/qlient-org/python-qlient)
45
[![license](https://img.shields.io/github/license/qlient-org/python-qlient.svg)](https://github.com/qlient-org/python-qlient/blob/master/LICENSE)

docs/examples/simple_client_instantiation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
client = Client("https://swapi-graphql.netlify.app/.netlify/functions/index")
44

5-
assert isinstance(client.schema, Schema)
6-
assert isinstance(client.backend, HTTPBackend)
5+
isinstance(client.schema, Schema)
6+
isinstance(client.backend, HTTPBackend)
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
from qlient import Client
1+
from qlient import Client, Settings
22
from qlient.cache import SqliteCache
33

44
client = Client("https://...", cache=SqliteCache())
55

66
# or with custom settings
77

8+
settings = Settings(
9+
json_loads=..., # uses json.loads by default, can be overwritten to ujson.loads
10+
json_dumps=..., # and ujson.dumps
11+
)
12+
813
client = Client(
914
"https://...",
1015
cache=SqliteCache(
1116
path="/path/to/my/schema_cache.sqlite",
12-
expires_in=86400 # seconds
17+
expires_in=86400, # seconds
18+
settings=settings,
1319
)
1420
)

poetry.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "qlient"
3-
version = "0.2.0-beta"
3+
version = "0.2.1-beta"
44
description = "A fast and modern graphql client designed with simplicity in mind."
55
authors = ["Daniel Seifert <[email protected]>"]
66
maintainers = ["Daniel Seifert <[email protected]>"]

src/qlient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" This file contains the qlient exports
1+
"""This file contains the qlient exports
22
33
:author: Daniel Seifert
44
:created: 09.09.2021

src/qlient/backend.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" This file contains the different transports
1+
"""This file contains the different transports
22
33
:author: Daniel Seifert
44
:created: 09.09.2021
@@ -22,6 +22,13 @@
2222

2323

2424
class Backend(abc.ABC):
25+
"""Abstract base class for all graphql backend.
26+
27+
In order to create your own custom graphql backend you must overwrite the `execute_query`
28+
method down below.
29+
30+
This is useful in cases where your backend is not typically reachable via http.
31+
"""
2532

2633
@abc.abstractmethod
2734
def execute_query(
@@ -32,12 +39,25 @@ def execute_query(
3239
context: GraphQLContext = None,
3340
root: GraphQLRoot = None,
3441
) -> GraphQLReturnType:
42+
"""Abstract method to execute a query on this backend.
43+
44+
Keep in mind that this method is synchronous.
45+
If you want to create an async backend, make sure that the `execute_query` method
46+
returns a result and not a Promise.
47+
48+
:param query: holds the graphql query
49+
:param variables: optional, holds variables that are mentioned in the query
50+
:param operation_name: optional, holds the name of this specific operation
51+
:param context: optional, holds a graphql context
52+
:param root: optional, holds a root value for this query
53+
:return: the result of the graphql backend
54+
"""
3555
raise NotImplementedError
3656

3757
@property
3858
@abc.abstractmethod
3959
def cache_key(self) -> str:
40-
""" A key that uniquely identifies the schema for a specific backend
60+
"""A key that uniquely identifies the schema for a specific backend
4161
4262
For example this can be a unique url or hostname.
4363
Or even a static key if the schema remains the same for the backend.
@@ -50,6 +70,10 @@ def cache_key(self) -> str:
5070

5171

5272
class HTTPBackend(Backend):
73+
"""A backend implementation that communicates with a http server.
74+
75+
The HTTPBackend uses pythons requests package under the hood for making requests.
76+
"""
5377

5478
def __init__(
5579
self,
@@ -69,7 +93,7 @@ def execute_query(
6993
context: GraphQLContext = None,
7094
root: GraphQLRoot = None,
7195
) -> GraphQLReturnType:
72-
""" Send a query to the graphql endpoint
96+
"""Send a query to the http graphql backend
7397
7498
:param query: holds the query
7599
:param variables: holds variables that should be sent with in the query
@@ -95,6 +119,10 @@ def execute_query(
95119

96120
@property
97121
def cache_key(self) -> str:
122+
"""The http backend uses the http server uri as the unique cache key.
123+
124+
:return: the endpoint where the graphql server is running.
125+
"""
98126
return self.endpoint
99127

100128
def __str__(self) -> str:

0 commit comments

Comments
 (0)