Skip to content

Commit

Permalink
Adjust caches
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Aug 3, 2024
1 parent 73d637f commit 408804d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/lib/gql/gql-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export const graphqlClient = (requestConfig: Omit<RequestInit, "method"> = {}, i
export const buildHeaders = (headers?: HeadersInit, isPreviewMode?: boolean): Headers => {
const requestHeaders = new Headers(headers)
// If viewing while in preview mode, use the admin credentials if they are available. Fall back to the basic credentials.
const authCreds = (
isPreviewMode ? process.env.DRUPAL_BASIC_AUTH_ADMIN || process.env.DRUPAL_BASIC_AUTH : process.env.DRUPAL_BASIC_AUTH
) as string
const authCreds = (isPreviewMode ? process.env.DRUPAL_BASIC_AUTH : process.env.DRUPAL_BASIC_AUTH) as string

requestHeaders.set("Authorization", "Basic " + Buffer.from(authCreds).toString("base64"))
return requestHeaders
Expand Down
6 changes: 3 additions & 3 deletions src/lib/gql/gql-queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const getConfigPage = async <T extends ConfigPagesUnion>(
async () => {
let query: ConfigPagesQuery
try {
query = await graphqlClient({next: {tags: ["config-pages"]}}).ConfigPages()
query = await graphqlClient({cache: "no-cache"}).ConfigPages()
} catch (e) {
console.warn("Unable to fetch config pages: " + (e instanceof Error && e.stack))
return
Expand Down Expand Up @@ -104,7 +104,7 @@ export const getMenu = cache(async (name?: MenuAvailable, maxLevels?: number): P

const getData = nextCache(
async () => {
const menu = await graphqlClient({next: {tags: [`menu:${menuName}`]}}).Menu({name})
const menu = await graphqlClient({cache: "no-cache"}).Menu({name})
const menuItems = (menu.menu?.items || []) as MenuItem[]

const filterInaccessible = (items: MenuItem[], level: number): MenuItem[] => {
Expand Down Expand Up @@ -133,7 +133,7 @@ export const getAllNodes = nextCache(
const cursors: Omit<AllNodesQueryVariables, "first"> = {}

while (fetchMore) {
nodeQuery = await graphqlClient({next: {tags: ["paths"]}}).AllNodes({first: 1000, ...cursors})
nodeQuery = await graphqlClient({cache: "no-cache"}).AllNodes({first: 1000, ...cursors})
queryKeys = Object.keys(nodeQuery) as (keyof AllNodesQuery)[]
fetchMore = false

Expand Down

0 comments on commit 408804d

Please sign in to comment.