Retrieve Link field content
This page will show you how to retrieve the content from a Link field.
1. Specify the Link field
Start by defining the Link field you want to retrieve.
In the following example, we are querying for all the documents of the type "blog_post". In this case, the API ID of the Link field is page_link. We are also specifying the __typename field so that we can see the field names we need to use in the next step of this process.
query{
allBlog_posts{
edges{
node{
page_link{
__typename
}
}
}
}
}
2. Add a switch for the link type
Next we need to add a Union type in order to specify which fields we need for each link type. The Union type will look something like this:
... on _ExternalLink
There are three different kinds of links:
Here is an example that will give you different fields depending on the type of link. In this case you could get content from an External link, Media link, or a Document link to a "page" type.
query{
allBlog_posts{
edges{
node{
page_link{
__typename
... on _ExternalLink{
url
}
... on _FileLink{
name
url
size
}
... on Page{
title
description
_meta{
uid
}
}
}
}
}
}
}