Skip to content

Class-based graph definition API

No due date 0% complete

Currently hiku graph definition is declarative based:

graph = Graph([
  Node('User', [
    Field('id', Interger, user_fields)
  ]),
  Root([
    Link('user', Optional[TypeRef['User']], link_user, requires=None)
  ])
])

Problems with this approach:

  • strings, strings everywhere
    • easy to mistype
    • TypeRef['some_type'] is tedious to write
    • no go to definitions
    • n…

Currently hiku graph definition is declarative based:

graph = Graph([
  Node('User', [
    Field('id', Interger, user_fields)
  ]),
  Root([
    Link('user', Optional[TypeRef['User']], link_user, requires=None)
  ])
])

Problems with this approach:

  • strings, strings everywhere
    • easy to mistype
    • TypeRef['some_type'] is tedious to write
    • no go to definitions
    • no mypy support
    • but the good part of this is recursive types
  • can not use Node as class for typing

New approach - strawberry-like https://strawberry.rocks/

  • All types defined using classes/dataclasses
  • Enables annotation use and mypy support
  • No strings

What it can look like:

@hiku.type
class User:
  id: int = hiku.field(resolver=user_fields)

@hiku.query
class Query:
  user: User | None = hiku.link(resolver=link_user)

graph = Graph(query=Query)  
Loading