Was this helpful?
A collection provides you the ability to manage a single, large number of locations as your application or website place database. Queries and mutations are optimised to queries across many locations.
Note: If you are considering an integration from an external data source to a collection, consider also reviewing the importing locations topic.
Associated to profiles are collections. You will need to identify which collection you are managing in order to be able to supply a collection ID.
1# Load the collections available for a profile
2
3query QueryCollections {
4 # Use collections() operation for listing collections
5 collections(
6 # Supply the profile to list profiles for. Use authorizedProfiles operation
7 # to identify your profile
8 profileId: "profile/ABC123"
9 # Pagination controls for relay "cursor connections"
10 # See: https://relay.dev/graphql/connections.htm
11 first: 10 #, after: <cursor>
12 ) {
13 edges {
14 node {
15 # Collection ID/Type
16 id
17 __typename
18 # Information to obtain about the collection
19 title
20 }
21 cursor
22 }
23 pageInfo {
24 hasNextPage
25 }
26 totalCount
27 }
28}
Sandbox: Configure | Try Operation
Note: the collections
operation returns a cursor connection. You can read
how to paginate using cursor connections
The API provides mechanisms to query the collection to list locations associated to the collection.
1# Queries for collection locations from a collection by a supplied tag. This
2# will take a supplied collection ID and look for items that have the tag of
3# "my-tag" present. This is a basic filtering capability based on tagging items
4# within groups.
5
6query QueryCollectionLocationsByTag {
7 # use collectionItems() operation
8 collectionItems(
9 # Specify the collection ID
10 collectionIds: "collection/ABC123"
11 # Specify the tag to include
12 tags: "my-tag"
13 # Pagination controls for relay "cursor connections"
14 # See: https://relay.dev/graphql/connections.htm
15 first: 10 #, after: <cursor>
16 ) {
17 edges {
18 node {
19 # Returned records
20 id
21 __typename
22 # Access whatever we want here about the items
23 ... on CollectionLocation {
24 title
25 }
26 }
27 # Use the cursor and supply to "after" in operation to paginate
28 cursor
29 }
30 totalCount
31 }
32}
Sandbox: Configure | Try Operation
Note: A collection can house diffent types of items, outside of just locations.
As such, you will need to select fields from the CollectionLocation type as
illustated below using ... on CollectionLocation { ... }
. This allows you to
select the specific fields when the __typename
is CollectionLocation
.
You can also query a specific collection location by leveraging the
collectionItem
operation. This can help you when wanting to load more
information about a particular location.
1# Loads in a specific collection location
2
3query QueryCollectionLocation {
4 collectionItem(
5 # Provide the individual collection item ID
6 id: "item/ABC123"
7 ) {
8 # Identifier/Types
9 id
10 __typename
11 ... on CollectionLocation {
12 # Load some of the content as you need
13 title
14 synopsis
15 # ... description, tags, websiteUrl, readMoreUrl, etc etc
16 # Load the preferred media
17 preferredMedia {
18 resource {
19 ... on MediaImage {
20 # Load a thumnail at the desired size
21 thumbnail: source(bestFit: [100, 100]) {
22 url
23 }
24 # Text
25 altText
26 caption
27 # Photographer Attribution
28 copyright
29 attribution
30 }
31 }
32 }
33 # Load information about the place by joining the place node, allowing
34 # access to all the underlying place information that is provided by a
35 # place provider service (Facebook, ATDW, Yelp, TripAdvisor etc)
36 place {
37 # Identifier/Types
38 id
39 __typename
40 # Load contact information about the place
41 contact {
42 phoneNumber
43 websiteUrl
44 facebookUrl
45 }
46 # Geocoding positions
47 position {
48 lon
49 lat
50 }
51 # Maki icon
52 maki
53 }
54 }
55 }
56}
Sandbox: Configure | Try Operation
When creating a collection location, you will need to supply a place
value.
The Place within a collection location represents the physical place associated to this location.
You can supply just the position of this place, such as when you have placed a
dropped-pin, or supply a place.id
that refers to a place identifier from a
source of place information.
Alpaca supports a number of place providers, such as the ATDW, OSM, Facebook and
others. When you supply a place.id
to these providers, you will be able to
query back up to date information about that place in future queries, as Alpaca
will leverage integration to these providers to enable you to query data about
those places.
1# Creates a Collection Location within a collection
2
3mutation CreateCollectionLocation {
4 # use createCollectionLocation for this operation
5 createCollectionLocation(
6 # Supply the collection to place the collection location within
7 collectionId: "collection/ABC123"
8 # Supply the data for the location model
9 location: {
10 # Provide content for the collection item
11 # Synopsis, tags, description, media, website etc.
12 title: "Mavis the Grocer"
13 # Supply tags (we can later query on this)
14 tags: ["cafe"]
15 # Note: See external refs/source if you want to store your own identifiers
16 # Provide a reference to the place/position for the place location
17 place: {
18 # Place information will be sourced from ATDW provider
19 id: "place/atdw:product:5cae80be57a096cd7084b6ab"
20 position: { lon: 144.9970825017, lat: -37.803058481 }
21 }
22 }
23 ) {
24 location {
25 # Returns with the collection location just created
26 id
27 __typename
28 }
29 }
30}
Sandbox: Configure | Try Operation
You can update information you have added about your location by supplying the
arguments in location
. There are a number of fields you can manage, as well as
attributes to store extended information or overwrite/augment information from
place providers.
1# Modify an existing collection location title
2
3mutation UpdateCollectionLocationTitle {
4 # use the updateCollectionLocation() operation
5 updateCollectionLocation(
6 # ID of record to update
7 id: "item/ABC123"
8 # Update the data for the location
9 location: { title: "New Title" }
10 ) {
11 # Query back data after the mutation for the response
12 location {
13 # Should now become "New Title"
14 title
15 }
16 }
17}
Sandbox: Configure | Try Operation
Removing collection items is done so via the deleteCollectionItem
operation.
1# Removes a collection item from a collection
2
3mutation DeleteCollectionItem {
4 # Use the deleteCollectionItem() operation
5 deleteCollectionItem(
6 # Supply the ID of the record to remove
7 id: "item/ABC123"
8 ) {
9 # select back a response of the ID of the removed item
10 id
11 }
12}
Sandbox: Configure | Try Operation
Copyright © 2024 - Made with love ❤️ in Australia.