1- """ This file contains the different transports
1+ """This file contains the different transports
22
33:author: Daniel Seifert
44:created: 09.09.2021
2222
2323
2424class 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
5272class 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