Skip to content

Commit

Permalink
fix: Koa middleware interface (#1242)
Browse files Browse the repository at this point in the history
Added the KoaPlaygroundMiddlewareOptions alias so that packages that want to pass around or preset the options don't have to fight the `eslint(import/no-extraneous-dependencies)` warning.

Fixed the signature of KoaPlaygroundMiddleware to actually match the usage: Koa expects this signature and the previous way was making things mighty hard to use, plus any function that is async is supposed to return a Promise anyway.

I think the tslint hint could be dropped now, but I'm creating this commit from GitHub's interface no I'm not sure. Also I think both KoaPlaygroundMiddleware and Register types could be dropped and the type declarations inlined on the actual lambdas, but I don't know if the extant pattern had a good reason or was just C&P from something else.
  • Loading branch information
kf6kjg authored Aug 29, 2020
1 parent c8bd69c commit b596775
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/graphql-playground-middleware-koa/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Context } from 'koa'
import { Context, Next } from 'koa'
import {
MiddlewareOptions,
renderPlaygroundPage,
} from 'graphql-playground-html'

/* tslint:disable-next-line */
export declare type KoaPlaygroundMiddlewareOptions = MiddlewareOptions

export type KoaPlaygroundMiddleware = (ctx: Context, next: () => void) => void
/* tslint:disable-next-line */
export type KoaPlaygroundMiddleware = (ctx: Context, next: Next) => Promise<void>

export type Register = (options: MiddlewareOptions) => KoaPlaygroundMiddleware
export type Register = (options: KoaPlaygroundMiddlewareOptions) => KoaPlaygroundMiddleware

const koa: Register = options => {
return async function voyager(ctx, next) {
Expand Down

0 comments on commit b596775

Please sign in to comment.