graphql
graphql copied to clipboard
No ways to add a field with arguments but without sub-fields to the Query
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!