Skip to content

Commit c3488e3

Browse files
deps(global): try to bump graphql to 16.x (#34)
* deps(global): try to bump graphql to 16.x * fix(global): fix cache-hints and errors * fix(global): fix types * missmatch * fix(global): fix eslint
1 parent d834613 commit c3488e3

File tree

13 files changed

+372
-384
lines changed

13 files changed

+372
-384
lines changed

examples/blog/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"date-fns": "^2.22.1",
4040
"dotenv": "^8.6.0",
4141
"express": "^4.17.1",
42-
"graphql": "^15.5.0",
42+
"graphql": "^16.10.0",
4343
"isomorphic-unfetch": "^3.1.0",
4444
"next": "10.2.3",
4545
"react": "^17.0.2",

examples/meetup/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"express": "^4.17.1",
3838
"facepaint": "^1.2.1",
3939
"get-contrast": "^2.0.0",
40-
"graphql": "^15.5.0",
40+
"graphql": "^16.10.0",
4141
"isomorphic-unfetch": "^3.1.0",
4242
"lodash.uniqby": "^4.7.0",
4343
"next": "10.2.3",

packages/app-admin-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"express-history-api-fallback": "^2.2.1",
5757
"falsey": "^1.0.0",
5858
"file-loader": "^6.2.0",
59-
"graphql": "^15.5.0",
59+
"graphql": "^16.10.0",
6060
"html-webpack-plugin": "^4.5.2",
6161
"lodash.debounce": "^4.0.8",
6262
"lodash.set": "^4.3.2",

packages/app-graphql/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class GraphQLApp {
2525
/**
2626
* @return Array<middlewares>
2727
*/
28-
prepareMiddleware({ keystone, dev }) {
29-
const server = keystone.createApolloServer({
28+
async prepareMiddleware({ keystone, dev }) {
29+
const server = await keystone.createApolloServer({
3030
apolloConfig: this._apollo,
3131
schemaName: this._schemaName,
3232
dev,

packages/app-graphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@open-keystone/app-graphql-playground": "workspace:^",
1212
"@open-keystone/session": "workspace:^",
1313
"@open-keystone/utils": "workspace:^",
14-
"graphql": "^15.5.0",
14+
"graphql": "^16.10.0",
1515
"graphql-upload": "^15.0.2",
1616
"nanoassert": "^2.0.0"
1717
},

packages/fields/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"date-fns": "^2.22.1",
4848
"decimal.js": "^10.2.1",
4949
"dumb-passwords": "^0.2.1",
50-
"graphql": "^15.5.0",
50+
"graphql": "^16.10.0",
5151
"image-extensions": "^1.1.0",
5252
"inflection": "^1.13.1",
5353
"intersection-observer": "^0.12.0",

packages/keystone/lib/Keystone/index.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const { ApolloServer, gql } = require('apollo-server-express');
2+
const { ApolloServerPluginCacheControl } = require('apollo-server-core');
23
const flattenDeep = require('lodash.flattendeep');
34
const memoize = require('micro-memoize');
45
const falsey = require('falsey');
56
const createCorsMiddleware = require('cors');
67
const { execute, print } = require('graphql');
8+
const { makeExecutableSchema } = require('@graphql-tools/schema');
79
const GraphQLUpload = require('graphql-upload/GraphQLUpload.js');
810
const { arrayToObject, objMerge, flatten, unique, filterValues } = require('@open-keystone/utils');
911
const {
@@ -226,7 +228,8 @@ module.exports = class Keystone {
226228
query = gql(query);
227229
}
228230

229-
return execute(schema, query, null, context, variables);
231+
// return execute(schema, query, null, context, variables);
232+
return execute({ schema, document: query, contextValue: context, variableValues: variables });
230233
}
231234

232235
createAuthStrategy(options) {
@@ -443,11 +446,20 @@ module.exports = class Keystone {
443446
}
444447
}
445448

446-
createApolloServer({ apolloConfig = {}, schemaName, dev }) {
449+
async createApolloServer({ apolloConfig = {}, schemaName }) {
447450
// add the Admin GraphQL API
451+
452+
const typeDefs = this.getTypeDefs({ schemaName });
453+
const resolvers = this.getResolvers({ schemaName });
454+
const { parseOptions } = apolloConfig;
455+
const schema = makeExecutableSchema({
456+
typeDefs,
457+
resolvers,
458+
parseOptions,
459+
});
460+
448461
const server = new ApolloServer({
449-
typeDefs: this.getTypeDefs({ schemaName }),
450-
resolvers: this.getResolvers({ schemaName }),
462+
schema,
451463
context: ({ req }) => ({
452464
...this.createContext({
453465
schemaName,
@@ -457,22 +469,20 @@ module.exports = class Keystone {
457469
...this._sessionManager.getContext(req),
458470
req,
459471
}),
460-
...(process.env.ENGINE_API_KEY || process.env.APOLLO_KEY
461-
? {
462-
tracing: true,
463-
}
464-
: {
465-
engine: false,
466-
// Only enable tracing in dev mode so we can get local debug info, but
467-
// don't bother returning that info on prod when the `engine` is
468-
// disabled.
469-
tracing: dev,
470-
}),
471472
formatError,
472473
...apolloConfig,
473-
uploads: false, // User cannot override this as it would clash with the upload middleware
474+
plugins: [
475+
...(apolloConfig.plugins || []),
476+
ApolloServerPluginCacheControl({
477+
calculateHttpHeaders: true,
478+
defaultMaxAge: 0,
479+
}),
480+
],
474481
});
475-
this._schemas[schemaName] = server.schema;
482+
483+
await server.start();
484+
485+
this._schemas[schemaName] = schema;
476486

477487
return server;
478488
}
@@ -607,7 +617,7 @@ module.exports = class Keystone {
607617
pinoOptions,
608618
cors = { origin: true, credentials: true },
609619
} = {}) {
610-
this.createApolloServer({ schemaName: 'internal' });
620+
await this.createApolloServer({ schemaName: 'internal' });
611621
const middlewares = await this._prepareMiddlewares({ dev, apps, distDir, pinoOptions, cors });
612622
// These function can't be called after prepare(), so make them throw an error from now on.
613623
['extendGraphQLSchema', 'createList', 'createAuthStrategy'].forEach(f => {

packages/keystone/lib/ListTypes/list.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,15 @@ module.exports = class List {
489489
}
490490

491491
async listQueryMeta(args, context, gqlName, info, from) {
492+
if (info?.cacheControl) {
493+
const opName = info.operation?.name?.value;
494+
const hint =
495+
typeof this.cacheHint === 'function'
496+
? this.cacheHint({ results: [], operationName: opName, meta: true })
497+
: this.cacheHint;
498+
if (hint) info.cacheControl.setCacheHint(hint);
499+
}
500+
492501
return {
493502
// Return these as functions so they're lazily evaluated depending
494503
// on what the user requested

packages/keystone/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
},
1010
"bin": "bin/cli.js",
1111
"dependencies": {
12+
"@graphql-tools/schema": "^8.0.0",
1213
"@open-keystone/access-control": "workspace:^",
1314
"@open-keystone/app-version": "workspace:^",
1415
"@open-keystone/session": "workspace:^",
1516
"@open-keystone/utils": "workspace:^",
1617
"apollo-errors": "^1.9.0",
17-
"apollo-server-express": "^2.23.0",
18+
"apollo-server-core": "3.13.0",
19+
"apollo-server-express": "3.13.0",
1820
"arg": "^5.0.0",
1921
"chalk": "^4.1.1",
2022
"ci-info": "^3.2.0",
@@ -27,7 +29,7 @@
2729
"falsey": "^1.0.0",
2830
"fs-extra": "^9.1.0",
2931
"globby": "^11.0.3",
30-
"graphql": "^15.5.0",
32+
"graphql": "^16.10.0",
3133
"graphql-type-json": "^0.3.2",
3234
"graphql-upload": "^15.0.2",
3335
"lodash.flattendeep": "^4.4.0",

packages/session/src/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class SessionManager {
121121
next();
122122
};
123123

124+
// @ts-ignore
124125
return [injectAuthCookieMiddleware, sessionMiddleware, _populateAuthedItemMiddleware];
125126
}
126127

0 commit comments

Comments
 (0)