Skip to content

Commit 2032729

Browse files
committed
feat: add Altair IDE
1 parent 4761ee8 commit 2032729

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import express from 'express';
44
import cors from 'cors';
55
import graphqlHTTP from 'express-graphql';
66
import expressPlayground from 'graphql-playground-middleware-express';
7+
import { altairExpress } from 'altair-express-middleware';
78
import { mainPage, addToMainPage } from './mainPage';
89
import { expressPort, getExampleNames, resolveExamplePath } from './config';
910
import './mongooseConnection';
@@ -29,22 +30,23 @@ server.get('/', (req, res) => {
2930
});
3031

3132
server.listen(expressPort, () => {
32-
console.log(`The server is running at http://localhost:${expressPort}/`);
33+
console.log(`🚀🚀🚀 The server is running at http://localhost:${expressPort}/`);
3334
});
3435

3536
function addExample(example, uri) {
3637
example.uri = `/${uri}`; // eslint-disable-line
3738
server.use(
3839
example.uri,
39-
graphqlHTTP(() => ({
40+
(graphqlHTTP(() => ({
4041
schema: example.schema,
4142
graphiql: true,
42-
customFormatErrorFn: error => ({
43+
customFormatErrorFn: (error) => ({
4344
message: error.message,
4445
stack: !error.message.match(/for security reason/i) ? error.stack.split('\n') : null,
4546
}),
46-
}))
47+
})): any)
4748
);
4849
server.get(`${example.uri}-playground`, expressPlayground({ endpoint: example.uri }));
50+
server.use(`${example.uri}-altair`, altairExpress({ endpointURL: example.uri }));
4951
addToMainPage(example);
5052
}

mainPage.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ export function addToMainPage(example: any) {
99
}
1010

1111
function renderExamplesLinks() {
12-
const examplesHtml = examplesMeta.map(meta => {
12+
const examplesHtml = examplesMeta.map((meta) => {
1313
const titleHtml = `<h4>
1414
${meta.title}
1515
${
1616
meta.github
17-
? `<small><a href="${
18-
meta.github
19-
}" target="_blank">GitHub <span class="glyphicon glyphicon-new-window"></span></a></small>`
17+
? `<small><a href="${meta.github}" target="_blank">GitHub <span class="glyphicon glyphicon-new-window"></span></a></small>`
2018
: ''
2119
}
2220
</h4>`;
@@ -26,15 +24,16 @@ function renderExamplesLinks() {
2624
descriptionHtml = `<p>${meta.description}</p>`;
2725
}
2826

29-
const queries = meta.queries.map(queryData => {
27+
const queries = meta.queries.map((queryData) => {
3028
return `<b><a href="${meta.uri}/?query=${qs.escape(queryData.query)}" target="_blank">${
3129
queryData.title
3230
}</a></b>`;
3331
});
3432
queries.push(
35-
`<b><a href="${
36-
meta.uri
37-
}-playground" target="_blank">GraphQL Playground</a> (improved GraphiQL IDE)</b>`
33+
`<b><a href="${meta.uri}-playground" target="_blank">GraphQL Playground</a> (improved GraphiQL IDE)</b>`
34+
);
35+
queries.push(
36+
`<b><a href="${meta.uri}-altair" target="_blank">Altair</a> (improved GraphiQL IDE)</b>`
3837
);
3938
const queriesHtml = `<ul><li>${queries.join('</li><li>')}</li></ul>`;
4039

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@
3434
"@babel/plugin-transform-flow-strip-types": "7.8.3",
3535
"@babel/preset-env": "7.8.4",
3636
"@babel/preset-flow": "7.8.3",
37-
"@babel/cli": "7.5.0",
38-
"@babel/core": "7.5.4",
39-
"@babel/node": "7.5.0",
40-
"@babel/plugin-proposal-object-rest-spread": "7.5.4",
41-
"@babel/plugin-transform-flow-strip-types": "7.4.4",
42-
"@babel/preset-env": "7.5.4",
43-
"@babel/preset-flow": "7.0.0",
44-
"aws-sdk": "2.490.0",
37+
"altair-express-middleware": "^2.4.3",
4538
"aws-sdk": "2.614.0",
4639
"cors": "2.8.5",
4740
"elasticsearch": "16.6.0",

0 commit comments

Comments
 (0)