Skip to content

Commit

Permalink
Merge pull request #7837 from apollographql/mm/mern-stack-tutorial
Browse files Browse the repository at this point in the history
Docs: content updates to match MongoDB tutorial
  • Loading branch information
Meschreiber committed Mar 1, 2024
2 parents ce568b3 + f235875 commit aa67e22
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions docs/source/integrations/mern.mdx
Expand Up @@ -61,10 +61,10 @@ This schema lets you perform various actions on records: fetching single or mult

Resolver functions are responsible for performing the actions defined in the schema鈥攆or example, fetching and updating records. In a MERN stack application, they're how you connect the GraphQL schema to your MongoDB instance.

In your server's `/src` folder, create a new `resolvers.ts` file and paste in the following resolvers:
In your server's `/src` folder, create a new `resolvers.js` file and paste in the following resolvers:

```ts
import db from "./db/conn.ts";
```js
import db from "./db/connection.js";

const resolvers = {
Record: {
Expand Down Expand Up @@ -122,19 +122,19 @@ To learn more about writing resolver functions, check out the [resolver docs](..
## Step 4: Add Apollo Server to your Express server
Now you can begin integrating Apollo Server into your Express server. Wherever you instantiate your `express` server (usually `mern/server/server.ts`), import `@apollo/server` and its `expressMiddleware`. Then, instantiate and `start` the Apollo Server:
Now you can begin integrating Apollo Server into your Express server. Wherever you instantiate your `express` server (usually `mern/server/server.js`), import `@apollo/server` and its `expressMiddleware`. Then, instantiate and `start` the Apollo Server:
```ts
import express, { json } from 'express';
```js
import express from 'express';
import cors from 'cors';
import "./loadEnvironment.mjs";
import records from "./routes/record.mjs";
import records from "./routes/record.js";

//highlight-start
import gql from "graphql-tag";
import { ApolloServer } from '@apollo/server';
import { buildSubgraphSchema } from '@apollo/subgraph';
import { expressMiddleware } from '@apollo/server/express4';
import resolvers from "./resolvers.mjs";
import resolvers from "./resolvers.js";
import { readFileSync } from "fs";
//highlight-end

Expand Down Expand Up @@ -180,7 +180,7 @@ app.use("/record", records);
app.use(
'/graphql',
cors(),
json(),
express.json(),
expressMiddleware(server),
);
//highlight-end
Expand Down Expand Up @@ -251,4 +251,4 @@ Congrats on completing the tutorial! 馃帀 Incorporating a GraphQL server into yo
While this tutorial only covers the server portion of the MERN stack, the `/client` folder in the [completed example](#complete-example) picks up where the tutorial left off and implements [`@apollo/client`](/react/) to interact with the server. For more information on implementing the Apollo Client, head to the [getting started docs](/react/get-started).
For more hands-on learning on GraphQL and Apollo's server and client libraries, check out our interactive [Odyssey tutorials](https://www.apollographql.com/tutorials/).
For more hands-on learning on GraphQL and Apollo's server and client libraries, check out our interactive [Odyssey tutorials](https://www.apollographql.com/tutorials/).

0 comments on commit aa67e22

Please sign in to comment.