-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from AmazeeLabs/SLB-445-waku-decap
SLB-445: Integrate Waku with Decap
- Loading branch information
Showing
42 changed files
with
2,677 additions
and
1,531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ autoload.json | |
|
||
# A workaround to avoid turbo caching locally. | ||
turbo-seed.txt | ||
|
||
# Executor typescript build | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { AnyOperationId, OperationVariables } from '@custom/schema'; | ||
|
||
export function createDrupalExecutor(host: string) { | ||
return async function <OperationId extends AnyOperationId>( | ||
id: OperationId, | ||
variables?: OperationVariables<OperationId>, | ||
) { | ||
const url = new URL(`${host}/graphql`); | ||
const isMutation = id.includes('Mutation:'); | ||
const publicUrl = | ||
typeof window !== 'undefined' | ||
? new URL(window.location.href) | ||
: new URL(process.env.WAKU_PUBLIC_URL || 'http://127.0.0.1:8000'); | ||
const headers = { | ||
'SLB-Forwarded-Proto': publicUrl.protocol.slice(0, -1), | ||
'SLB-Forwarded-Host': publicUrl.hostname, | ||
'SLB-Forwarded-Port': publicUrl.port, | ||
'X-Forwarded-Proto': publicUrl.protocol.slice(0, -1), | ||
'X-Forwarded-Host': publicUrl.hostname, | ||
'X-Forwarded-Port': publicUrl.port, | ||
}; | ||
|
||
const requestInit = ( | ||
isMutation | ||
? { | ||
method: 'POST', | ||
credentials: 'include', | ||
body: JSON.stringify({ | ||
queryId: id, | ||
variables: variables || {}, | ||
}), | ||
headers: { | ||
...headers, | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
: { | ||
credentials: 'include', | ||
headers, | ||
} | ||
) satisfies RequestInit; | ||
|
||
if (!isMutation) { | ||
url.searchParams.set('queryId', id); | ||
url.searchParams.set('variables', JSON.stringify(variables || {})); | ||
} | ||
|
||
try { | ||
const { data, errors } = await (await fetch(url, requestInit)).json(); | ||
if (errors) { | ||
console.error('GraphQL error:', errors); | ||
if (!data) { | ||
throw new Error('GraphQL error: ' + JSON.stringify(errors)); | ||
} | ||
} | ||
return data; | ||
} catch (error) { | ||
console.error('Fetch error:', error); | ||
throw new Error(`Fetch error: ${error}`); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "NodeNext", | ||
"declaration": true, | ||
"moduleResolution": "NodeNext", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"checkJs": true, | ||
"outDir": "dist", | ||
"jsx": "react-jsx" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,54 @@ | ||
import { expect, test, vi } from 'vitest'; | ||
import { ListPagesQuery, ViewPageQuery } from '@custom/schema'; | ||
import { expect, test } from 'vitest'; | ||
import { z } from 'zod'; | ||
|
||
import { getPages } from '..'; | ||
import { createExecutor } from '../graphql'; | ||
import { pageResolvers } from './page'; | ||
|
||
vi.mock('../helpers/path', () => ({ | ||
path: `${new URL(import.meta.url).pathname | ||
.split('/') | ||
.slice(0, -1) | ||
.join('/')}/../..`, | ||
})); | ||
const exec = createExecutor([pageResolvers('./')]); | ||
|
||
test('getPages', () => { | ||
expect(() => getPages()).not.toThrow(); | ||
const listPagesSchema = z.object({ | ||
ssgPages: z.object({ | ||
rows: z.array( | ||
z.object({ translations: z.array(z.object({ path: z.string() })) }), | ||
), | ||
total: z.number(), | ||
}), | ||
}); | ||
|
||
test('retrieve all pages', async () => { | ||
const result = await exec(ListPagesQuery, { args: '' }); | ||
const parsed = listPagesSchema.safeParse(result); | ||
|
||
expect(parsed.success).toBe(true); | ||
}); | ||
|
||
test('load a page by path', async () => { | ||
const list = listPagesSchema.parse(await exec(ListPagesQuery, { args: '' })); | ||
|
||
const path = list.ssgPages.rows[0].translations[0].path; | ||
|
||
const result = await exec(ViewPageQuery, { pathname: path }); | ||
|
||
const parsed = z | ||
.object({ | ||
page: z.object({ | ||
path: z.string(), | ||
title: z.string(), | ||
locale: z.string(), | ||
translations: z.array( | ||
z.object({ | ||
locale: z.string(), | ||
path: z.string(), | ||
}), | ||
), | ||
}), | ||
}) | ||
.safeParse(result); | ||
|
||
if (!parsed.success) { | ||
console.error(parsed.error); | ||
} | ||
expect(parsed.success).toBe(true); | ||
expect(parsed.data?.page.path).toEqual(path); | ||
}); |
Oops, something went wrong.