graphql icon indicating copy to clipboard operation
graphql copied to clipboard

No ways to add a field with arguments but without sub-fields to the Query

Open MurzNN opened this issue 1 year ago • 0 comments

I'm working with Commercetools API, here is the reference https://docs.commercetools.com/api/graphql And it requires to add fields with arguments, here is an example:

query MyQuery {
  product(sku: "SKU1") {
    id
    masterData {
      current {
        slug(locale: "en")
        name(locale: "en")
      }
    }
  }
}

I'm trying to implement this using the library like this:

    $gql = new Query('product', ['sku' => "SKU1"]);
    $gql->use('id')
      ->masterData([])
      ->current([])
      ->slug(['locale' => 'en'])->prev()
      ->name(['locale' => 'en'])->prev()
    ;

But it produces a wrong result:

{
    product(sku: "SKU1") {
        id
        masterData {
            current {
                slug(locale: "en") {
                }
                name(locale: "en") {
                }
            }
        }
    }
}

The problem is that it produces slug(locale: "en") {} instead of slug(locale: "en").

If this is possible to do with the library, could you please give an example of how to make it produce the right result? Thanks!

MurzNN avatar Aug 01 '24 12:08 MurzNN