Graphql-laravel: Privacy is not work

Created on 23 Apr 2020  路  4Comments  路  Source: rebing/graphql-laravel

Versions:

  • graphql-laravel Version: 5.0
  • Laravel Version: 7.0
  • PHP Version: 7.3

Question:

public function fields(): array
    {
        return [
            'id' => [
                'type' => Type::nonNull(Type::id()),
                'description' => 'id'
            ],
            'nickname' => [
                'type' => Type::nonNull(Type::string()),
                'description' => 'nickname'
            ],
            'telephone' => [
                'type' => Type::string(),
                'description' => 'telephone',
            ],
            'username' => [
                'type' => Type::string(),
                'description' => 'username'
            ],
            'email' => [
                'type' => Type::string(),
                'description' => 'email',
                'resolve' => function ($root) {
                    return Str::lower($root->email);
                },
                'privacy' => function () {
                    return false;
                }
            ],
];
}

The privacy is not work whatever the function return true or false. Where did i go wrong?

question

Most helpful comment

@mfn thank you very much, i got it.
It work fine now, thank you.

$fields = $getSelectFields();
        $select = $fields->getSelect();
        $with = $fields->getRelations();

        $builder = User::select($select)->with($with);

Those code must be write to `UserQuery.php@resolve'

All 4 comments

image
This is the request

image
This relation query is not working, it is seem query not be called.

I think you're not using SelectFields, which is required to make all this magic work. Can you show your resolver?

Check the readme, lots of SelectFields examples

@mfn thank you very much, i got it.
It work fine now, thank you.

$fields = $getSelectFields();
        $select = $fields->getSelect();
        $with = $fields->getRelations();

        $builder = User::select($select)->with($with);

Those code must be write to `UserQuery.php@resolve'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Artem-Schander picture Artem-Schander  路  7Comments

constantinosergiou picture constantinosergiou  路  3Comments

shengslogar picture shengslogar  路  6Comments

niiapa picture niiapa  路  8Comments

timothyvictor picture timothyvictor  路  3Comments