Skip to content

Commit

Permalink
feat(apollo): support defining paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Oct 1, 2019
1 parent 42113c4 commit 11bb48f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 7 additions & 6 deletions packages/@nodepack/plugin-apollo/src/runtime/apollo-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ hook('expressHttp', async (ctx) => {
},
}))

// Express middleware
server.applyMiddleware({
app,
cors: config.cors,
path: apolloConfig.path || '/graphql',
})

// GraphQL Playground
if (apolloConfig.playground !== false) {
const playgroundRoute = ctx.playgroundRoute =
Expand All @@ -49,12 +56,6 @@ hook('expressHttp', async (ctx) => {
}))
}

// Express middleware
server.applyMiddleware({
app,
cors: config.cors,
})

// Subscriptions
server.installSubscriptionHandlers(httpServer)

Expand Down
2 changes: 1 addition & 1 deletion packages/@nodepack/plugin-apollo/src/runtime/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function getApolloConfig ({
tracing: true,
introspection: true,
subscriptions: {
path: '/subscriptions',
path: apolloConfig.apolloServerOptions.subscriptionsPath || '/subscriptions',
/**
* @param {any} connection
*/
Expand Down
6 changes: 5 additions & 1 deletion packages/@nodepack/plugin-apollo/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DocumentNode } from 'graphql'
import { IResolvers, PubSubEngine, ApolloServer } from 'apollo-server-express'
import { IResolvers, PubSubEngine, ApolloServer, Config } from 'apollo-server-express'
import { ExecutionParams } from 'subscriptions-transport-ws'
import { Request, Response } from 'express'

Expand All @@ -20,3 +20,7 @@ export interface ApolloContext {
user: any
server: ApolloServer
}

export interface ApolloConfig extends Config {
path: string
}

0 comments on commit 11bb48f

Please sign in to comment.