Skip to content

Commit 38b6fab

Browse files
authored
update apollo-server implementation to AS4 (apollographql#246)
1 parent 8a8efb4 commit 38b6fab

File tree

10 files changed

+1583
-2688
lines changed

10 files changed

+1583
-2688
lines changed

implementations/apollo-server/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { readFileSync } from 'fs';
2-
import { ApolloServer, ApolloError, gql } from 'apollo-server';
2+
import { gql } from 'graphql-tag';
3+
import { GraphQLError } from 'graphql';
4+
import { ApolloServer } from '@apollo/server';
5+
import { startStandaloneServer } from '@apollo/server/standalone';
36
import { buildSubgraphSchema } from '@apollo/subgraph';
47

5-
const port = process.env.PRODUCTS_PORT || 4001;
8+
const serverPort = parseInt(process.env.PRODUCTS_PORT || "") || 4001;
69

710
const deprecatedProduct = {
811
sku: "apollo-federation-v1",
@@ -125,7 +128,7 @@ const resolvers = {
125128
/** @type {(user: { email: String, totalProductsCreated: Number, yearsOfEmployment: Number }, args: any, context: any) => any} */
126129
averageProductsCreatedPerYear: (user, args, context) => {
127130
if (user.email != "[email protected]") {
128-
throw new ApolloError("user.email was not '[email protected]'")
131+
throw new GraphQLError("user.email was not '[email protected]'")
129132
}
130133
return Math.round(user.totalProductsCreated / user.yearsOfEmployment);
131134
},
@@ -152,6 +155,6 @@ const server = new ApolloServer({
152155
schema: buildSubgraphSchema({ typeDefs, resolvers }),
153156
});
154157

155-
server
156-
.listen({ port })
157-
.then(({ url }) => console.log(`Products subgraph ready at ${url}`));
158+
startStandaloneServer(server, {
159+
listen: { port: serverPort },
160+
}).then(({ url }) => console.log(`🚀 Products subgraph ready at ${url}`));

implementations/apollo-server/package-lock.json

Lines changed: 386 additions & 666 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

implementations/apollo-server/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"name": "apollo-server-implementation",
33
"type": "module",
44
"dependencies": {
5-
"@apollo/subgraph": "^2.0.5",
6-
"apollo-server": "^3.10.1",
7-
"graphql": "^16.6.0"
5+
"@apollo/server": "^4.0.0",
6+
"@apollo/subgraph": "^2.1.3",
7+
"graphql": "^16.6.0",
8+
"graphql-tag": "^2.12.6"
89
},
910
"devDependencies": {
10-
"typescript": "^4.7.4"
11+
"typescript": "^4.8.4"
1112
}
1213
}

0 commit comments

Comments
 (0)