getStaticPaths() suggested usage #515
-
I don't see any mention of how to utilize Are there any solutions or documentation on how to best perform a query within |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For those that may come to this and are wondering what resolved this issue, here was my solution. When issuing GQTY queries from within Example snippet: import { client } from "client";
import { getArrayFields } from "gqty";
// ...
export async function getStaticPaths() {
const people = await client.client.inlineResolved(() => {
return getArrayFields(
client.client.query.people()?.nodes, // used arbitrary query for people()
"slug" // pull whatever field(s) you need
);
});
const peopleSlugs = people.map((person) => {
return {
params: {
person: person.slug,
},
};
});
// ...
return {
paths: peopleSlugs,
// ...
};
} |
Beta Was this translation helpful? Give feedback.
For those that may come to this and are wondering what resolved this issue, here was my solution.
When issuing GQTY queries from within
getStaticPaths()
, bothclient.client.resolved()
andclient.client.inlineResolved()
were returning with a proxy yielding undefined data. Just returning the query we wanted (ie.client.client.query.generalSettings
) was not sufficient to then access such values outside of theinlineResolved()
callback. To get non-undefined data, you need to specify what fields you want to pull in within theinlineResolved()
callback using one of GQTY's core helper functions. We usedgetArrayFields()
as that was more appropriate for the use case withingetStaticPaths()
.Examp…