Skip to content

Commit 67400bc

Browse files
committed
feat: upgrade to @apollo/server 4 and graphql 16
1 parent 8c2d4be commit 67400bc

File tree

28 files changed

+706
-817
lines changed

28 files changed

+706
-817
lines changed

examples/accounts-microservice/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
"@accounts/mongo": "^0.34.0",
1919
"@accounts/password": "^0.32.1",
2020
"@accounts/server": "^0.33.1",
21+
"@apollo/server": "4.7.1",
22+
"@apollo/server-plugin-landing-page-graphql-playground": "4.0.1",
2123
"@graphql-tools/delegate": "9.0.35",
2224
"@graphql-tools/merge": "8.4.2",
2325
"@graphql-tools/schema": "9.0.19",
2426
"@graphql-tools/stitch": "8.7.50",
2527
"@graphql-tools/utils": "9.2.1",
2628
"@graphql-tools/wrap": "9.4.2",
27-
"apollo-server": "3.12.0",
28-
"graphql": "15.8.0",
29+
"graphql": "16.6.0",
2930
"graphql-modules": "2.1.2",
3031
"lodash": "4.17.21",
3132
"node-fetch": "2.6.11",

examples/accounts-microservice/src/accounts-microservice.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import 'reflect-metadata';
22
import { buildSchema, context, createAccountsCoreModule } from '@accounts/module-core';
33
import { createAccountsPasswordModule } from '@accounts/module-password';
44
import { createAccountsMongoModule } from '@accounts/module-mongo';
5-
import { ApolloServer, gql } from 'apollo-server';
6-
import { createApplication, createModule } from 'graphql-modules';
5+
import { createApplication, createModule, gql } from 'graphql-modules';
76
import { AuthenticationServicesToken } from '@accounts/server';
87
import { AccountsPassword } from '@accounts/password';
8+
import { ApolloServer } from '@apollo/server';
9+
import { startStandaloneServer } from '@apollo/server/standalone';
10+
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
11+
import { ApolloServerPluginLandingPageGraphQLPlayground } from '@apollo/server-plugin-landing-page-graphql-playground';
912

1013
(async () => {
1114
const typeDefs = gql`
@@ -55,13 +58,22 @@ import { AccountsPassword } from '@accounts/password';
5558
schemaBuilder: buildSchema({ typeDefs }),
5659
});
5760

61+
const schema = app.createSchemaForApollo();
62+
5863
// Create the Apollo Server that takes a schema and configures internal stuff
5964
const server = new ApolloServer({
60-
schema: app.createSchemaForApollo(),
61-
context: async ({ req }) => context({ req }, { injector: app.injector }),
65+
schema,
66+
plugins: [
67+
process.env.NODE_ENV === 'production'
68+
? ApolloServerPluginLandingPageDisabled()
69+
: ApolloServerPluginLandingPageGraphQLPlayground(),
70+
],
6271
});
6372

64-
server.listen(4003).then(({ url }) => {
65-
console.log(`🚀 Server ready at ${url}`);
73+
const { url } = await startStandaloneServer(server, {
74+
listen: { port: 4003 },
75+
context: (ctx) => context(ctx, { app }),
6676
});
77+
78+
console.log(`🚀 Server ready at ${url}`);
6779
})();

examples/accounts-microservice/src/app-server.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import {
1212
createAccountsCoreModule,
1313
} from '@accounts/module-core';
1414
import { createAccountsPasswordModule } from '@accounts/module-password';
15-
import { ApolloServer, gql } from 'apollo-server';
1615
import { delegateToSchema } from '@graphql-tools/delegate';
17-
import { createApplication, createModule } from 'graphql-modules';
16+
import { createApplication, createModule, gql } from 'graphql-modules';
1817
import { AuthenticationServicesToken } from '@accounts/server';
1918
import { AccountsPassword } from '@accounts/password';
19+
import { ApolloServer } from '@apollo/server';
20+
import { startStandaloneServer } from '@apollo/server/standalone';
21+
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
22+
import { ApolloServerPluginLandingPageGraphQLPlayground } from '@apollo/server-plugin-landing-page-graphql-playground';
2023

2124
const accountsServerUri = 'http://localhost:4003/';
2225

@@ -124,13 +127,22 @@ const accountsServerUri = 'http://localhost:4003/';
124127
),
125128
});
126129

130+
const schema = app.createSchemaForApollo();
131+
127132
// Create the Apollo Server that takes a schema and configures internal stuff
128133
const server = new ApolloServer({
129-
schema: app.createSchemaForApollo(),
130-
context: async ({ req }) => context({ req }, { injector: app.injector }),
134+
schema,
135+
plugins: [
136+
process.env.NODE_ENV === 'production'
137+
? ApolloServerPluginLandingPageDisabled()
138+
: ApolloServerPluginLandingPageGraphQLPlayground(),
139+
],
131140
});
132141

133-
server.listen(4000).then(({ url }) => {
134-
console.log(`🚀 Server ready at ${url}`);
142+
const { url } = await startStandaloneServer(server, {
143+
listen: { port: 4000 },
144+
context: (ctx) => context(ctx, { app }),
135145
});
146+
147+
console.log(`🚀 Server ready at ${url}`);
136148
})();

examples/graphql-server-mikro-orm-postgres/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"@accounts/module-password": "^0.34.0",
2626
"@accounts/password": "^0.32.1",
2727
"@accounts/server": "^0.33.1",
28+
"@apollo/server": "4.7.1",
29+
"@apollo/server-plugin-landing-page-graphql-playground": "4.0.1",
2830
"graphql-modules": "2.1.2",
2931
"@graphql-tools/merge": "8.4.2",
3032
"@graphql-tools/schema": "9.0.19",
31-
"apollo-server": "3.12.0",
32-
"apollo-server-core": "3.12.0",
33-
"graphql": "15.8.0",
33+
"graphql": "16.6.0",
3434
"@mikro-orm/cli": "5.7.9",
3535
"@mikro-orm/core": "5.7.9",
3636
"@mikro-orm/entity-generator": "5.7.9",

examples/graphql-server-mikro-orm-postgres/src/index.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import 'reflect-metadata';
2-
import { ApolloServer, gql } from 'apollo-server';
32
import { buildSchema, createAccountsCoreModule } from '@accounts/module-core';
43
import { createAccountsPasswordModule } from '@accounts/module-password';
54
import { AccountsPassword } from '@accounts/password';
65
import { MikroORM } from '@mikro-orm/core';
76
import config from './mikro-orm-config';
87
import { User } from './entities/user';
98
import { Email } from './entities/email';
10-
import { createApplication } from 'graphql-modules';
9+
import { createApplication, gql } from 'graphql-modules';
1110
import AccountsServer, { AuthenticationServicesToken, ServerHooks } from '@accounts/server';
1211
import { context, createAccountsMikroORMModule } from '@accounts/module-mikro-orm';
12+
import { ApolloServer } from '@apollo/server';
13+
import { startStandaloneServer } from '@apollo/server/standalone';
14+
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
15+
import { ApolloServerPluginLandingPageGraphQLPlayground } from '@apollo/server-plugin-landing-page-graphql-playground';
1316

1417
export const createAccounts = async () => {
1518
const orm = await MikroORM.init(config);
@@ -109,6 +112,15 @@ export const createAccounts = async () => {
109112
// Create the Apollo Server that takes a schema and configures internal stuff
110113
const server = new ApolloServer({
111114
schema,
115+
plugins: [
116+
process.env.NODE_ENV === 'production'
117+
? ApolloServerPluginLandingPageDisabled()
118+
: ApolloServerPluginLandingPageGraphQLPlayground(),
119+
],
120+
});
121+
122+
const { url } = await startStandaloneServer(server, {
123+
listen: { port: 4000 },
112124
context: (ctx) =>
113125
context(ctx, {
114126
app,
@@ -117,15 +129,13 @@ export const createAccounts = async () => {
117129
}),
118130
});
119131

120-
server.listen(4000).then(async ({ url }) => {
121-
console.log(`🚀 Server ready at ${url}`);
132+
console.log(`🚀 Server ready at ${url}`);
122133

123-
try {
124-
const generator = orm.getSchemaGenerator();
125-
await generator.createSchema({ wrap: true });
126-
} catch {
127-
// Schema has already been created
128-
}
129-
});
134+
try {
135+
const generator = orm.getSchemaGenerator();
136+
await generator.createSchema({ wrap: true });
137+
} catch {
138+
// Schema has already been created
139+
}
130140
};
131141
createAccounts();

examples/graphql-server-typeorm-postgres/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
"@accounts/password": "^0.32.2",
1919
"@accounts/server": "^0.33.1",
2020
"@accounts/typeorm": "^0.34.0",
21+
"@apollo/server": "4.7.1",
22+
"@apollo/server-plugin-landing-page-graphql-playground": "4.0.1",
2123
"@graphql-tools/merge": "8.4.2",
22-
"apollo-server": "3.12.0",
2324
"dotenv": "10.0.0",
24-
"graphql": "15.8.0",
25+
"graphql": "16.6.0",
2526
"graphql-modules": "2.1.2",
2627
"pg": "8.11.0",
2728
"tslib": "2.5.2",

examples/graphql-server-typeorm-postgres/src/index.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
require('dotenv').config();
1+
import 'dotenv/config';
22
import 'reflect-metadata';
3-
import { ApolloServer, gql } from 'apollo-server';
43
import { AccountsPassword } from '@accounts/password';
54
import { AccountsServer, AuthenticationServicesToken } from '@accounts/server';
65
import { connect } from './connect';
7-
import { createApplication } from 'graphql-modules';
6+
import { createApplication, gql } from 'graphql-modules';
87
import { buildSchema, context, createAccountsCoreModule } from '@accounts/module-core';
98
import { createAccountsPasswordModule } from '@accounts/module-password';
109
import { createAccountsTypeORMModule } from '@accounts/module-typeorm';
10+
import { ApolloServer } from '@apollo/server';
11+
import { startStandaloneServer } from '@apollo/server/standalone';
12+
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
13+
import { ApolloServerPluginLandingPageGraphQLPlayground } from '@apollo/server-plugin-landing-page-graphql-playground';
1114

1215
export const createAccounts = async () => {
1316
const connection = await connect(process.env.DATABASE_URL);
@@ -53,7 +56,7 @@ export const createAccounts = async () => {
5356
// ctx.userId will be set if user is logged in
5457
if (ctx.userId) {
5558
// We could have simply returned ctx.user instead
56-
return ctx.accountsServer.findUserById(ctx.userId);
59+
return ctx.injector.get(AccountsServer).findUserById(ctx.userId);
5760
}
5861
return null;
5962
},
@@ -83,22 +86,23 @@ export const createAccounts = async () => {
8386
],
8487
schemaBuilder: buildSchema({ typeDefs, resolvers }),
8588
});
86-
const { injector } = app;
8789
const schema = app.createSchemaForApollo();
8890

8991
// Create the Apollo Server that takes a schema and configures internal stuff
9092
const server = new ApolloServer({
9193
schema,
92-
context: async ({ req }) => ({
93-
...(await context({ req }, { injector })),
94-
// If you don't use GraphQL Modules in your app you will have to share the
95-
// accountsServer instance via context in order to access it via resolvers
96-
accountsServer: injector.get(AccountsServer),
97-
}),
94+
plugins: [
95+
process.env.NODE_ENV === 'production'
96+
? ApolloServerPluginLandingPageDisabled()
97+
: ApolloServerPluginLandingPageGraphQLPlayground(),
98+
],
9899
});
99100

100-
server.listen(4000).then(async ({ url }) => {
101-
console.log(`🚀 Server ready at ${url}`);
101+
const { url } = await startStandaloneServer(server, {
102+
listen: { port: 4000 },
103+
context: (ctx) => context(ctx, { app }),
102104
});
105+
106+
console.log(`🚀 Server ready at ${url}`);
103107
};
104108
createAccounts();

examples/graphql-server-typescript/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"@accounts/password": "^0.32.2",
1717
"@accounts/rest-express": "^0.33.1",
1818
"@accounts/server": "^0.33.1",
19+
"@apollo/server": "4.7.1",
20+
"@apollo/server-plugin-landing-page-graphql-playground": "4.0.1",
1921
"@graphql-tools/merge": "8.4.2",
2022
"@graphql-tools/schema": "9.0.19",
21-
"apollo-server": "3.12.0",
22-
"apollo-server-core": "3.12.0",
23-
"graphql": "15.8.0",
23+
"graphql": "16.6.0",
2424
"graphql-modules": "2.1.2",
2525
"graphql-tag": "2.12.6",
2626
"mongoose": "7.2.0",

examples/graphql-server-typescript/src/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ import {
88
import { createAccountsPasswordModule } from '@accounts/module-password';
99
import { AccountsPassword } from '@accounts/password';
1010
import { AccountsServer, AuthenticationServicesToken, ServerHooks } from '@accounts/server';
11-
import { ApolloServer } from 'apollo-server';
1211
import gql from 'graphql-tag';
1312
import mongoose from 'mongoose';
1413
import { createApplication } from 'graphql-modules';
1514
import { createAccountsMongoModule } from '@accounts/module-mongo';
16-
import {
17-
ApolloServerPluginLandingPageGraphQLPlayground,
18-
ApolloServerPluginLandingPageDisabled,
19-
} from 'apollo-server-core';
15+
import { ApolloServer } from '@apollo/server';
16+
import { startStandaloneServer } from '@apollo/server/standalone';
17+
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
18+
import { ApolloServerPluginLandingPageGraphQLPlayground } from '@apollo/server-plugin-landing-page-graphql-playground';
2019

2120
const start = async () => {
2221
// Create database connection
@@ -126,17 +125,19 @@ const start = async () => {
126125
// Create the Apollo Server that takes a schema and configures internal stuff
127126
const server = new ApolloServer({
128127
schema,
129-
context: (ctx) => context(ctx, { app }),
130128
plugins: [
131129
process.env.NODE_ENV === 'production'
132130
? ApolloServerPluginLandingPageDisabled()
133131
: ApolloServerPluginLandingPageGraphQLPlayground(),
134132
],
135133
});
136134

137-
server.listen(4000).then(({ url }) => {
138-
console.log(`🚀 Server ready at ${url}`);
135+
const { url } = await startStandaloneServer(server, {
136+
listen: { port: 4000 },
137+
context: (ctx) => context(ctx, { app }),
139138
});
139+
140+
console.log(`🚀 Server ready at ${url}`);
140141
};
141142

142143
start();

examples/react-graphql-typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@apollo/client": "3.7.14",
3535
"@material-ui/core": "4.12.3",
3636
"@material-ui/styles": "4.11.4",
37-
"graphql": "15.8.0",
37+
"graphql": "16.6.0",
3838
"graphql-tag": "2.12.6",
3939
"qrcode.react": "1.0.1",
4040
"react": "17.0.2",

0 commit comments

Comments
 (0)