apollographql / meteor-integration

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

Apollo Optics #47

Closed bearcanrun closed 8 years ago

bearcanrun commented 8 years ago

Is there a way to use Apollo Optics with this package, or would we need to integrate Apollo manually to apply OpticsAgent as middleware and set opticsContext?

lorensr commented 8 years ago

Hi! I haven't tried, but think this should work?

https://github.com/apollostack/optics-agent-js/blob/master/README.md

Instrument your schema: OpticsAgent.instrumentSchema(executableSchema);
Add the middleware: expressServer.use(OpticsAgent.middleware());
Add to your GraphQL context object: context.opticsContext = OpticsAgent.context(req);
createApolloServer(req => {
  return {
    schema: OpticsAgent.instrumentSchema(executableSchema),
    context: {
      opticsContext:  OpticsAgent.context(req)
    }
  }
}, {
  configServer: (expressServer) => {
    expressServer.use(OpticsAgent.middleware())
  }
})
bearcanrun commented 8 years ago

This works perfect. Thank you! I didn't understand how to integrate the middleware and didn't realize it was so easy.

davidboom95 commented 7 years ago

Hi, it seems this code breaks the meteor context, it should pass context.userId and context.user, when I try to reverse changes, context is still undefined. I tried meteor reset, and re-install apollo-server but it does not work