Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting graphql-playground-react to work when offline #1734

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/apollo-server-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"apollo-server-core": "file:../apollo-server-core",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"graphql-playground-react": "^1.7.20",
"graphql-subscriptions": "^1.0.0",
"graphql-tools": "^4.0.0",
"type-is": "^1.6.16"
Expand Down
10 changes: 10 additions & 0 deletions packages/apollo-server-express/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ export class ApolloServer extends ApolloServerBase {
app.use(path, uploadsMiddleware);
}

// mount graphql-playground-react on localhost so that it can be used offline
app.use(
penx marked this conversation as resolved.
Show resolved Hide resolved
'/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
// schema, you'll need to manually specify `introspection: true` in the
// ApolloServer constructor; by default, the introspection query is only
Expand All @@ -198,6 +206,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);
Expand Down