Skip to content

Commit e732f31

Browse files
authored
Update Apollo Server code snippet
Resolves #1078
1 parent 5cab7e4 commit e732f31

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/code/language-support/javascript/server/apollo-server.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ npm install @apollo/server graphql
1515
Then run `node server.js` with this code in `server.js`:
1616

1717
```js
18-
import { ApolloServer } from "@apollo/server"
19-
import { startStandaloneServer } from "@apollo/server/standalone"
20-
import { buildSchema } from "graphql"
18+
import { ApolloServer } from '@apollo/server';
19+
import { startStandaloneServer } from '@apollo/server/standalone';
2120

22-
const schema = buildSchema(`
23-
type Query {
24-
hello: String
25-
}
26-
`)
21+
// The GraphQL schema
22+
const typeDefs = `#graphql
23+
type Query {
24+
hello: String
25+
}
26+
`;
2727

28+
// A map of functions which return data for the schema.
2829
const resolvers = {
2930
Query: {
30-
hello: () => "Hello World!",
31+
hello: () => 'world',
3132
},
32-
}
33+
};
3334

3435
const server = new ApolloServer({
3536
typeDefs,
3637
resolvers,
37-
})
38+
});
3839

39-
const { url } = await startStandaloneServer(server)
40-
41-
console.log(`🚀 Server ready at ${url}`)
40+
const { url } = await startStandaloneServer(server);
41+
console.log(`🚀 Server ready at ${url}`);
4242
```
4343

4444
Apollo Server has a built in standalone HTTP server and middleware for Express, and has an framework integration API that supports all [Node.js HTTP server frameworks and serverless environments](https://www.apollographql.com/docs/apollo-server/integrations/integration-index) via community integrations.

0 commit comments

Comments
 (0)