Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of provider vs. RESTDataSource #174

Closed
nathanchapman opened this issue Nov 9, 2018 · 3 comments
Closed

Use of provider vs. RESTDataSource #174

nathanchapman opened this issue Nov 9, 2018 · 3 comments

Comments

@nathanchapman
Copy link
Contributor

I would love to see some examples in the documentation of when to use a provider vs. RESTDataSource

Do they work together? It seems like a provider would be re-implementing a lot of methods that already exist in a RESTDataSource. Also I'm guessing any RESTDataSources would go into the contextBuilder?

@ardatan
Copy link
Collaborator

ardatan commented Nov 10, 2018

DataSources feature looks quite similar to providers while providers feature is part of Dependency Injection and can be connected to each other in modular approach. And providers are constructed in application scope, not in request scope while DataSources are created inside a factory function on each request. But you can call providers inside datasources by using injector inside context, or get datasources inside providers by using onRequest hook inside of providers.
We can think about request scope providers. What do you think @dotansimha @darkbasic @kamilkisiela?

@dotansimha
Copy link
Collaborator

That's a great questions, @nathanchapman !
@ardatan is right, DataSources of apollo-server is similar to Providers in graphql-modules.
Actually, before we started to develop graphql-modules, we used DataSources in some of our projects.
DataSources is great as a simple bridge for your data, it's an abstraction that prevents from your resolvers to access directly the data source.
The problem is that each DataSource stands by itself, and they cannot interact with each other easily, and Providers can interact and communicate with other Providers with dependency-injection.

@ardatan
Copy link
Collaborator

ardatan commented Nov 10, 2018

Then I am planning to create a PR about request scope providers.

@ardatan ardatan closed this as completed Nov 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants