Skip to content

Commit a3f4760

Browse files
authored
Merge pull request #23 from qlient-org/develop
Pre-Release 0.1.0-alpha
2 parents 783d06c + 6b4b6f0 commit a3f4760

File tree

135 files changed

+18907
-726
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+18907
-726
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
/.pytest_cache/**
88
/*.egg-info/
99
.install.stamp
10-
.coverage
11-
/site/**
10+
.coverage

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ help:
1111
@echo " clean remove all temporary files"
1212
@echo " test run all the tests"
1313
@echo " report print coverage report"
14+
@echo " docs create the docs"
1415
@echo " shell open a Poetry shell"
1516

1617

@@ -23,7 +24,7 @@ $(INSTALL_STAMP): pyproject.toml
2324
.PHONY: clean
2425
clean:
2526
find . -type d -name "__pycache__" | xargs rm -rf {};
26-
rm -rf $(INSTALL_STAMP) .coverage .mypy_cache
27+
rm -rf $(INSTALL_STAMP) .coverage .mypy_cache .pytest_cache
2728
rm -rf build
2829
rm -rf dist
2930

@@ -36,6 +37,10 @@ test: $(INSTALL_STAMP)
3637
report: $(INSTALL_STAMP)
3738
$(POETRY) run coverage report
3839

40+
.PHONY: docs
41+
docs: $(INSTALL_STAMP)
42+
$(POETRY) run mkdocs build
43+
3944

4045
.PHONY: shell
4146
shell: $(INSTALL_STAMP)

README.md

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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-
[![pypi](https://img.shields.io/pypi/v/python-qlient.svg)](https://pypi.python.org/pypi/python-qlient)
5-
[![versions](https://img.shields.io/pypi/pyversions/python-qlient.svg)](https://github.com/qlient-org/python-qlient)
4+
[![pypi](https://img.shields.io/pypi/v/qlient.svg)](https://pypi.python.org/pypi/qlient)
5+
[![versions](https://img.shields.io/pypi/pyversions/qlient.svg)](https://github.com/qlient-org/python-qlient)
66
[![license](https://img.shields.io/github/license/qlient-org/python-qlient.svg)](https://github.com/qlient-org/python-qlient/blob/master/LICENSE)
77

88
A fast and modern graphql client designed with simplicity in mind.
@@ -20,65 +20,19 @@ pip install qlient
2020
## Quick Start
2121

2222
````python
23-
from qlient import Client
23+
from qlient import Client, GraphQLResponse
2424

25-
client = Client("https://api.spacex.land/graphql/")
25+
client = Client("https://swapi-graphql.netlify.app/.netlify/functions/index")
2626

27-
res = client.query.launchesPast(
28-
# spacex graphql input fields
29-
find={"mission_name": "Starlink"},
30-
limit=5,
31-
sort="mission_name",
27+
res: GraphQLResponse = client.query.film(
28+
# swapi graphql input fields
29+
id="ZmlsbXM6MQ==",
3230

3331
# qlient specific
34-
_fields=["mission_name", "launch_success", "launch_year"]
32+
_fields=["id", "title", "episodeID"]
3533
)
36-
````
37-
38-
which sends the following query
39-
40-
```gql
41-
query launchesPast($find: LaunchFind, $limit: Int, $sort: String) {
42-
launchesPast(find: $find, limit: $limit, sort: $sort) {
43-
mission_name
44-
launch_success
45-
launch_year
46-
}
47-
}
48-
```
49-
50-
to the server and return this body:
5134

52-
````json
53-
{
54-
"data": {
55-
"launchesPast": [
56-
{
57-
"mission_name": "Paz / Starlink Demo",
58-
"launch_success": true,
59-
"launch_year": "2018"
60-
},
61-
{
62-
"mission_name": "Starlink 1",
63-
"launch_success": true,
64-
"launch_year": "2019"
65-
},
66-
{
67-
"mission_name": "Starlink 2",
68-
"launch_success": true,
69-
"launch_year": "2020"
70-
},
71-
{
72-
"mission_name": "Starlink 3",
73-
"launch_success": true,
74-
"launch_year": "2020"
75-
},
76-
{
77-
"mission_name": "Starlink 4",
78-
"launch_success": true,
79-
"launch_year": "2020"
80-
}
81-
]
82-
}
83-
}
84-
````
35+
print(res.query) # query film($id: ID) { film(id: $id) { id title episodeID } }
36+
print(res.variables) # {'id': 'ZmlsbXM6MQ=='}
37+
print(res.data) # {'film': {'id': 'ZmlsbXM6MQ==', 'title': 'A New Hope', 'episodeID': 4}}
38+
````

docs/examples/.graphqlconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "SWAPI GraphQL API",
3+
"schemaPath": "swapi-schema.graphql",
4+
"extensions": {
5+
"endpoints": {
6+
"Default GraphQL Endpoint": {
7+
"url": "https://swapi-graphql.netlify.app/.netlify/functions/index",
8+
"introspect": true
9+
}
10+
}
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import Dict
2+
3+
from qlient import Client, Schema
4+
from qlient.schema.providers import SchemaProvider
5+
6+
7+
class MySchemaProvider(SchemaProvider):
8+
9+
def load_schema(self) -> Dict:
10+
# do some logic that loads your schema
11+
return {...}
12+
13+
14+
my_schema = Schema(provider=MySchemaProvider())
15+
16+
client = Client("https://...", schema=my_schema)

docs/examples/full_settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from qlient import Settings, Client
2+
3+
my_settings = Settings(
4+
introspect=True, # default, enable backend schema introspection
5+
validate_fields=True, # default, enable query field selection validation
6+
validate_variables=True # default, enable query variable validation
7+
)
8+
9+
my_client = Client("https://...", settings=my_settings)

docs/examples/index_quick_start.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from qlient import Client, GraphQLResponse
2+
3+
client = Client("https://swapi-graphql.netlify.app/.netlify/functions/index")
4+
5+
res: GraphQLResponse = client.query.film(
6+
# swapi graphql input fields
7+
id="ZmlsbXM6MQ==",
8+
9+
# qlient specific
10+
_fields=["id", "title", "episodeID"]
11+
)
12+
13+
print(res.query) # query film($id: ID) { film(id: $id) { id title episodeID } }
14+
print(res.variables) # {'id': 'ZmlsbXM6MQ=='}
15+
print(res.data) # {'film': {'id': 'ZmlsbXM6MQ==', 'title': 'A New Hope', 'episodeID': 4}}

docs/examples/project_batches.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[![qlient-org](https://circleci.com/gh/qlient-org/python-qlient.svg?style=svg)](https://circleci.com/gh/qlient-org/python-qlient)
2+
[![pypi](https://img.shields.io/pypi/v/qlient.svg)](https://pypi.python.org/pypi/qlient)
3+
[![versions](https://img.shields.io/pypi/pyversions/qlient.svg)](https://github.com/qlient-org/python-qlient)
4+
[![license](https://img.shields.io/github/license/qlient-org/python-qlient.svg)](https://github.com/qlient-org/python-qlient/blob/master/LICENSE)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pathlib import Path
2+
3+
from qlient import Client, Schema
4+
from qlient.schema.providers import FileSchemaProvider
5+
6+
path_to_schema = Path("./path/to/my/schema.json")
7+
8+
local_schema = Schema(provider=FileSchemaProvider(path_to_schema))
9+
10+
client = Client("https://...", schema=local_schema)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from qlient import Client, Fields
2+
3+
client: Client = Client("https://swapi-graphql.netlify.app/.netlify/functions/index")
4+
5+
nested_fields = Fields(
6+
people=Fields(
7+
"id",
8+
"name",
9+
homeworld="name"
10+
)
11+
)
12+
13+
response = client.query.allPeople(first=3, _fields=nested_fields)
14+
15+
print(response.query)
16+
# query allPeople($first: Int) { allPeople(first: $first) { people { id name homeworld { name } } } }

0 commit comments

Comments
 (0)