From 8b552000fc8684e7aa1270fd41b809b10e3e76fd Mon Sep 17 00:00:00 2001 From: Alasdair McLeay Date: Wed, 26 Sep 2018 11:36:13 +0100 Subject: [PATCH 1/4] initial attempt at getting graphql-playground-react to work when offline --- packages/apollo-server-express/package.json | 1 + packages/apollo-server-express/src/ApolloServer.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/packages/apollo-server-express/package.json b/packages/apollo-server-express/package.json index 34369e03f24..8a93a101b81 100644 --- a/packages/apollo-server-express/package.json +++ b/packages/apollo-server-express/package.json @@ -41,6 +41,7 @@ "apollo-server-core": "file:../apollo-server-core", "body-parser": "^1.18.3", "cors": "^2.8.4", + "graphql-playground-react": "^1.7.4", "graphql-subscriptions": "^0.5.8", "graphql-tools": "^3.0.4", "type-is": "^1.6.16" diff --git a/packages/apollo-server-express/src/ApolloServer.ts b/packages/apollo-server-express/src/ApolloServer.ts index 2205414cb21..f0e272087f9 100644 --- a/packages/apollo-server-express/src/ApolloServer.ts +++ b/packages/apollo-server-express/src/ApolloServer.ts @@ -140,6 +140,13 @@ export class ApolloServer extends ApolloServerBase { app.use(path, uploadsMiddleware); } + // mount graphql-playground-react on localhost so that it can be used offline + // TODO: how to ensure path to node_modules will always resolve, e.g. when used as a dependency or npm link? + app.use( + '/graphql-playground-react', + express.static('node_modules/graphql-playground-react/'), + ); + // Note: if you enable playground in production and expect to be able to see your // schema, you'll need to manually specify `introspection: true` in the // ApolloServer constructor; by default, the introspection query is only @@ -161,6 +168,8 @@ export class ApolloServer extends ApolloServerBase { endpoint: path, subscriptionEndpoint: this.subscriptionsPath, ...this.playgroundOptions, + cdnUrl: '/graphql-playground-react', + version: '', }; res.setHeader('Content-Type', 'text/html'); const playground = renderPlaygroundPage(playgroundRenderPageOptions); From 7af129200a2e87e1ac3a735e7165bb880298cd9e Mon Sep 17 00:00:00 2001 From: Alasdair McLeay Date: Mon, 18 Mar 2019 14:37:26 +0000 Subject: [PATCH 2/4] use require.resolve to get path to graphql-playground-react --- packages/apollo-server-express/src/ApolloServer.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/apollo-server-express/src/ApolloServer.ts b/packages/apollo-server-express/src/ApolloServer.ts index 85bcc8baefb..572cca102cd 100644 --- a/packages/apollo-server-express/src/ApolloServer.ts +++ b/packages/apollo-server-express/src/ApolloServer.ts @@ -181,7 +181,9 @@ export class ApolloServer extends ApolloServerBase { // TODO: how to ensure path to node_modules will always resolve, e.g. when used as a dependency or npm link? app.use( '/graphql-playground-react', - express.static('node_modules/graphql-playground-react/'), + express.static( + require.resolve('graphql-playground-react/package.json').slice(0, -12), + ), ); // Note: if you enable playground in production and expect to be able to see your From 0add0e744618c586c89cfe3de2967bd011555c8b Mon Sep 17 00:00:00 2001 From: Alasdair McLeay Date: Mon, 18 Mar 2019 14:37:38 +0000 Subject: [PATCH 3/4] update graphql-playground-react --- packages/apollo-server-express/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apollo-server-express/package.json b/packages/apollo-server-express/package.json index c2083e118b8..73529e4553f 100644 --- a/packages/apollo-server-express/package.json +++ b/packages/apollo-server-express/package.json @@ -35,7 +35,7 @@ "apollo-server-core": "file:../apollo-server-core", "body-parser": "^1.18.3", "cors": "^2.8.4", - "graphql-playground-react": "^1.7.4", + "graphql-playground-react": "^1.7.20", "graphql-subscriptions": "^1.0.0", "graphql-tools": "^4.0.0", "type-is": "^1.6.16" From 41e42be4e02341dfa830fa7ba06e2c0af0291952 Mon Sep 17 00:00:00 2001 From: Alasdair McLeay Date: Mon, 18 Mar 2019 14:40:16 +0000 Subject: [PATCH 4/4] remove resolved TODO --- packages/apollo-server-express/src/ApolloServer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/apollo-server-express/src/ApolloServer.ts b/packages/apollo-server-express/src/ApolloServer.ts index 572cca102cd..9d1f8bedae7 100644 --- a/packages/apollo-server-express/src/ApolloServer.ts +++ b/packages/apollo-server-express/src/ApolloServer.ts @@ -178,7 +178,6 @@ export class ApolloServer extends ApolloServerBase { } // mount graphql-playground-react on localhost so that it can be used offline - // TODO: how to ensure path to node_modules will always resolve, e.g. when used as a dependency or npm link? app.use( '/graphql-playground-react', express.static(