Adding GraphQL playground option to server.

This commit is contained in:
Alejandro Lembke Barrientos 2022-06-05 02:58:11 +00:00
parent b371152812
commit 5ce9f4ff9a
5 changed files with 84 additions and 8 deletions

View File

@ -4,5 +4,7 @@ ENVIRONMENT=
WHITELIST_URLS=
#GRAPHIQL Default to "false"
GRAPHIQL=
#PLAYGROUND GRAPHQL Default to "false"
PLAYGROUND_GRAPHQL=
# PORT EXPOSE APP Default to 4000
PORT=

View File

@ -5,6 +5,7 @@ dotenv.config();
export const config = {
env: process.env.ENVIRONMENT ? process.env.ENVIRONMENT : 'production',
graphiQL: process.env.GRAPHIQL === 'true' ? true : false,
playgroundGraphQL: process.env.PLAYGROUND_GRAPHQL === 'true' ? true : false,
whiteList: process.env.WHITELIST_URLS ? process.env.WHITELIST_URLS.split(',') : [
'http://localhost'
],

80
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@aleleba/create-node-ts-graphql-server",
"version": "1.0.5",
"version": "1.0.7",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@aleleba/create-node-ts-graphql-server",
"version": "1.0.5",
"version": "1.0.7",
"license": "MIT",
"dependencies": {
"@graphql-tools/schema": "^8.3.13",
@ -17,6 +17,7 @@
"express": "^4.18.1",
"express-graphql": "^0.12.0",
"graphql": "^16.5.0",
"graphql-playground-middleware-express": "^1.7.23",
"graphql-subscriptions": "^2.0.0",
"graphql-tools": "^8.2.11",
"graphql-ws": "^5.8.2",
@ -4819,8 +4820,7 @@
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
},
"node_modules/commondir": {
"version": "1.0.1",
@ -5061,6 +5061,11 @@
"node": ">=8"
}
},
"node_modules/cssfilter": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/cssfilter/-/cssfilter-0.0.10.tgz",
"integrity": "sha512-FAaLDaplstoRsDR8XGYH51znUN0UY7nMc6Z9/fvE8EXGwvJE9hu7W2vHwx1+bd6gCYnln9nLbzxFTrcO9YQDZw=="
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -6589,6 +6594,25 @@
"node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0"
}
},
"node_modules/graphql-playground-html": {
"version": "1.6.30",
"resolved": "https://registry.npmjs.org/graphql-playground-html/-/graphql-playground-html-1.6.30.tgz",
"integrity": "sha512-tpCujhsJMva4aqE8ULnF7/l3xw4sNRZcSHu+R00VV+W0mfp+Q20Plvcrp+5UXD+2yS6oyCXncA+zoQJQqhGCEw==",
"dependencies": {
"xss": "^1.0.6"
}
},
"node_modules/graphql-playground-middleware-express": {
"version": "1.7.23",
"resolved": "https://registry.npmjs.org/graphql-playground-middleware-express/-/graphql-playground-middleware-express-1.7.23.tgz",
"integrity": "sha512-M/zbTyC1rkgiQjFSgmzAv6umMHOphYLNWZp6Ye5QrD77WfGOOoSqDsVmGUczc2pDkEPEzzGB/bvBO5rdzaTRgw==",
"dependencies": {
"graphql-playground-html": "^1.6.30"
},
"peerDependencies": {
"express": "^4.16.2"
}
},
"node_modules/graphql-subscriptions": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-2.0.0.tgz",
@ -12258,6 +12282,21 @@
"node": ">=8"
}
},
"node_modules/xss": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/xss/-/xss-1.0.12.tgz",
"integrity": "sha512-8pXgz5BUUfKMrb81tmcbvLNA97ab4d6HdoBHYF5XYHa8oarc2s64hF+oqI4FhBHVBWvEM1wHGy+vqt8kZhCaNw==",
"dependencies": {
"commander": "^2.20.3",
"cssfilter": "0.0.10"
},
"bin": {
"xss": "bin/xss"
},
"engines": {
"node": ">= 0.10.0"
}
},
"node_modules/y18n": {
"version": "5.0.8",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
@ -15881,8 +15920,7 @@
"commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
},
"commondir": {
"version": "1.0.1",
@ -16074,6 +16112,11 @@
"integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==",
"dev": true
},
"cssfilter": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/cssfilter/-/cssfilter-0.0.10.tgz",
"integrity": "sha512-FAaLDaplstoRsDR8XGYH51znUN0UY7nMc6Z9/fvE8EXGwvJE9hu7W2vHwx1+bd6gCYnln9nLbzxFTrcO9YQDZw=="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -17232,6 +17275,22 @@
"resolved": "https://registry.npmjs.org/graphql/-/graphql-16.5.0.tgz",
"integrity": "sha512-qbHgh8Ix+j/qY+a/ZcJnFQ+j8ezakqPiHwPiZhV/3PgGlgf96QMBB5/f2rkiC9sgLoy/xvT6TSiaf2nTHJh5iA=="
},
"graphql-playground-html": {
"version": "1.6.30",
"resolved": "https://registry.npmjs.org/graphql-playground-html/-/graphql-playground-html-1.6.30.tgz",
"integrity": "sha512-tpCujhsJMva4aqE8ULnF7/l3xw4sNRZcSHu+R00VV+W0mfp+Q20Plvcrp+5UXD+2yS6oyCXncA+zoQJQqhGCEw==",
"requires": {
"xss": "^1.0.6"
}
},
"graphql-playground-middleware-express": {
"version": "1.7.23",
"resolved": "https://registry.npmjs.org/graphql-playground-middleware-express/-/graphql-playground-middleware-express-1.7.23.tgz",
"integrity": "sha512-M/zbTyC1rkgiQjFSgmzAv6umMHOphYLNWZp6Ye5QrD77WfGOOoSqDsVmGUczc2pDkEPEzzGB/bvBO5rdzaTRgw==",
"requires": {
"graphql-playground-html": "^1.6.30"
}
},
"graphql-subscriptions": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-2.0.0.tgz",
@ -21405,6 +21464,15 @@
"integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==",
"dev": true
},
"xss": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/xss/-/xss-1.0.12.tgz",
"integrity": "sha512-8pXgz5BUUfKMrb81tmcbvLNA97ab4d6HdoBHYF5XYHa8oarc2s64hF+oqI4FhBHVBWvEM1wHGy+vqt8kZhCaNw==",
"requires": {
"commander": "^2.20.3",
"cssfilter": "0.0.10"
}
},
"y18n": {
"version": "5.0.8",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",

View File

@ -1,6 +1,6 @@
{
"name": "@aleleba/create-node-ts-graphql-server",
"version": "1.0.7",
"version": "1.0.8",
"description": "Node with Typescript and GraphQL Server",
"bin": "./bin/cli.js",
"main": "index.js",
@ -40,6 +40,7 @@
"express": "^4.18.1",
"express-graphql": "^0.12.0",
"graphql": "^16.5.0",
"graphql-playground-middleware-express": "^1.7.23",
"graphql-subscriptions": "^2.0.0",
"graphql-tools": "^8.2.11",
"graphql-ws": "^5.8.2",

View File

@ -7,11 +7,11 @@ import cookieParser from 'cookie-parser';
import { useServer } from 'graphql-ws/lib/use/ws';
import { execute, subscribe } from 'graphql';
import GraphQLserver from './GraphQL/server';// Server of GraphQL,
import expressPlayground from 'graphql-playground-middleware-express';
import schema from './GraphQL/schema';
import { config } from '../config';
import apiRouter from './routes';
const app = express(), //creating app
whitelist = config.whiteList,
corsOptions = {
@ -34,6 +34,10 @@ app
.use(apiRouter)//Routes de App
.use('/graphql', GraphQLserver);//Server of Graphql
if(config.playgroundGraphQL === true){
app.get('/playground', expressPlayground({ endpoint: '/graphql' }));
}
// DO NOT DO app.listen() unless we're testing this directly
if (require.main === module) {