Was this helpful?

Checking if a place is within an itinerary

You can check whether a place has already been added to an itinerary by performing a query and supplying the place identifier.

Prerequisites

  • You will need to supply an ID in order to check the place exists in an Itinerary

  • You will need to have access to the ID of the itinerary to check for a place

1# Checks whether a place has been added to an itinerary, for creating a button
2# state on an "Add to Itinerary" button. If a result is returned, you may then
3# want to indicate to the user it is already present in their itinerary, or
4# offer them to remove it. You can pass the matching itinerary location ID that
5# has this place associated from this query to the deleteItineraryItem operation
6
7query CheckItineraryPlacePresent {
8  # Use the itinerary query, supplying the itinerary ID to check
9  itinerary(id: "itinerary/ABC123") {
10    # Query the descendants, providing some constraints
11    descendants(
12      # Provide the place identifiers to check
13      placeIds: ["place/123"]
14      # You may support adding a place multiple times, but for most reading
15      # back one will be enough
16      first: 1
17    ) {
18      nodes {
19        # Obtain the ID, so we can remove this location using the operation
20        # deleteItineraryItem() to remove the item from the itinerary.
21        id
22      }
23      # Total Count should be greater than 0, as the place could be added more
24      # than once to an itinerary
25      totalCount
26    }
27  }
28}

Sandbox: Configure | Try Operation

If successful, you'll be returned with a reference to the itinerary location ID

1{
2  "data": {
3    "itinerary": {
4      "descendants": {
5        "nodes": [
6          {
7            "id": "itinerary/ABC123/location/DEF456"
8          }
9        ],
10        "totalCount": 1
11      }
12    }
13  }
14}

alpaca.tech

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