Graphql query works in playground not on client

Hi there,

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, thanks for reaching out.
What do you see if you log the API response of the query, can you see the content of the link?

Hi Pau,

In the console (or terminal) the nested link data doesn't show either.

I see, could you send us the URL of your repository so we can run a test?

https://dirk-portfolio-website.prismic.io

Hi @Pau , any news on this perhaps? :smiley:

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:

Aside from this, we couldn't see any problems with the API response.

Hi Pau,

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.

Below you can see the query I do, and the response in the explorer. Here I fetch the nested data, linkType Link.document.

Below you can see the response, logged in the console (chrome devtools). It's missing this nested linkType (and the meta).

I see. Can you share the complete page query?
I'm not sure why the content isn't getting displayed.

Hi Pau,

I tried two querries:

query {
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
}
}
}
}

{
home(uid: "home", lang: "nl-nl") {
slices {
... on HomeSlicesProject_card {
variation {
... on HomeSlicesProject_cardDefault {
primary {
title
description
image
link {
_linkType
... on _Document {
_meta {
id
uid
}
}
... on _ExternalLink {
url
target
}
}
}
}
}
}
... on HomeSlicesTech_stack_card {
variation {
... on HomeSlicesTech_stack_cardDefault {
primary {
title
description
}
items {
icon
tech_name
}
}
}
}
... on HomeSlicesCall_to_action {
variation {
... on HomeSlicesCall_to_actionDefault {
primary {
title
description
button_text
image
link {
_linkType
}
}
}
}
}
... on HomeSlicesHome_hero {
variation {
... on HomeSlicesHome_heroDefault {
primary {
title
button
image
link {
... on _Document {
_meta {
id
uid
}
}
}
}
}
}
}
}
}
}

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.

Sure thing!

You can find the repo right here: https://github.com/dirkkelderman/portfolio-website-dirk

Simple NextJS, npm/yarn and run dev to get it going.

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.

Hi Pau,

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.

Did you change the field to a Content Relationship field?

The GraphiQL tool probably still "reads" all fields equally.
We still need to standardize this functionality.

Hello! We are running into a very similar situation. Using Nextjs and Graphql.

When creating a Link in Slicemachine it states this
image
"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
image

Then, when using the Graphql playground for the project we do this
image
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
image

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 :person_shrugging:

1 Like

Is there a document linked in the field? Maybe it's returning an empty object cause there's no document

Thanks for the reply! :slight_smile:

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.

Encounter the same issue, any news about this subject ?