spring-projects / spring-projects/spring-graphql
QueryDSL datafetcher should support default arguments
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 336
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with QuerydslDataFetcher.builder and QuerydslPredicateBuilder around line 92, then trace how QuerydslPredicateExecutor bindings are converted when no query argument values exist. Determine how a customizer can contribute a default owner predicate without user input, and verify that queries without an owner argument return only the intended records while explicit arguments still behave correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100