File tree Expand file tree Collapse file tree 6 files changed +12
-33
lines changed
graphql-playground-middleware-express
graphql-playground-middleware-hapi/src
graphql-playground-middleware-koa/src
graphql-playground-middleware-lambda Expand file tree Collapse file tree 6 files changed +12
-33
lines changed Original file line number Diff line number Diff line change 14
14
"files" : [
15
15
" dist"
16
16
],
17
- "playgroundVersion" : " 1.7.8" ,
18
17
"scripts" : {
19
18
"build" : " rimraf dist && tsc" ,
20
19
"prepare" : " npm run build"
Original file line number Diff line number Diff line change 1
1
import { Request , Response } from 'express'
2
2
import {
3
3
MiddlewareOptions ,
4
- RenderPageOptions ,
5
4
renderPlaygroundPage ,
6
5
} from 'graphql-playground-html'
7
6
8
7
/* tslint:disable */
9
- const { playgroundVersion } = require ( '../package.json' )
10
8
11
9
export type ExpressPlaygroundMiddleware = (
12
10
req : Request ,
@@ -19,14 +17,9 @@ export type Register = (
19
17
) => ExpressPlaygroundMiddleware
20
18
21
19
const express : Register = function voyagerExpress ( options : MiddlewareOptions ) {
22
- const middlewareOptions : RenderPageOptions = {
23
- ...options ,
24
- version : playgroundVersion ,
25
- }
26
-
27
20
return ( req , res , next ) => {
28
21
res . setHeader ( 'Content-Type' , 'text/html' )
29
- const playground = renderPlaygroundPage ( middlewareOptions )
22
+ const playground = renderPlaygroundPage ( options )
30
23
res . write ( playground )
31
24
res . end ( )
32
25
next ( )
Original file line number Diff line number Diff line change 5
5
renderPlaygroundPage ,
6
6
} from 'graphql-playground-html'
7
7
8
- const pkg = require ( '../package.json' )
9
-
10
8
export interface Register {
11
9
( server : Server , options : MiddlewareOptions ) : void
12
10
}
@@ -17,26 +15,29 @@ export interface Plugin {
17
15
}
18
16
19
17
const plugin : Plugin = {
20
- pkg,
21
- register : function ( server , options : any ) {
18
+ register : function ( server , options : any ) {
22
19
if ( arguments . length !== 2 ) {
23
- throw new Error ( `Playground middleware expects exactly 2 arguments, got ${ arguments . length } ` )
20
+ throw new Error (
21
+ `Playground middleware expects exactly 2 arguments, got ${
22
+ arguments . length
23
+ } `,
24
+ )
24
25
}
25
26
26
27
const { path, route : config = { } , ...rest } = options
27
28
28
29
const middlewareOptions : RenderPageOptions = {
29
30
...rest ,
30
- version : pkg . playgroundVersion ,
31
31
}
32
32
33
33
server . route ( {
34
34
method : 'GET' ,
35
35
path,
36
36
config,
37
- handler : ( request , h ) => h . response ( renderPlaygroundPage ( middlewareOptions ) ) . type ( 'text/html' )
37
+ handler : ( request , h ) =>
38
+ h . response ( renderPlaygroundPage ( middlewareOptions ) ) . type ( 'text/html' ) ,
38
39
} )
39
- }
40
+ } ,
40
41
}
41
42
42
43
export default plugin
Original file line number Diff line number Diff line change @@ -2,25 +2,18 @@ import { Context } from 'koa'
2
2
import {
3
3
MiddlewareOptions ,
4
4
renderPlaygroundPage ,
5
- RenderPageOptions ,
6
5
} from 'graphql-playground-html'
7
6
8
7
/* tslint:disable-next-line */
9
- const { playgroundVersion } = require ( '../package.json' )
10
8
11
9
export type KoaPlaygroundMiddleware = ( ctx : Context , next : ( ) => void ) => void
12
10
13
11
export type Register = ( options : MiddlewareOptions ) => KoaPlaygroundMiddleware
14
12
15
13
const koa : Register = options => {
16
- const middlewareOptions : RenderPageOptions = {
17
- ...options ,
18
- version : playgroundVersion ,
19
- }
20
-
21
14
return async function voyager ( ctx , next ) {
22
15
try {
23
- ctx . body = await renderPlaygroundPage ( middlewareOptions )
16
+ ctx . body = await renderPlaygroundPage ( options )
24
17
await next ( )
25
18
} catch ( err ) {
26
19
ctx . body = { message : err . message }
Original file line number Diff line number Diff line change 14
14
"files" : [
15
15
" dist"
16
16
],
17
- "playgroundVersion" : " 1.7.8" ,
18
17
"scripts" : {
19
18
"build" : " rimraf dist && tsc" ,
20
19
"prepare" : " npm run build"
Original file line number Diff line number Diff line change 1
1
import * as lambda from 'aws-lambda'
2
2
import {
3
3
MiddlewareOptions ,
4
- RenderPageOptions ,
5
4
renderPlaygroundPage ,
6
5
} from 'graphql-playground-html'
7
6
8
7
/* tslint:disable-next-line */
9
- const { playgroundVersion } = require ( '../package.json' )
10
8
11
9
export default function lambdaPlayground ( options : MiddlewareOptions ) {
12
10
return async (
13
11
event ,
14
12
lambdaContext : lambda . Context ,
15
13
callback : lambda . Callback ,
16
14
) => {
17
- const middlewareOptions : RenderPageOptions = {
18
- ...options ,
19
- version : playgroundVersion ,
20
- }
21
- const body = await renderPlaygroundPage ( middlewareOptions )
15
+ const body = await renderPlaygroundPage ( options )
22
16
callback ( null , {
23
17
statusCode : 200 ,
24
18
headers : {
You can’t perform that action at this time.
0 commit comments