Hello to all,
I'm coming to you because I'm stuck with my requests to Prismic in my NextJS application.
I have a main request that calls my custom type homepage
which contains all the slices on the page.
For the example I'm going to base it on the blog
slice:
This slice contains static information that I can retrieve.
However, I have custom posts of type post
inside this slice that appear in items
but do not contain the post information (see below), post
also contains a custom type cta
.
I realized that I needed to use graphQuery
to access the contents of post
and cta
.
The hierarchy of this part of the content giving :
blog
( slice ) => post
( content relationship, repeatable, custom type ) => cta
( content relationship, custom type )
For a better readability and less code I took only the query that retrieves my custom type post
and must also retrieve the custom type cta
inside
Note: My request works in the Prismic dashboard by testing it in: my-repo/graphql
I currently have this result:
{
"id": "ZDQmzhAAACIADPKP",
"type": "cta",
"tags": [],
"lang": "fr-fr",
"slug": "discover-our-pms",
"first_publication_date": "2023-04-10T15:10:14+0000",
"last_publication_date": "2023-04-12T14:19:16+0000",
"uid": "management",
"link_type": "Document",
"isBroken": false
}
I have this query currently:
export async function getStaticProps({ previewData }: GetStaticPropsContext) {
const client = createClient({ previewData });
// Query page
const page = await client.getSingle("homepage");
const posts = await client.getAllByType("post", {
graphQuery: `{
allPosts {
edges {
node {
image
icon
title
body
list
cta {
... on Cta {
text
url {
_linkType
}
}
}
}
}
}
}
`,
});
return {
props: {
page,
posts,
},
};
}
Thank you very much for your help