ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.23k stars 744 forks source link

Allow anonymous schema introspection from federation gateway #6992

Closed hrshv6 closed 1 month ago

hrshv6 commented 7 months ago

Product

Hot Chocolate

Is your feature request related to a problem?

We have several graphql domain services we are federating through a gateway, via federation with schema polling → Federation with Polling

Below screenshot shows a snip of how we add this fallback policy to our domain service: 2024-03-14_133710

Is there a setting in Hot Chocolate’s authorization middleware that will allow for anonymous introspection of schemas while requiring authentication on other types of queries?

We do have a temporary solution to get around this problem:

  1. When calling MapGraphQL(), we open up the “/graphql” endpoint to be completely anonymous by calling AllowAnonymous()
  2. Then we decorate our queries and mutations with the [Authorize] attribute which adds authentication to the “/graphql” endpoint.

2024-03-14_113320

We have already tried the following things in our domain services, to make schema introspection anonymous. But none of these have worked:

2024-03-14_113532

The solution you'd like

In this comment and this one in similar issues reported previously, you mentioned that it was now possible in Hot Chocolate.

Can you please provide instructions on how to allow schema introspection without being authenticated, or running into 401-Unauthorized responses? Thanks!

michaelstaib commented 7 months ago

There are I think some misconceptions ... The AllowAnonymous on MapGraphQL is transport authentication ... which has nothing to do with the GraphQL authorization. In most cases I would say this creates most problems.

You can secure your GraphQL types and remove and authentication from the MapGraphQL method.

michaelstaib commented 7 months ago

Have you considered just dumping the schema at build time ... its far more efficient.

hrshv6 commented 7 months ago

Hi @michaelstaib No, we have not tried this --> "Have you considered just dumping the schema at build time ... its far more efficient."

Can you give us some clues on how we can do this, or where to start? Thanks!

sc-cpais commented 2 months ago

Did you end up finding any solution @hrshv6 ? I'm struggling with the same issue.