Skip to content

Commit

Permalink
Automatically set Auth headers and add preRQ script
Browse files Browse the repository at this point in the history
- Automatically install the GQL explorer plugin
- Update Altair version
  • Loading branch information
Mythicaeda committed Dec 6, 2023
1 parent 7eb3d6f commit de528eb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"start": "node dist/main.js"
},
"dependencies": {
"altair-express-middleware": "^5.0.28",
"altair-express-middleware": "^5.2.11",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-rate-limit": "^6.7.0",
Expand Down
41 changes: 40 additions & 1 deletion src/packages/api-playground/api-playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,44 @@ import { getEnv } from '../../env.js';
export default (app: Express) => {
const { GQL_API_URL: endpointURL, GQL_API_WS_URL: subscriptionsEndpoint } = getEnv();
const initialQuery = '{ plan { id name } }';
app.use('/api-playground', altairExpress({ endpointURL, initialQuery, subscriptionsEndpoint }));
const initialHeaders = { Authorization: 'Bearer {{user}}', 'x-hasura-role': 'viewer' };
const initialPreRequestScript =
`
// Fetch a new token from the Gateway
const res = await altair.helpers.request(
'POST',
'/auth/login', // AUTH ENDPOINT OF THE DEPLOYMENT
{
body: { "username": "<YOUR_AERIE_USERNAME>", "password": "<YOUR_AERIE_PASSWORD>"}, // CREDENTIALS TO LOG IN AS
headers: {"Content-Type": "application/json"}
});
if(res.success) {
const token = res.token;
await altair.helpers.setEnvironment("user", token);
} else {
altair.log(res);
}`;
const initialSettings = {
addQueryDepthLimit: 5,
enableExperimental: true,
'plugin.list': ['altair-graphql-plugin-graphql-explorer'],
'request.withCredentials': true,
'schema.reloadOnStart': true,
'script.allowedCookies': ['user'],
tabSize: 2,
theme: 'dracula',
};

app.use(
'/api-playground',
altairExpress({
disableAccount: true,
endpointURL,
initialHeaders,
initialPreRequestScript,
initialQuery,
initialSettings,
subscriptionsEndpoint,
}),
);
};

0 comments on commit de528eb

Please sign in to comment.