Skip to content

QueryDSL datafetcher should support default arguments #867

Open
@paulbakker

Description

@paulbakker

Given a UsefulThingRepository which implements QuerydslPredicateExecutor<UsefulThing>.
The UsefulThing entity has an owner field.
When a user executes the query { usefulThing { name } } query, they should only get the items they own.
This works when owner is provided as a query argument.

However, in this case it makes sense to add the WHERE clause by default instead of relying on a query argument.
I would expect something like this work to add a default WHERE clause on the owner field.

var many = QuerydslDataFetcher.builder(repository)
                .customizer((bindings, root) -> bindings.bind(QUsefulThing.usefulThing.owner)
                        .first((path, value) -> path.eq(ssoCallerResolver.get().username).many();

Note that in this example the ssoCallerResolver.get().username is just an example of something that would give the current user form the request.

In QuerydslPredicateBuilder on line 92 there is a check on values. Since the value is not user provided, this will be empty, and it won't build a predicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: blockedAn issue that's blocked on an external project change

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions