Skip to content

Commit 10e2069

Browse files
committed
updating README and adding Pydantic type instantiation to function connector
1 parent 0bd2701 commit 10e2069

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
Hasura Python SDK
1+
# Hasura Python SDK
22

3-
pip3 install hasura_ndc
3+
To install the library you can use:
44

5-
Work in progress
5+
`pip3 install hasura-ndc`
66

7-
python3 main.py serve --configuration config.json --port 8101 --service-token-secret secret
7+
Python developers can use this SDK to create Hasura Data Connectors using the Python programming language.
88

9-
python3 main.py configuration serve --port 9101
9+
You would be interested in this repository if you wanted to write your own Hasura data connector in Python that wrapped a database or custom data-source.
1010

11+
Included in this SDK is an implementation of a Lambda connector, called a FunctionConnector. If you wanted to simply write Python code you'd likely be more interested in the Python Lambda connector which makes use of this, and you can find that repo here: https://github.com/hasura/ndc-python-lambda
1112

12-
Upload to pypi:
13+
Developer notes:
14+
15+
To upload a new version of the Hasura SDK to pypi:
1316

1417
python3 setup.py sdist
1518

hasura_ndc/function_connector.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,19 @@ def get_type_info(typ, caller_name, object_types, arg_name=None):
207207

208208
async def query(self, configuration: Configuration, state: State, request: QueryRequest) -> QueryResponse:
209209
args = {}
210+
func = self.query_functions[request.collection]
211+
signature = inspect.signature(func)
212+
210213
for k, v in request.arguments.items():
211214
if v.type == "literal":
212-
args[k] = v.value
215+
arg_type = signature.parameters[k].annotation
216+
if issubclass(arg_type, BaseModel):
217+
args[k] = arg_type(**v.value)
218+
else:
219+
args[k] = v.value
213220
elif v.type == "variable":
214221
raise Exception("Variable not supported yet")
215222

216-
func = self.query_functions[request.collection]
217223

218224
if asyncio.iscoroutinefunction(func):
219225
result = await func(**args)
@@ -239,7 +245,15 @@ async def mutation(self,
239245
for operation in request.operations:
240246
operation_name = operation.name
241247
func = self.mutation_functions[operation_name]
242-
args = operation.arguments if operation.arguments else {}
248+
signature = inspect.signature(func)
249+
args = {}
250+
if operation.arguments:
251+
for k, v in operation.arguments.items():
252+
arg_type = signature.parameters[k].annotation
253+
if issubclass(arg_type, BaseModel):
254+
args[k] = arg_type(**v)
255+
else:
256+
args[k] = v
243257
if asyncio.iscoroutinefunction(func):
244258
response = await func(**args)
245259
else:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='hasura_ndc',
9-
version='0.17',
9+
version='0.18',
1010
packages=find_packages(),
1111
install_requires=[
1212
# This line reads the requirements from your `requirements.txt`

0 commit comments

Comments
 (0)