Skip to content

Full Sync Example

  • Full sync = the entire sync process with the retrieval of all data in batches, as well as how to use entity changes to maintain all the data retrieved.

Scenario -Fetch Invoice Data

  • Make sure to look up the specific entityType that you should sync, in our example we show you how to sync ledgerNote data.
  • We currently support the "Subscription-entities" towards this use-case scenario, to read more about the current "Subscription-entities" please visit our GQL-endpoint here.
  • Fetch the latest lastLocalId, save it, then use it after the full sync process.

Start the Synchronization

  • Use lastId for pagination, i.e., the lastId/page serves as the lastId for the next page.
  • The entire process flows through steps a-b-c.
  • In our example we filter against replaced, removed and draft statuses to only fetch current data.
  • Extend queries a b or c based on your data preferences.
    query a {
      ledgerNotesSync(
        where: {
          and: [
            {
              statusDraft: { eq: false }
              statusReplaced: { eq: false }
              statusRemoved: { eq: false }
            }
          ]
        }
        order: [ {
          refersToPeriodDisplayName: DESC
        }]
        first: 1000
        lastId: ""
      ) {
        nodes {
          id
          toPay
          refersToPeriodDisplayName
          customer {
            displayName
            id
          }
        }
      }
    }
    

Use the Latest localId (which you saved earlier) from Entity Changes

  • Use the latest localId as the starting point (e.g., lastLocalId: LatestFetchedLocalID).
  • In the usecase enitity change you can get further details.
  • Check for pruned = true. If pruned = true is encountered, you must re-run the entire process. Read more about pruned.
    query b {
      entityChangesByEntityTypeIdSync(
        lastLocalId: $LatestFetchedLocalID 
        entityTypeId: "ledgerNote"
        first: 1000
      ) {
        nodes {
          entityId
          statusCreated
          pruned
          type {
            displayName
            id
          }
          localId
        }
      }
    }
    

Populate a "Resync" Based on Changed IDs

  • Use ledgerNotesById to fetch updated details for entityId's that have changed.
  • Filter the entityId's to ensure they are distinct (removing any duplicate IDs).
    query c {
      ledgerNotesById(ids: ["", "", ""]) {
        id
        toPay
        refersToPeriodDisplayName
        customer {
          displayName
          id
        }
      }
    }
    

Further reading: