Skip to content

Commit 142176a

Browse files
committed
fix(start): Return Server instance in .start method
In order to include yoga in a CI environment, it's important to have access to the HTTP Server instance to use the 0 port.
1 parent aa27925 commit 142176a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/index.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { execute, GraphQLSchema, subscribe } from 'graphql'
1313
import { importSchema } from 'graphql-import'
1414
import expressPlayground from 'graphql-playground-middleware-express'
1515
import { makeExecutableSchema } from 'graphql-tools'
16-
import { createServer } from 'http'
16+
import { createServer, Server } from 'http'
1717
import * as path from 'path'
1818
import { SubscriptionServer } from 'subscriptions-transport-ws'
1919

@@ -39,8 +39,8 @@ export class GraphQLServer {
3939
private middlewares: {
4040
[key: string]: {
4141
path?: PathParams
42-
handlers: RequestHandler[] | RequestHandlerParams[],
43-
}[],
42+
handlers: RequestHandler[] | RequestHandlerParams[]
43+
}[]
4444
} = { use: [], get: [], post: [] }
4545

4646
constructor(props: Props) {
@@ -101,12 +101,12 @@ export class GraphQLServer {
101101
start(
102102
options: Options,
103103
callback?: ((options: Options) => void),
104-
): Promise<void>
105-
start(callback?: ((options: Options) => void)): Promise<void>
104+
): Promise<Server>
105+
start(callback?: ((options: Options) => void)): Promise<Server>
106106
start(
107107
optionsOrCallback?: Options | ((options: Options) => void),
108108
callback?: ((options: Options) => void),
109-
): Promise<void> {
109+
): Promise<Server> {
110110
const options =
111111
optionsOrCallback && typeof optionsOrCallback === 'function'
112112
? {}
@@ -208,7 +208,10 @@ export class GraphQLServer {
208208

209209
if (this.options.playground) {
210210
const playgroundOptions = this.options.subscriptions
211-
? { endpoint: this.options.endpoint, subscriptionsEndpoint: this.options.subscriptions }
211+
? {
212+
endpoint: this.options.endpoint,
213+
subscriptionsEndpoint: this.options.subscriptions,
214+
}
212215
: { endpoint: this.options.endpoint }
213216

214217
app.get(this.options.playground, expressPlayground(playgroundOptions))
@@ -229,7 +232,7 @@ export class GraphQLServer {
229232

230233
combinedServer.listen(this.options.port, () => {
231234
callbackFunc(this.options)
232-
resolve()
235+
resolve(combinedServer)
233236
})
234237

235238
this.subscriptionServer = SubscriptionServer.create(

0 commit comments

Comments
 (0)