I've been writing some queries to fetch the "linked documents" to use in my slice components. I've managed to write the correct query (I think) and tested it in the playground.
However, when I try to use the same query in my code. The link document object won't fetch that last bit of data in order to use in the PrismicLink component. Any help would be nice.
query allHomePages {
allHomes(id: "YvKx6xAAACAAyZS0") {
edges {
node {
slices {
__typename
... on HomeSlicesProject_card {
type
label
variation {
__typename
... on HomeSlicesProject_cardDefault {
primary {
title
description
link {
_linkType
... on _ExternalLink {
url
target
}
... on _Document {
_meta {
id
uid
}
}
}
image
}
}
}
}
__typename
... on HomeSlicesTech_stack_card {
type
label
variation {
__typename
... on HomeSlicesTech_stack_cardDefault {
items {
icon
tech_name
}
primary {
title
description
}
}
}
}
__typename
... on HomeSlicesCall_to_action {
type
label
variation {
__typename
... on HomeSlicesCall_to_actionDefault {
primary {
title
description
button_text
link {
_linkType
__typename
}
image
}
}
}
}
__typename
... on HomeSlicesHome_hero {
type
label
variation {
__typename
... on HomeSlicesHome_heroDefault {
primary {
title
button
link {
_linkType
__typename
}
image
}
}
}
}
}
_meta {
id
uid
type
tags
lang
}
_linkType
}
}
}
}
Hello @dirkkelderman, we ran a test query on our end. We noticed that there's a missing set to call the nested content inside the link field, you need to go one level further down like this:
I'm trying to get the links of the "HomeSlicesProject_card". The query I run there is with the nested link you suggested. So this is where the problem starts. I get that data in the explorer, not in the client.
I've tested it again and can't seem to see the error. If you want, you can send us the project code and the instructions to run it so we can see the err first hand.
Hi @dirkkelderman, I identified the problem. Link fields in Slice Machine are designed to link external web pages only. To create links to documents that need to use Content Relationship fields.
I will add a note to our documentation backlog to clarify this detail.
I tried that also, no luck. By the way, that still doesn't explains why the data in the chrome dev tool, and a console log, doesn't show the nested link documents. And the graphQL explorer does.
Hello! We are running into a very similar situation. Using Nextjs and Graphql.
When creating a Link in Slicemachine it states this
"A link to web, media, or Prismic document". And in the Prismic UI, when selecting what type of link this should be, we get this dropdown
Then, when using the Graphql playground for the project we do this
and both types of buttons return the data asked for.
However, when running the same query from localhost we can't get any attributes from the link type _Document. We only get the typename
Why is there a difference between the Graphql playground and my localhost? Are they querying different endpoints/APIs? This is a very bad experience for the client, i.e. having to have 2 fields, Documents link, and then External link, when it seems that you can have them both in the same field, just not anywhere else than in the graphql playground
No it's definitely linked to a document, it's linked to the frontpage that is very much populated with data. There's just a difference between the GraphQL playground response and the Apollo client response.
We're going to try to recreate the GraphQL playground request, by creating the string manually and then urlencoding it and doing a GET request. We tried doing that in Insomnia and it worked. Not sure why there's a difference between the two. The only difference we see is using the Apollo client + apollo-prismic-link for the requests.