Skip to content
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

[Support] - date range #76

Closed
rccc opened this issue Oct 28, 2022 · 4 comments
Closed

[Support] - date range #76

rccc opened this issue Oct 28, 2022 · 4 comments

Comments

@rccc
Copy link

rccc commented Oct 28, 2022

Hello,

I wonder how to implement this query with Sailor (a date range query base on an input that is built up incrementally) :

query MyQuery {
  molecule(where: {mol_weight: {_gte: "", _lte: ""}}) {
    id
    mol_weight
  }
}

In my case, "mol_weight" type is "numeric_comparison_exp".

I wish i could do this:

$exp = new ...\molecule_bool_exp();
$exp->mol_weight = "define_my_interval_here";

Many thanks in advance.

Eric

@spawnia
Copy link
Owner

spawnia commented Oct 28, 2022

I do not understand why you have an issue with this. Sailor generates fully typed input objects, it should be obvious from their definition how they must be constructed.

In general, I recommend using their ::make() method and PHP 8 named arguments, for example:

MyOperation::execute(
  where: WhereCondition::make(
    field: FieldRange::make(from: 1, to: 2),
  ),
)

Look at the actual generated types to figure out what to pass, there should be no guesswork involved.

@spawnia
Copy link
Owner

spawnia commented Oct 28, 2022

Oh and since your example uses inline arguments: make sure to use variables.

@spawnia spawnia closed this as completed Oct 28, 2022
@rccc
Copy link
Author

rccc commented Oct 28, 2022

Dear Spania,

Sorry for this newbie question, here is how i did it finally:

$numExp = new \App\Api\Types\numeric_comparison_exp();
$numExp->_gte = $data['min_weight'];
$numExp->_lte = $data['max_weight'];

$exp->mol_weight = $numExp;

Sorry again, next time i will take more time to think twice before posting.

I wish you a nice day, many thanks for this (very) nice library.

@spawnia
Copy link
Owner

spawnia commented Oct 28, 2022

This looks fine and is how I would do it prior to PHP 8. With PHP 8, I would use named arguments to avoid the intermediary variables and shorten the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants