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

Preserve auth header for playground #49

Merged
merged 7 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 54 additions & 0 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"dependencies": {
"@apollo/server": "^4.5.0",
"@prisma/client": "^4.11.0",
"@types/cookie-parser": "^1.4.3",
"bcrypt": "^5.1.0",
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
Expand Down
19 changes: 13 additions & 6 deletions api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Express } from 'express';
import express from 'express';
import expressPlayground from 'graphql-playground-middleware-express';
import cookierParser from 'cookie-parser';
import { getChildLogger } from './logger';
import prisma from './database';

Expand Down Expand Up @@ -31,12 +32,18 @@ export const createApp = (): Express => {

app.get(
'/',
expressPlayground({
endpoint: '/api/graphql',
settings: {
'editor.theme': 'light',
},
}),
cookierParser(undefined, { decode: (value: string) => value }),
(req, res, next) => {
const globalHeaders = req.cookies['gql:default'];
const playgroundMiddleware = expressPlayground({
endpoint: '/api/graphql',
settings: {
'editor.theme': 'light',
'request.globalHeaders': { Authorization: `Bearer ${globalHeaders}` },
valiafetisov marked this conversation as resolved.
Show resolved Hide resolved
},
});
playgroundMiddleware(req, res, next);
},
);

return app;
Expand Down