Skip to content

Commit

Permalink
Merge branch 'master' into 29184-implement-breadcrumb-navigation-for-…
Browse files Browse the repository at this point in the history
…categories
  • Loading branch information
nicobytes authored Aug 2, 2024
2 parents c35d878 + 25fb12a commit 4391278
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions examples/nextjs/src/utils/gql.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const API_URL = `${process.env.NEXT_PUBLIC_DOTCMS_HOST}/api/v1/graphql`;
const GRAPHQL_ENPOINT = `/api/v1/graphql`;

/**
* Get the GraphQL query for a page
Expand Down Expand Up @@ -93,17 +93,27 @@ function getGraphQLPageQuery({ path, language_id, mode}) {
*/
export const getGraphQLPageData = async (params) => {
const query = getGraphQLPageQuery(params);
const url = new URL(GRAPHQL_ENPOINT, process.env.NEXT_PUBLIC_DOTCMS_HOST);

const res = await fetch(API_URL, {
method: "POST",
headers: {
"Cookie": `access_token=${process.env.NEXT_PUBLIC_DOTCMS_AUTH_TOKEN}`,
"Content-Type": "application/json",
"dotcachettl": "0" // Bypasses GraphQL cache
},
body: JSON.stringify({ query }),
cache: "no-cache", // Invalidate cache for Next.js
});
const { data } = await res.json();
return data;
try {
const res = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.NEXT_PUBLIC_DOTCMS_AUTH_TOKEN}`,
"Content-Type": "application/json",
"dotcachettl": "0" // Bypasses GraphQL cache
},
body: JSON.stringify({ query }),
cache: "no-cache", // Invalidate cache for Next.js
});
const { data } = await res.json();
return data;
} catch(err) {
console.group("Error fetching Page");
console.warn("Check your URL or DOTCMS_HOST: ", url.toString());
console.error(err);
console.groupEnd();

return { page: null };
}
};

0 comments on commit 4391278

Please sign in to comment.