Conditions on references
Less than to read
In a GraphQL node, you have references that correspond to branches in the graph.
For example, if an item refers to a sales unit, the corresponding field is just a node in the hierarchy and you have to refer to the properties associated with it:
{
xtremMasterData{
item{
query {
edges {
node {
id
salesUnit{
name
}
}
}
}
}
}
}
In the previous example, the field salesUnit cannot be displayed as a field. To display the field salesUnit as a field, you have to open a curly bracket section to describe wthe fields to display. In this case, the field is the name.
Sometimes, a reference is not mandatory. For example, if an item is not sold, there will not be be a salesUnit reference and you will see the following result:
{
"data": {
"xtremMasterData": {
"item": {
"query": {
"edges": [
{
"node": {
"id": "101",
"name": "TestCottage Pie",
"salesUnit": null
}
}
]
}
}
}
}
}
On a reference, you cannot directly apply a filter. However, you can apply it to fields found below a reference in the graph hierarchy. This is why you write conditions with nested elements, such as:
{
xtremMasterData {
item {
query(filter: "{salesUnit:{name:'Each'}}") {
edges {
node {
id
name
salesUnit {
name
}
}
}
}
}
}
}
In the previous example, the nested part {salesUnit{ describres how the condition is applied on a nested a property.
It is possible to nest as much levels as required.
The following example is of a deeply nested condition:
{
xtremSales {
salesOrder {
query (filter:"{soldToCustomer:{country:{currency:{name:{_eq:'US Dollar'}}}}}"){
edges {
node {
number
orderDate
soldToCustomer {
country {
language
currency {
name
}
}
}
}
}
}
}
}
}
When a property is a reference, you cannot apply a conditional operator. You can only apply the conditional operator on a property of the corresponding node.
There are two exceptions to this rule: the _eq and _ne operators with null as a value. The following example is a query that lists all the items that have a sales unit:
{
xtremMasterData {
item {
query (filter: "{ salesUnit:{_ne: null}}"){
edges {
node {
id
salesUnit {
name
}
}
}
}
}
}
}