-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Flexible client side querying through @whereConstraints
directive
#753
Conversation
@whereConstraints
directive
@spawnia looks pretty interesting! Not able to test at the moment but should get to this soon. Will this suffer from the same exploit mentioned here since the column names are dynamic and controlled by the client? Might be nice to have the operators as Enums as well, not sure if those suffer the same fate as the columns or not. |
@whereConstraints
directive@whereConstraints
directive
@chrissm79 good point, let's definitely fix the security issue before we merge this. The article you linked was great, i think we can employ a similar security mechanism as in spatie/laravel-query-builder@3aa483b Having the operator as an Enum makes sense, but i am not too sure if we can define a generalized solution that works for all databases. Maybe we will have to leave that up to the user and make them add the |
@whereConstraints
directive@whereConstraints
directive
@chrissm79 fixed the security issue and made the user add an Operator enum themselves. |
Nice job @spawnia! |
@whereConstraints
Add a dynamically client-controlled where constraint to a fields query.
Setup
This is an experimental feature and not included in Lighthouse by default.
First, enable the service provider:
It depends upon mll-lab/graphql-php-scalars:
Finally, add an enum type
Operator
to your schema. Depending on yourdatabase, you may want to allow different internal values. This default
should work for most databases:
Usage
The argument it is defined on may have any name but must be
of the input type
WhereConstraints
.This is how you can use it to construct a complex query
that gets actors over age 37 who either have red hair or are at least 150cm.
The definition for the
WhereConstraints
input is automatically includedwithin your schema.