-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apollo Server 2 Hapi context #1563
Comments
Anyone experiencing? For some reason the |
I had a similar issue with express |
@apollomusa I set user to req.session in express, but couldn't get user in apolloServer context definition. |
@ILovePing similar issue with me, the request object in apolloServer context differs so for example
|
Still trying to find a solution |
@apollomusa Currently,I just use a variable to store user for the first let user = null;
//...some other code here
public configureGraphQL(app: any, httpServer: any) {
const typeDefs = this.graphQLFactory.mergeTypesByPaths('./**/*.graphql');
const schema = this.graphQLFactory.createSchema({ typeDefs });
app.use('/graphql', (req, res, next) => {
if (req.session.user){
user = req.session.user;
}
next();
});
const server = new ApolloServer({
schema,
context: () => {
return { user };
},
});
server.applyMiddleware({ app,
cors: true,
bodyParserConfig: true,
});
server.installSubscriptionHandlers(httpServer);
} |
This may has some other problems but helps now. |
You can specify route options when you call await apolloServer.applyMiddleware({
app: server, // a hapi server instance
path: '/my/path/to/graphql',
route: {
auth: 'simple',
},
}); @apollomusa - Hope that helps a bit. |
@maxnachlinger Your commend it's not clear. What does |
@obedparla
route is if type hapi.RouteOptions .
|
@musab if you found an answer would you mind closing this issue? |
How 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
I see
Logged in{"username":"admin","isValid":true,"id":"1","name":"John"}
But the following returns undefined:
Here's a Github gist of my whole
index.ts
file https://gist.github.com/apollomusa/1afff80b29600c863705dc2cc174e86aThe text was updated successfully, but these errors were encountered: