I'd like to disable authentication on introspection queries and enable it for other kinds of queries, so that I can see schema in GraphQL playground, even when no valid authorization header is present.
If I just throw exception when no valid authorization is present, playground fails to load schema because introspection query fails.
The only way to get around from this problem seems to be not throwing authentication errors at all if NODE_ENV is development. There is no way to check whether GraphQL query is introspection or not inside context function, isn't it?
const server = new ApolloServer({
schema,
context: () => {
// throw authentication error if authorization header is not present or invalid
throw new AuthenticationError("Invalid authorization header");
}
});
@vroad , hey there!
My understanding is that, in this case, you should not validate user authentication on the context callback.
As per the docs:
We would want to do this only on very restrictive environments where there is no public access to the schema or any fields, like an internal tool or maybe an independent micro service that we don’t want exposed to the public.
Did you take a look on Resolver auth? Maybe it fits better with your case.
Hi, @eberhara , Sorry for the late reply.
Is that only way? I'd like to handle authentication in a single place on an API gateway server. It already has executable GraphQL schema from underlying APIs, so I didn't want to duplicate resolvers/mutations at API gateway level.
What would be the best approach for allowing introspection for our CI? I'd like to be able to use apollo-tooling to perform checks against the schema registry.
👋 I'll close this since this doesn't appear to be a bug with Apollo Server, but rather a question about how to use it or one of its components.
Rather than asking it here in GitHub Issues — where efforts are focused on fixing bugs and adding new features — I'd ask that you take this question to the _Apollo Server_ channel within the Apollo community on Spectrum.chat where there are community members who might be able to relate to a similar problem, or might be able to help you out more interactively. Thanks for your understanding!
Most helpful comment
What would be the best approach for allowing introspection for our CI? I'd like to be able to use
apollo-toolingto perform checks against the schema registry.