Skip to content
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

Privacy Attribute is ignored when is sub type #1161

Open
ricardosierra opened this issue Dec 12, 2024 · 0 comments
Open

Privacy Attribute is ignored when is sub type #1161

ricardosierra opened this issue Dec 12, 2024 · 0 comments
Labels

Comments

@ricardosierra
Copy link

ricardosierra commented Dec 12, 2024

Versions:

  • graphql-laravel Version: 9.5.0
  • Laravel Version: 11.15.0
  • PHP Version: 8.3

Description:

When my UserType is loaded from another Type such as AlbumType, the Privacy attribute is completely ignored. Note that in the first request my CPF comes null, however, if I request this information from the AlbumType it returns and ignores my Privacy

Steps To Reproduce:

To reproduce, create the Types and the Privacy class and try to execute the commands in the prints below.
image

image

Code

class MePrivacy extends Privacy
{
    public function validate(array $queryArgs, $queryContext = null): bool
    {
        if (!auth('sanctum')->check()) {
            return false;
        }
        if (!isset($queryArgs['id'])) {
            return false;
        }
        return $queryArgs['id'] == auth('sanctum')->id();
    }
}
class UsuarioType extends GraphQLType
{
    protected $attributes = [
        'name'          => 'Usuario',
        'description'   => 'A Usuario',
        // Note: only necessary if you use `SelectFields`
        'model'         => Usuario::class,
    ];
    public function fields(): array
    {
        return [
            'chave_pix' => [
                'type' => Type::string(),
                'description' => 'Chave PIX para recebimentos de pagamentos.',
                'privacy'       => MePrivacy::class,
            ],
            'cpf' => [
                'type' => Type::string(),
                'description' => 'CPF do usuário.',
                'privacy'       => MePrivacy::class,
            ],
        ]
   }
}
class AlbumType extends GraphQLType
{
    protected $attributes = [
        'name' => 'Album',
        'description' => 'Collection of albuns with their respective category',
        'model' => Album::class
    ];
    public function fields(): array
    {
        return [
            'id' => [
                'type' => Type::nonNull(Type::int()),
                'description' => 'The unique identifier of the album.'
            ],
            ...
            'usuario' => [
                'type' => GraphQL::type('Usuario'),
                'description'   => 'A list of fotos written by the user'
            ],
            ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant