Was this helpful?

Position Numbering

When displaying a map or itinerary, it is often helpful to display a sequence to represent visiting places in order. While you are able to query GraphQL to obtain and represent ordering in your application how you want, the GraphQL API also provides some fields to assist common use cases.

Using GraphQL queries, it is possible to query and access numbering for queries. This can be used for presenting basic numeric ordering in your list or for when you load a specific itinerary location.

  • Using edge data provided by children or descendants queries, you can access the edgePositionNumber. This will provide a numeric value for the returned as a position relative to the other edges returned as a sequence

  • Using siblingPositionNumber on ItineraryLocation and ItineraryDirection, you can access the position relative to the other child siblings

You can modify the numbering behaviour with the optional skipOptional or\ skipOmitList query parameters. These default to true, and will provide a null number on nodes that have been marked as optional, or excluded from being returned in a list.

Sibling Numbering

When loading information about a specific itinerary location, you may wish to identify a numbering that could be displayed as relative to the other siblings.

To determine a position number for the node, you can use the siblingPositionNumber() and determine any constraints, such as the type or any skip behaviour for any of the siblings.

1# Identify a number for a specific itinerary location without loading the list
2# of siblings.
3
4query ItineraryLocationSiblingPositionNumber {
5  # Query the itinerary location directly
6  node(id: "itinerary/ABC123/location/DEF456") {
7    ... on ItineraryLocation {
8      # Identifiers
9      id
10      __typename
11
12      # Create a numeric representation for this itinerary location
13      position: siblingPositionNumber(
14        # Reduce the sibling types to just Itinerary Locations
15        type: ItineraryLocation
16        # Control the omits with further properties
17        skipOptional: true
18        skipOmitList: true
19      )
20    }
21  }
22}

Sandbox: Configure | Try Operation

Edge Numbering

Additionally, if you are presenting a list of itinerary locations via a connection response of children() and descendants(), you can use the edge numbering to assist determine a number.

To determine a position number for the edge, you can use the edgePositionNumber() and determine any constraints, such as the type or any skip behaviour.

1# Leverage the connection edge data to create a position number for each of the
2# edges returned.
3
4query ItineraryEdgePositionNumber {
5  # When querying the children determine a position number
6  itinerary(id: "itinerary/ABC123") {
7    # Using the edge data for children
8    children(type: ItineraryLocation, first: 10) {
9      edges {
10        # The node information ...
11        node {
12          id
13          __typename
14        }
15
16        # Determine a position number, relative to the current edge
17        position: edgePositionNumber(
18          type: ItineraryLocation
19          # Control the omits with further properties
20          skipOptional: true
21          skipOmitList: true
22        )
23      }
24    }
25
26    # Using the edge data for descendants
27    descendants(type: ItineraryLocation, first: 10) {
28      edges {
29        # The node information ...
30        node {
31          id
32          __typename
33        }
34
35        # Determine the position number, relative to the current edge
36        position: edgePositionNumber(
37          type: ItineraryLocation
38          # Control the omits with further properties
39          skipOptional: true
40          skipOmitList: true
41        )
42      }
43    }
44  }
45}

Sandbox: Configure | Try Operation

alpaca.tech

Copyright © 2024 - Made with love ❤️ in Australia.