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..f48ed3b --- /dev/null +++ b/404.html @@ -0,0 +1,700 @@ + + + +
+ + + + + + + + + + + + + + +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 | +
the ql
api is small and simple, you don't need to import anything
+from inside the module, just import the module and use the exported functionality
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.
+