Skip to content

Commit b511edb

Browse files
unicodeveloperpeggyrayzis
authored andcommitted
Add more context
1 parent 7431b4f commit b511edb

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

docs/source/tutorial/data-source.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,18 @@ const server = new ApolloServer({
404404
});
405405
```
406406

407-
In the code above, we required the `launch` and `user` data source files, created an instance of both classes and passed them as objects to the `dataSources` key in `ApolloServer`'s' constructor.
407+
In the code above, we required the `launch` and `user` data source files, created an instance of both classes and passed them as objects to the `dataSources` function in `ApolloServer`'s constructor.
408408

409-
We also required the `utils.js` file, assigned the `createStore()` method to a `store` variable and passed it the `UserAPI` constructor. The `createStore()` method is responsible for making sure the `users` and `trips` tables exist, and ensures they can be connected to! Apollo Server will then put the data sources on the `context` for every request, so you can access them from your resolvers.
409+
We also required the `utils.js` file, assigned the `createStore()` method to a `store` variable and passed it to the `UserAPI` constructor. The `createStore()` method is responsible for making sure the `users` and `trips` tables exist.
410+
411+
```js
412+
dataSources: () => ({
413+
launchAPI: new LaunchAPI(),
414+
userAPI: new UserAPI({ store }),
415+
}),
416+
```
417+
418+
The block of code above ensures that when Apollo Server boots up, the server puts the data sources on the `context` for every request, so you can access them from your resolvers.
410419

411420
Now, what about the `context` function defined explicitly in the `ApolloServer` constructor?
412421

0 commit comments

Comments
 (0)