-
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.
- Loading branch information
Showing
38 changed files
with
2,013 additions
and
673 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
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
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,32 +1,35 @@ | ||
'use client'; | ||
|
||
import { | ||
drupalOperator, | ||
registerOperator, | ||
ViewPageQuery, | ||
} from '@custom/schema'; | ||
import { Loading } from '@custom/ui/routes/Loading'; | ||
// import { Page } from '@custom/ui/routes/Page'; | ||
import { PreviewDrupalPageQuery, ViewPageQuery } from '@custom/schema'; | ||
import { registerExecutor } from '@custom/ui'; | ||
import { Page } from '@custom/ui/routes/Page'; | ||
import React from 'react'; | ||
|
||
// import { usePreviewParameters } from '../utils/preview'; | ||
import { drupalExecutor } from '../utils/drupal-executor'; | ||
import { usePreviewParameters } from '../utils/preview'; | ||
|
||
const previewExecutor = drupalExecutor( | ||
`${process.env.GATSBY_DRUPAL_URL}/graphql`, | ||
); | ||
|
||
export default function PagePreview() { | ||
// const { nid, rid, lang } = usePreviewParameters(); | ||
registerOperator( | ||
drupalOperator(`${process.env.GATSBY_DRUPAL_URL}/graphql`), | ||
ViewPageQuery, | ||
); | ||
return <Loading />; | ||
// const data = useOperation( | ||
// PreviewPageQuery, | ||
// nid && rid && lang | ||
// ? { | ||
// id: nid, | ||
// rid: rid, | ||
// locale: lang, | ||
// } | ||
// : undefined, | ||
// ); | ||
// return data?.previewPage ? <Page page={data.previewPage} /> : <Loading />; | ||
const { nid, rid, lang } = usePreviewParameters(); | ||
|
||
registerExecutor(ViewPageQuery, () => { | ||
return new Promise<ViewPageQuery>((resolve, reject) => { | ||
if (nid && rid && lang) { | ||
previewExecutor(PreviewDrupalPageQuery, { | ||
id: nid, | ||
locale: lang, | ||
rid, | ||
}) | ||
.then((result) => { | ||
if (result.preview) { | ||
resolve({ page: result.preview }); | ||
} | ||
return; | ||
}) | ||
.catch((error) => reject(error)); | ||
} | ||
}); | ||
}); | ||
return <Page id="preview" locale="en" />; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// TODO: Duplication of types generated in the schema package. | ||
export type OperationId< | ||
TQueryResult extends any, | ||
TQueryVariables extends any, | ||
> = string & { | ||
___query_result: TQueryResult; | ||
___query_variables: TQueryVariables; | ||
}; | ||
|
||
export type AnyOperationId = OperationId<any, any>; | ||
|
||
export type OperationResult<TQueryID extends OperationId<any, any>> = | ||
TQueryID['___query_result']; | ||
|
||
export type OperationVariables<TQueryID extends OperationId<any, any>> = | ||
TQueryID['___query_variables']; | ||
|
||
/** | ||
* Create an executor that operates against a Drupal endpoint. | ||
* TODO: Fix typing after moving Operation types into executors package. | ||
*/ | ||
export function drupalExecutor(endpoint: string) { | ||
return async function <OperationId extends AnyOperationId>( | ||
id: OperationId, | ||
variables?: OperationVariables<OperationId>, | ||
) { | ||
const url = new URL(endpoint, window.location.origin); | ||
url.searchParams.set('queryId', id); | ||
url.searchParams.set('variables', JSON.stringify(variables)); | ||
const { data, errors } = await ( | ||
await fetch(url, { | ||
credentials: 'include', | ||
headers: { | ||
'SLB-Forwarded-Proto': window.location.protocol.slice(0, -1), | ||
'SLB-Forwarded-Host': window.location.hostname, | ||
'SLB-Forwarded-Port': window.location.port, | ||
}, | ||
}) | ||
).json(); | ||
if (errors) { | ||
throw errors; | ||
} | ||
return data; | ||
}; | ||
} |
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,4 @@ | ||
export default { | ||
extends: ['@amazeelabs/eslint-config'], | ||
root: true, | ||
}; |
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 @@ | ||
build |
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 @@ | ||
"@amazeelabs/prettier-config" |
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,29 @@ | ||
{ | ||
"name": "@amazeelabs/executors", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"type": "module", | ||
"scripts": { | ||
"prep": "tsc", | ||
"build": "tsc", | ||
"test:unit": "vitest run", | ||
"test:static": "tsc --noEmit && eslint \"**/*.{ts,tsx,js,jsx}\" --ignore-path=\"./.gitignore\" --fix" | ||
}, | ||
"keywords": [], | ||
"author": "Amazee Labs <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@types/lodash-es": "^4.17.12", | ||
"lodash-es": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@amazeelabs/eslint-config": "^1.4.43", | ||
"@amazeelabs/prettier-config": "^1.1.3", | ||
"eslint": "^8.43.0", | ||
"prettier": "^2.8.8", | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.1.0" | ||
} | ||
} |
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 @@ | ||
export { createExecutor, registerExecutor, clearRegistry } from './lib.js'; |
Oops, something went wrong.