Allow data based validation rules on scalars `Date` and `DateTime`
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.5k
- Forks
- 468
- Avg merge
- 3h 9m
- Merged PRs (30d)
- 2
Description
What problem does this feature proposal attempt to solve?
Laravel offers useful validation rules that operate on date values, e.g. after, before, different.
While those typically expect plain strings as input, Lighthouse typically uses scalar types for date values and internally casts them to \Carbon\Carbon instances.
This causes some of those rules to misbehave. Comparison may not work as expected. The following rules will always succeed, even if the passed dates have different values:
type Query {
foo(
bar: Date @rules(apply: ["different:baz"])
baz: Date
): Int
}
Which possible solutions should be considered?
In order to just work™, we will have to pass plain inputs into validation.
Scalar conversion is a process that is currently outside of Lighthouse's control, it is handled by graphql-php. Maybe we can disable it to run later or somehow get a hold of the original inputs?
We could also convert the input back to plain values before validating. This might not be possible in all cases, custom scalars we don't know about might not allow that operation.
Contributor guide
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 by tracing how the Date and DateTime scalars are converted by graphql-php before Lighthouse's @rules validation runs. Compare the behavior of data-based rules such as different, after, and before; done means these rules correctly compare the original scalar inputs without breaking unknown custom scalars.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, laravel, php
- Domain
- api, backend, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100