Ergonode docs
Search…
Integrating data
Note: the following examples are based on the API Stream integration concept - if you are not yet familiar with it check an overview of the Query types to understand the approach.

A simple example of integrating categories into the system from scratch:

Fetch the first page of the Category stream

1
{
2
categoryStream(first: 1) {
3
totalCount
4
pageInfo {
5
endCursor
6
hasNextPage
7
}
8
edges {
9
node {
10
code
11
name {
12
value
13
language
14
}
15
}
16
cursor
17
}
18
}
19
}
Copied!
first parameter means how many categories are fetched in one result
example response:
1
{
2
"data": {
3
"categoryStream": {
4
"totalCount": 5,
5
"pageInfo": {
6
"endCursor": "YXJyYXljb25uZWN0aW9uOjQ5",
7
"hasNextPage": true
8
},
9
"edges": [
10
{
11
"node": {
12
"code": "category_name_clothing",
13
"name": [
14
{
15
"value": "Clothing",
16
"language": "en_GB"
17
},
18
{
19
"value": "Odzież",
20
"language": "pl_PL"
21
}
22
]
23
},
24
"cursor": "YXJyYXljb25uZWN0aW9uOjQ5"
25
}
26
]
27
}
28
}
29
}
Copied!

Fetch the next page of the Category stream

Since we received information that the next page exists data.categoryStream.pageInfo.hasNextPage=true we should request the next resource. The query is very similar to the previous one except we are passing the appropriate cursor with the request:
1
{
2
categoryStream(first: 1, after: "YXJyYXljb25uZWN0aW9uOjQ5") {
3
...
4
}
Copied!
after parameter represents the appropriate cursor which identifies a last-fetched resource. Available as either cursor field of the node or endCursor of PageInfo object.
example response:
1
{
2
"data": {
3
"categoryStream": {
4
"pageInfo": {
5
"endCursor": "YXJyYXljb25uZWN0aW9uOjUw",
6
"hasNextPage": false
7
}
8
...
9
}
10
}
11
}
Copied!
we do know that there is no next page, therefore, nothing to fetch at the very moment. We can retry the next request(for the retrieved cursor) with i.e. increased interval, not to waste resources.

A more complex example of integrating categories

Alternatively in some systems, we will want to only fetch the identifier of the resource using some sort of queueing system in order to distribute the consumption processes. In that case, we can just fetch our resource id(code in the case of categories) and the PageInfo object:
1
{
2
categoryStream(first: 1) {
3
pageInfo {
4
endCursor
5
hasNextPage
6
}
7
edges {
8
node {
9
code
10
}
11
}
12
}
13
}
Copied!
and fetch it in the separate consuming process via a single resource query:
1
{
2
category(code: "category_name_clothing") {
3
name {
4
value
5
language
6
}
7
code
8
}
9
}
Copied!
The rest of the process looks the same for the paginating over the stream.
Though given above content provides the example of handling categories you can use the same approach for every other resource available via streams like products, multimedia, and attributes.
Last modified 1mo ago