Skip to content

How to modularize resolvers file? #672

Answered by rafalp
Alexander-Trinh asked this question in Q&A
Discussion options

You must be logged in to vote

Your resolvers aren't getting registered because you need to import python modules in order for code in them to be executed.


As for ideas how to organize your resolvers, I split them in python packages (types, mutations, scalars) and I give each GraphQL type and mutation separate module. I'm then aggregating those resolvers in __init__.py of each of packages, which I in turn import in schema module and pass to make_executable_schema.

Example types dir will contain files like this:

  • query.py
  • thread.py
  • user.py

types/__init__.py will look like this:

from .query import query_type
from .thread import thread_type
from .user import user_type

types = [query_type, thread_type, user_type]

In mut…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rafalp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants