apollographql / meteor-integration

🚀 meteor add apollo
http://dev.apollodata.com/core/meteor.html
108 stars 45 forks source link

Accessing the http request in context in createApolloServer #45

Closed rasmushjulskov closed 7 years ago

rasmushjulskov commented 8 years ago

I'm having this issues when following the Header example from: http://dev.apollodata.com/react/auth.html.

I don't seem to have the same options for accessing the Req in the context in createApolloServer?

lorensr commented 8 years ago

Looks like the Header example is on the client, not server?

I haven't tried it, but this might work?

http://dev.apollodata.com/core/meteor.html#meteorClientConfig

const config = meteorClientConfig()
config.networkInterface.use([{
  applyMiddleware(req, next) {
    // header stuff
  }
}]);

const client = new ApolloClient(config)
xavxyz commented 7 years ago

Hey @Rhjulskov!

As @lorensr pointed out, you can access the request from the client with a custom middleware: http://dev.apollodata.com/core/network.html#networkInterfaceMiddleware

And if you want to do stuff on the request server-side, you can use configServer config of the createApolloServer function:

createApolloServer({
  schema,
}, {
  configServer: expressServer => expressServer.use((req, res, next) => {
    // do something there manually or use an express middleware instead of this custom function
  }),
});