From 9acd96375098e790122c341866d94b3bb938c349 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 31 Aug 2024 14:37:38 +0000 Subject: [PATCH] Deployed c13f698 with MkDocs version: 1.6.1 --- .nojekyll | 0 404.html | 838 ++ about/index.html | 1002 +++ api/exceptions/index.html | 1055 +++ api/http/index.html | 1016 +++ api/model/index.html | 1106 +++ api/query/index.html | 1048 +++ assets/images/favicon.png | Bin 0 -> 1870 bytes assets/javascripts/bundle.af256bd8.min.js | 29 + assets/javascripts/bundle.af256bd8.min.js.map | 7 + assets/javascripts/lunr/min/lunr.ar.min.js | 1 + assets/javascripts/lunr/min/lunr.da.min.js | 18 + assets/javascripts/lunr/min/lunr.de.min.js | 18 + assets/javascripts/lunr/min/lunr.du.min.js | 18 + assets/javascripts/lunr/min/lunr.el.min.js | 1 + assets/javascripts/lunr/min/lunr.es.min.js | 18 + assets/javascripts/lunr/min/lunr.fi.min.js | 18 + assets/javascripts/lunr/min/lunr.fr.min.js | 18 + assets/javascripts/lunr/min/lunr.he.min.js | 1 + assets/javascripts/lunr/min/lunr.hi.min.js | 1 + assets/javascripts/lunr/min/lunr.hu.min.js | 18 + assets/javascripts/lunr/min/lunr.hy.min.js | 1 + assets/javascripts/lunr/min/lunr.it.min.js | 18 + assets/javascripts/lunr/min/lunr.ja.min.js | 1 + assets/javascripts/lunr/min/lunr.jp.min.js | 1 + assets/javascripts/lunr/min/lunr.kn.min.js | 1 + assets/javascripts/lunr/min/lunr.ko.min.js | 1 + assets/javascripts/lunr/min/lunr.multi.min.js | 1 + assets/javascripts/lunr/min/lunr.nl.min.js | 18 + assets/javascripts/lunr/min/lunr.no.min.js | 18 + assets/javascripts/lunr/min/lunr.pt.min.js | 18 + assets/javascripts/lunr/min/lunr.ro.min.js | 18 + assets/javascripts/lunr/min/lunr.ru.min.js | 18 + assets/javascripts/lunr/min/lunr.sa.min.js | 1 + .../lunr/min/lunr.stemmer.support.min.js | 1 + assets/javascripts/lunr/min/lunr.sv.min.js | 18 + assets/javascripts/lunr/min/lunr.ta.min.js | 1 + assets/javascripts/lunr/min/lunr.te.min.js | 1 + assets/javascripts/lunr/min/lunr.th.min.js | 1 + assets/javascripts/lunr/min/lunr.tr.min.js | 18 + assets/javascripts/lunr/min/lunr.vi.min.js | 1 + assets/javascripts/lunr/min/lunr.zh.min.js | 1 + assets/javascripts/lunr/tinyseg.js | 206 + assets/javascripts/lunr/wordcut.js | 6708 +++++++++++++++++ .../workers/search.b8dbb3d2.min.js | 42 + .../workers/search.b8dbb3d2.min.js.map | 7 + assets/stylesheets/main.3cba04c6.min.css | 1 + assets/stylesheets/main.3cba04c6.min.css.map | 1 + assets/stylesheets/palette.06af60db.min.css | 1 + .../stylesheets/palette.06af60db.min.css.map | 1 + examples/index.html | 880 +++ examples/query/index.html | 972 +++ index.html | 910 +++ install/index.html | 902 +++ search/search_index.json | 1 + sitemap.xml | 47 + sitemap.xml.gz | Bin 0 -> 261 bytes tutorial/model/index.html | 978 +++ tutorial/query/index.html | 1101 +++ 59 files changed, 19146 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 about/index.html create mode 100644 api/exceptions/index.html create mode 100644 api/http/index.html create mode 100644 api/model/index.html create mode 100644 api/query/index.html create mode 100644 assets/images/favicon.png create mode 100644 assets/javascripts/bundle.af256bd8.min.js create mode 100644 assets/javascripts/bundle.af256bd8.min.js.map create mode 100644 assets/javascripts/lunr/min/lunr.ar.min.js create mode 100644 assets/javascripts/lunr/min/lunr.da.min.js create mode 100644 assets/javascripts/lunr/min/lunr.de.min.js create mode 100644 assets/javascripts/lunr/min/lunr.du.min.js create mode 100644 assets/javascripts/lunr/min/lunr.el.min.js create mode 100644 assets/javascripts/lunr/min/lunr.es.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.he.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hu.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hy.min.js create mode 100644 assets/javascripts/lunr/min/lunr.it.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ja.min.js create mode 100644 assets/javascripts/lunr/min/lunr.jp.min.js create mode 100644 assets/javascripts/lunr/min/lunr.kn.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ko.min.js create mode 100644 assets/javascripts/lunr/min/lunr.multi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.nl.min.js create mode 100644 assets/javascripts/lunr/min/lunr.no.min.js create mode 100644 assets/javascripts/lunr/min/lunr.pt.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ro.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ru.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sa.min.js create mode 100644 assets/javascripts/lunr/min/lunr.stemmer.support.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sv.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ta.min.js create mode 100644 assets/javascripts/lunr/min/lunr.te.min.js create mode 100644 assets/javascripts/lunr/min/lunr.th.min.js create mode 100644 assets/javascripts/lunr/min/lunr.tr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.vi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.zh.min.js create mode 100644 assets/javascripts/lunr/tinyseg.js create mode 100644 assets/javascripts/lunr/wordcut.js create mode 100644 assets/javascripts/workers/search.b8dbb3d2.min.js create mode 100644 assets/javascripts/workers/search.b8dbb3d2.min.js.map create mode 100644 assets/stylesheets/main.3cba04c6.min.css create mode 100644 assets/stylesheets/main.3cba04c6.min.css.map create mode 100644 assets/stylesheets/palette.06af60db.min.css create mode 100644 assets/stylesheets/palette.06af60db.min.css.map create mode 100644 examples/index.html create mode 100644 examples/query/index.html create mode 100644 index.html create mode 100644 install/index.html create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz create mode 100644 tutorial/model/index.html create mode 100644 tutorial/query/index.html diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..7e531cb --- /dev/null +++ b/404.html @@ -0,0 +1,838 @@ + + + +
+ + + + + + + + + + + + + + +this library is wrapped around pydantic for easy modeling, typechecking and +because it is pydantic, it is well known package, no need to reinvent the wheel here.
+ql
over other libraries++At the time of writing this library does NOT support
+mutation
, onlyquery
.
this library was written because when I searched for graphql client libraries, I couldn't
+find easy/well written libraries for graphql, most of the libraries are small wrappers around requests
,
+or they are trying to reinvent the wheel, and they just feel awkward...
simplicity
- it is simple to query data, you can provide a query string, or generate a
+query string with python objects.
pydantic
- working with a well known library doesn't requires you to learn a lot of new things, also typechecking
scalar
- unlike other libraries, where there is no scalarize ability, or sometimes they require you to
+create a Schema
, ql
library takes use of the __typename
field from graphql for scalarize functionality, which means,
+you don't need to create Schema
classes, and it can scalar from any given graphql response as long it includes the __typename
+field for sub types
exceptions are only raised in scalar
requests, when we convert graphql
+response to python objects it make sense to convert graphql errors to python exceptions.
graphql errors are always the same, if it returned an error you have a problem +with your query.
+an exception class that is raised when scalar function +gets error response from graphql +
+Name | +Type | +Description | +
---|---|---|
errors |
+list[QueryErrorDict] |
+list of graphql errors | +
import ql
+
+try:
+ _ = ql.scalar_query_response({
+ "errors": [
+ {"message": "example for error", "locations": {"line": 0, "column": 0}},
+ {"message": "I have another error in my query!", "locations": {"line": 0, "column": 0}},
+ ],
+ "data": None
+ })
+except ql.QLErrorResponseException:
+ print("damn... my graphql query failed...")
+
property
returns a list of QLErrorDetails
.
class used to map each error detail to python object +
+Name | +Type | +Description | +
---|---|---|
message |
+str |
+the message field from the graphql error | +
locations |
+list[QueryErrorLocationDict] |
+list of locations where the error occurse | +
this library does not implement http communication with graphql server since API can be
+different from implementation to implementation. the library http client accept a request
function
+that takes a graphql query string, and returns the json response parsed as dict, this allows
+the flexability to implement error handlers in the passed request function instead
+of wrapping each query
request with try...except
.
set request function for the ql
client
+
Name | +Type | +Description | +
---|---|---|
request_func |
+GraphqlRequestFunc |
+callable function that accepts a string and returns dict | +
import ql
+import requests
+
+def request_graphql(query: str) -> dict:
+ response = requests.post("...", json={"query": query})
+ response.raise_for_status() # can handle errors here in one place
+ return response.json()
+
+ql.http.set_request_func(request_graphql)
+
send request query with given request function +
+Name | +Type | +Description | +
---|---|---|
query |
+str |
+the query request that will be passed to the function | +
returns a dict mapping between all registered models and thier +registered typename
+ +returns the model configured typename, if model is not registered
+with ql.model
then return None
Name | +Type | +Description | +
---|---|---|
model |
+type[BaseModel] |
+the model we want the typename for | +
returns all child models, that the given model implements
+ +Name | +Type | +Description | +
---|---|---|
cls |
+type[BaseModel] |
+the model we want to take implementations from | +
import ql
+from pydantic import BaseModel
+
+
+@lq.model
+class Human(BaseModel):
+ first_name: str
+ last_name: str
+
+
+@ql.model
+class Male(Human):
+ pass
+
+
+@ql.model
+class Female(Human):
+ pass
+
+
+print(ql.implements(Human))
+# (<class '__main__.Male'>, <class '__main__.Female'>)
+
returns a namedtuple of all queryable fields in the given model, mapping between +the model field name to the query name.
+Info
+this function is also aliased as ql._
because it is common
Name | +Type | +Description | +
---|---|---|
cls |
+type[BaseModel] |
+the model we want the namedtuple from | +
import ql
+from typing import Annotated
+from pydantic import BaseModel
+
+
+@ql.model
+class Article(BaseModel):
+ name: Annotated[str, ql.metadata(query_name="title")]
+ description: str
+
+ foo: Annotated[str, ql.metadata(queryable=False)]
+
+print(ql.query_fields_nt(Article).name) # "title"
+print(ql.query_fields_nt(Article).description) # "description"
+print(ql.query_fields_nt(Article).foo) # exception
+
reading data from apis is the most common operation we do, that's why ql
makes it
+easy to query data from your graphql endpoint and provide variety of query methods.
takes python ql query structure and returns a valid graphql query string. +
def query(
+ *query_models: _QueryModelType,
+ fragments: Optional[_QueryFragmentType] = None,
+ include_typename: bool = True,
+) -> str:
+
Name | +Type | +Description | +
---|---|---|
query_models |
+*_QueryModelType |
+python ql structured query | +
fragments |
+Optional[_QueryFragmentType] |
+dict mapping between ql.fragment to the python ql structured query |
+
include_typename |
+bool |
+if include __typename field when querying sub types |
+
import ql
+from pydantic import BaseModel
+
+@ql.model
+class Point(BaseModel):
+ x: int
+ y: int
+
+query_str = ql.query(
+ (Point, (
+ ql._(Point).x,
+ ql._(Point).y
+ ))
+)
+
serializes the ql query structure, send it via http and returns the response as dict
.
+
def query_response(
+ *query_models: _QueryModelType,
+ fragments: Optional[_QueryFragmentType] = {},
+ include_typename: bool = True,
+) -> QueryResponseDict:
+
http request function must be set to make this function work, click here to view.
+serializes the ql query structure to a valid graphql query, send it via http, takes the response
+and returns a scalared dict with the defined models, this function will also raise
+graphql errors if the query responsed with errors
field
+