Guest User

graphene_solution

a guest
Feb 16th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. def do_something(name):
  2. # runs an additional python method that returns something like:
  3. this_returns_a_dict = {
  4. "name": name,
  5. "id": 1,
  6. "age": 99,
  7. "some_list": ["a", "b"],
  8. }
  9. return this_returns_a_dict
  10.  
  11. from graphene.types.resolver import dict_resolver
  12.  
  13.  
  14. class Patron(graphene.ObjectType):
  15. # class Meta:
  16. # default_resolver = dict_resolver
  17. name = graphene.String()
  18. id = graphene.ID()
  19. age = graphene.Int()
  20. some_list = graphene.List(graphene.String)
  21.  
  22.  
  23. class Query(graphene.ObjectType):
  24.  
  25. patron = graphene.Field(Patron, name=graphene.String(required=True))
  26.  
  27. def resolve_patron(root, info, name):
  28. run_asd = do_something(name)
  29. return Patron(
  30. name=run_asd["name"],
  31. id=run_asd["id"],
  32. age=run_asd["age"],
  33. some_list=run_asd["some_list"],
  34. )
  35.  
  36.  
  37. schema = graphene.Schema(query=Query)
Advertisement
Add Comment
Please, Sign In to add comment