Apollo Server 2 Hapi context
See original GitHub issueHow can I get my request object passed into my context? I am trying to verify the user is authenticated.
I am using the hapi pkg yar
to manage the session.
For example in my root path, when I do the following
app.route({
method: 'GET',
path: '/',
options: {
auth: 'simple'
},
handler(request) {
return 'Logged in' + JSON.stringify(request.yar.get('auth'))
}
})
I see Logged in{"username":"admin","isValid":true,"id":"1","name":"John"}
But the following returns undefined:
const server = new ApolloServer({
schema: query,
tracing: true,
context: async ({ request }) => {
return {
request
}
}
})
const resolvers = {
Query: {
rules: async (_, args, context) => {
console.log(context.request.yar.get('auth'))
return mock.rules
}
}
}
Here’s a Github gist of my whole index.ts
file https://gist.github.com/apollomusa/1afff80b29600c863705dc2cc174e86a
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top Results From Across the Web
API Reference: apollo-server - Apollo GraphQL Docs
This API reference documents the exports from the apollo-server package. class ApolloServer. The core of an Apollo Server implementation.
Read more >apollo-server-hapi - npm
This package has only been tested with @hapi/hapi 20.1.2 and higher; that is the minimum version of Hapi that supports Node 16. A...
Read more >apollo-server-hapi16 - npm Package Health Analysis - Snyk
apollo -server-hapi16. v0.0.2. Node.js GraphQL server for Hapi v16 For more information about how to use this package see README.
Read more >GraphQL Code Libraries, Tools and Services
GitHubapollographql/apollo-client ... JavaScript GraphQL client, designed to work well with React, React Native, Angular 2, or just plain JavaScript.
Read more >apollo-server | Yarn - Package Manager
The apollo-server package is part of Apollo Server v2 and v3, which are now ... A TypeScript GraphQL Server for Express, Koa, Hapi,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can specify route options when you call
await apolloServer.applyMiddleware()
, for example:@apollomusa - Hope that helps a bit.
@obedparla
route
provides options for the graphql route in Hapi, have a look here - https://github.com/apollographql/apollo-server/blob/ad4240295469821c24aaf2f1032b12882dd3b6f9/packages/apollo-server-hapi/src/ApolloServer.ts#L59 -route
is if typehapi.RouteOptions
.