How do I restrict GraphQL access with Basic Auth? According to this Gitbook (near the bottom), its possible to require GraphQL query authentication with Drupal Core's Basic Auth module. This allows GraphQL to authenticate against a user stored in the Drupal DB.
https://drupal-graphql.gitbook.io/graphql/authentication/authentication
I created an event subscriber that adds the Basic Auth option to the route like this:
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    if ($route = $collection-&gt;get('graphql.query.default:default')) {
      $route-&gt;setOptions(['_auth' =&gt; ['basic_auth']]);
    }
  }
}

However, when I make a curl request without an Authorization header it still goes through:
curl -X POST -H &quot;Content-Type: application/json&quot;   --data '{&quot;query&quot;:&quot;{fileById(id: \&quot;33\&quot;) {changed}}&quot;,&quot;variables&quot;:null,&quot;operationName&quot;:null}' http://MYLOCALHOST/graphql

Response:
{&quot;data&quot;:{&quot;fileById&quot;:{&quot;changed&quot;:1572374455}}}

I did enable my custom module with the RouteSubscriber information above and also the Basic Auth module. When I visit the /graphql Drupal path in a browser, access is denied but when I make the CURL request it goes through. I was hoping to restrict CURL access as well.
Here is the Drupal 8 documentation on Basic Auth:
https://www.drupal.org/docs/8/core/modules/basic_auth/overview
I am using v3 of the Drupal 8 GraphQL module.
I got it!
I needed to add
$route-&gt;setRequirements(['_user_is_logged_in' =&gt; 'TRUE']);

...And then do the curl request with the username and password.