Skip to content

How do I default to guarded, but allow public queries/mutations? #2537

Closed Answered by axynos
axynos asked this question in Q&A
Discussion options

You must be logged in to vote

To answer my own question:

I found that in the end, the simplest solution is to write a custom replacement for the @guard directive that implements logic to skip prepending @guard to fields if a stub @public directive is found on the field in question.

The simplest proof of concept for those with the same issue:

// app/GraphQL/Directives/ProtectDirective.php

<?php declare(strict_types=1);

namespace App\GraphQL\Directives;

use GraphQL\Language\AST\DirectiveNode;
use GraphQL\Language\AST\InterfaceTypeExtensionNode;
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
use GraphQL\Language\AST\ObjectTypeExtensionNode;
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use GraphQL\Language\A…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by axynos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant