Skip to content

Commit d6f42df

Browse files
committed
fix(start): fixed callback and options combinations on start
server.start() All of the below now work correctly: server.start({ port: 5000 }) server.start({ port: 5000 }, ({ port }) => console.log(`server started on port ${port}`)) server.start(({ port }) => console.log(`server started on port ${port}`)) Closes #88
1 parent 04d9b55 commit d6f42df

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Diff for: src/index.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ export class GraphQLServer {
8989
return this
9090
}
9191

92-
start(options?: Options, callback: ((options: Options) => void) = () => null): Promise<void> {
92+
start(options: Options, callback?: ((options: Options) => void)): Promise<void>
93+
start(callback?: ((options: Options) => void)): Promise<void>
94+
start(optionsOrCallback?: Options | ((options: Options) => void), callback?: ((options: Options) => void)): Promise<void> {
95+
const options = (optionsOrCallback && typeof optionsOrCallback === 'function') ? {} : optionsOrCallback
96+
const callbackFunc = callback ? callback : (optionsOrCallback && typeof optionsOrCallback === 'function') ? optionsOrCallback : () => null
97+
9398
const app = this.express
9499

95100
this.options = { ...this.options, ...options }
@@ -190,14 +195,14 @@ export class GraphQLServer {
190195
return new Promise((resolve, reject) => {
191196
if (!this.options.subscriptions) {
192197
app.listen(this.options.port, () => {
193-
callback(this.options)
198+
callbackFunc(this.options)
194199
resolve()
195200
})
196201
} else {
197202
const combinedServer = createServer(app)
198203

199204
combinedServer.listen(this.options.port, () => {
200-
callback(this.options)
205+
callbackFunc(this.options)
201206
resolve()
202207
})
203208

0 commit comments

Comments
 (0)