How to structure GraphQL server code
Jonas Helfer
38610

Hi there, so I’m building my project similar to the GitHunt API. What I realized it is a bit different from what you described from this article In GitHunt API, each model only has one connector.

Repositories => GitHub
Users => GitHub
Comments => SQL
Entries => SQL

Then they’re passed via context: 
Repositories: new Repositories({ connector: gitHubConnector })
Users: new Users({ connector: gitHubConnector })
Entries: new Entries()
Comments: new Comments()
__________

My question is, if we were keeping the good structure in the GitHunt API, what do you do when one Model deals with multiple Connectors? My specific use case is I have a collection of Books which belong to my MongoDB, but on writes, I need them to sync to ElasticSearch.

So would this look like:
Books: new Books({ connector: mongoDbConnector, sync: elasticSearchConnector })
-or-
Books: new Books({ connector: mongoDbConnector })
IndexedBooks: new IndexedBooks({ connector: elasticSearchConnector })

What would you do?

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.