SimonDegraeve / hapi-graphql

Create a GraphQL HTTP server with Hapi.
115 stars 27 forks source link

Schema resolve functions need access to db connection objects defined in other plugins #2

Closed KyleAMathews closed 9 years ago

KyleAMathews commented 9 years ago

Not sure how I can access them with how you've set things up atm...

bmcmahen commented 9 years ago

couldn't you pass it through the rootValue?

SimonDegraeve commented 9 years ago

Indeed you need to pass it through the rootValue using a function.

server.register({
  register: GraphQL,
  options: {
    query: (request) => {{
      schema: TestSchema,
      // the rootValue will be available in every `resolve` in your schema
      // see graphql doc for more informations
      rootValue: {
        db: request.server.app.db, // or request.server.plugins.db or ...
        viewer: request.auth.credentials
      }
    }),
    route: {
      path: '/graphql',
      config: {}
    }
  }
}, () =>
  server.start(() =>
    console.log('Server running at:', server.info.uri)
  )
);