spawnia / sailor

A typesafe GraphQL client for PHP
MIT License
78 stars 18 forks source link

[Support] - date range #76

Closed rccc closed 1 year ago

rccc commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

rccc commented 1 year ago

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 commented 1 year ago

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.