S
S
Shakir Darion2020-06-25 14:52:09
Node.js
Shakir Darion, 2020-06-25 14:52:09

Is it possible to throw models in context?

I am new to graphql.

I am making a project using apollo-server mongoose node.js.

Is it considered normal practice to add models to context ?

or should i import each model in resolvers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleh, 2020-07-03
@shakiriker

Yes, it is considered normal practice to initialize models, synchronize and forward models to the context. BUT, in the case of mongoose, the best practice would be to initialize the connection and call the models in the resolver. In any case, there will be no superfluous overhead in the context, either in one or the other case. But the plus of using models in the resolver is autocomplete and the ability to look at the entity, nothing like this will happen in the context :)
My practice is, I won’t judge how correct it is:
- In the context of the user
- In the context of global things (cache, sending tasks to the queue, logger)
- In the context of a subscription (just convenient)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question