-
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
graphql along with existing hapijs routes #97
Comments
Can you describe the problem a bit more accurately? Do you not want to authenticate the requests made to the graphql route? If that's your issue, I think it might be a HAPI configuration problem, not an issue with Apollo Server. |
Do you not want to authenticate the requests made to the graphql route? no, but the existing rest api routes take in auth, which break the graphql route. I get a 401 for the graphql route. how can i specify config : { auth : false }for graphql route? {"statusCode":401,"error":"Unauthorized","message":"Missing authentication"} |
@helfer any pointer please? do you have any example that uses both rest service and graphql with the auth strategy? |
@helfer I have hit a road block with this. Can you please let me know if the apollo server plugin takes the config : { auth : false } or the auth strategy set by hapi server?? I tried setting in the options, routes etc. nothing works. Am I doing something wrong? |
@BhaskaranR I don't know, because I didn't write that part. Maybe @nnance can help? If I were you, I would try send the authentication token with the graphql request as well, because presumably you already have it on the client? Alternatively you can run two separate servers. PS: I see you already found this issue, so I think you have your answer: outmoded/discuss#162 PPS: It seems this would be easy if we used |
@BhaskaranR I am working on some improvements to the HAPI implementation and this is one area I am working on improving. I will reach out when I have more detail |
I see only three ways to allow full control on HAPI routes:
import { Server } from 'hapi';
import { ApolloHAPI as Apollo } from 'apollo-server';
const server = new Server();
server.connection({ port: 3000 });
server.register({
register: new Apollo({
route: {
// Route configuration
}
}),
options: { schema: myGraphQLSchema },
routes: { prefix: '/graphql' },
});
import { Server } from 'hapi';
import { createApolloHandler } from 'apollo-server';
const server = new Server();
server.connection({ port: 3000 });
const apolloHandler = createApolloHandler({ schema: myGraphQLSchema });
server.route({
method: 'POST',
path: '/',
config: {
handler: apolloHandler,
// Route configuration
},
});
import { Server } from 'hapi';
import { ApolloHAPI as Apollo } from 'apollo-server';
const server = new Server();
server.connection({ port: 3000 });
server.register({
register: new Apollo(),
options: {
route: {
// Route configuration
},
schema: myGraphQLSchema },
routes: { prefix: '/graphql' },
}); The 3) is the closest to the HAPI ecosystem but require a breaking change. |
@SimonDegraeve @nnance I think we'll bump the version for the next release, so a breaking change won't be an issue. Let's make sure we make the API as close to perfect as we can! |
@SimonDegraeve @BhaskaranR I have opened a PR that should resolve this issue. Feedback welcome. #127 |
Hi,
I currently have some rest services which i don’t want to convert to graphql. For the new services i would like to use GraphQL.
I tried registering both hapijs rest api routes and graphql. I could still access the rest api but could not access graphql route unless the auth strategy is commented. I need the auth for my existing routes. How do I configure auth for graphql route?
server.auth.strategy('jwt', 'jwt', true,
{ key: config.get("jwtSecret"),
validateFunc: validate,
verifyOptions: { ignoreExpiration: true }
});
server.register({
register: new apollo.ApolloHAPI(),
options: graphqlOptions,
routes: { prefix: '/graphql' },
});
server.register({
register: new apollo.GraphiQLHAPI(),
options: { endpointURL: '/graphql' },
});
server.route(user.routes);
server.route(device.routes);
server.route(posts.routes);
The text was updated successfully, but these errors were encountered: