Was this helpful?

Segments

Segments provide a mechanism available to associate itinerary items, such as the Itinerary Location or Itinerary Directions to a specific group. Segments are most commonly used to break a trip into several parts.

Segments can be used to provide the user a selection in order to view a specific part of a trip.

Managing Segments

Segments are added to your itinerary as an itinerary item.

1# Creates an Itinerary Segment, which can be used to break up a list into
2# smaller discrete sections.
3
4mutation createItinerarySegment(
5  $itineraryId: ID!
6  $itinerarySegment: CreateItinerarySegmentInput!
7) {
8  createItinerarySegment(
9    itineraryId: $itineraryId
10    segment: $itinerarySegment
11  ) {
12    segment {
13      id
14    }
15  }
16}

Sandbox: Configure | Try Operation

Note: Segment attributes can be created and added at any supported mutation, such as createItinerary, createItineraryLocation etc. and are not limited to update.

You can then add trip segment identifiers to each of the itinerary items.

1# Assign a series of segments to your itinerary locations. Be sure to first
2# add your segments using the "itinerary/segment" attribute avaialble on the
3# itinerary.
4
5mutation UpdateItineraryLocationSegments {
6  # use updateItineraryLocation()
7  updateItineraryLocation(
8    # Supply the itinerary location ID
9    id: "itinerary/ABC123"
10    # Update the location
11    location: {
12      upsertAttrs: [
13        # Add the association of segment IDs
14        # Value as correlates to the "itinerary/segments" ids
15        { id: "itinerary/location/segments", value: ["my-UID"] }
16      ]
17    }
18  ) {
19    # Read back the changed data
20    itinerary {
21      # Identifiers
22      id
23      __typename
24
25      # Add in the segments
26      segments: attrValue(id: "itinerary/location/segments")
27    }
28  }
29}

Sandbox: Configure | Try Operation

Listing the Itinerary Segments

You can use the children field operation in order to obtain a list of the segments.

1# Query the itinerary segments for an itinerary.
2
3query listItinerarySegments($itineraryId: ID!, $first: Int!, $after: String) {
4  itinerary(
5    # Supply the itinerary ID
6    id: $itineraryId
7  ) {
8    # Select the associated itinerary segments using the children selector
9    children(
10      # Limit to querying the itinerary segments
11      type: ItinerarySegment
12      # Using the relay "cursor connection" specification for pagination
13      # See: https://relay.dev/graphql/connections.htm
14      first: $first
15      after: $after
16    ) {
17      edges {
18        node {
19          # ID/Types
20          id
21          __typename
22
23          # Specific information drawn from the Itinerary Segment
24          ... on ItinerarySegment {
25            title
26            color
27            contrastColor
28          }
29        }
30        # Obtain the cursor to pass back as the "after" property
31        cursor
32      }
33      # Total number of locations
34      totalCount
35      pageInfo {
36        hasNextPage
37        endCursor
38      }
39    }
40  }
41}

Sandbox: Configure | Try Operation

Querying itinerary segments

Query the itinerary children or descendants and restrict the results to a  specific segment ID.

1# Use the `segmentIds`
2
3query ListItineraryLocations {
4  # query the itinerary
5  itinerary(
6    # Supply the itinerary ID
7    id: "itinerary/ABC123"
8  ) {
9    # List the children
10    children(
11      # Query the locations
12      type: ItineraryLocation
13      # Limit the first 10
14      first: 10
15      # Limit the results to records with segment ID
16      segmentIds: ["day-one"]
17    ) {
18      edges {
19        node {
20          # Identifier
21          id
22          __typename
23
24          ... on ItineraryLocation {
25            # Name of the location associated with "day-one"
26            title
27            place {
28              name
29            }
30
31            # Should contain the id "day-one" in the collection
32            segmentIds: attrValue(id: "itinerary/location/segments")
33          }
34        }
35      }
36    }
37  }
38}

Sandbox: Configure | Try Operation

alpaca.tech

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