diff --git a/examples/sveltekit/kitchen-sink/.gitignore b/examples/sveltekit/kitchen-sink/.gitignore
new file mode 100644
index 000000000..c7e35228d
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/.gitignore
@@ -0,0 +1,25 @@
+node_modules
+
+# Output
+.output
+.vercel
+.netlify
+.wrangler
+/.svelte-kit
+/build
+
+# OS
+.DS_Store
+Thumbs.db
+
+# Env
+.env
+.env.*
+!.env.example
+!.env.test
+
+# Vite
+vite.config.js.timestamp-*
+vite.config.ts.timestamp-*
+
+package-lock.json
\ No newline at end of file
diff --git a/examples/sveltekit/kitchen-sink/package.json b/examples/sveltekit/kitchen-sink/package.json
new file mode 100644
index 000000000..dba80e1ac
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/package.json
@@ -0,0 +1,34 @@
+{
+ "name": "@faustjs/sveltekit-template-hierarchy-example",
+ "private": true,
+ "version": "0.1.0",
+ "license": "0BSD",
+ "type": "module",
+ "scripts": {
+ "dev": "vite dev",
+ "build": "vite build",
+ "preview": "vite preview",
+ "prepare": "svelte-kit sync || echo ''",
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
+ },
+ "devDependencies": {
+ "@faustjs/sveltekit": "workspace:*",
+ "@faustjs/template-hierarchy": "workspace:*",
+ "@faustjs/data-fetching": "workspace:*",
+ "@sveltejs/adapter-auto": "^6.0.0",
+ "@sveltejs/kit": "^2.16.0",
+ "@sveltejs/vite-plugin-svelte": "^5.0.0",
+ "svelte": "^5.0.0",
+ "svelte-check": "^4.0.0",
+ "vite": "^6.2.6"
+ },
+ "dependencies": {
+ "@tailwindcss/vite": "^4.1.12",
+ "@urql/core": "^5.1.1",
+ "@urql/exchange-persisted": "^4.3.1",
+ "deepmerge": "^4.3.1",
+ "graphql": "^16.11.0",
+ "tailwindcss": "^4.1.12"
+ }
+}
diff --git a/examples/sveltekit/kitchen-sink/src/app.html b/examples/sveltekit/kitchen-sink/src/app.html
new file mode 100644
index 000000000..77a5ff52c
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/app.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+ %sveltekit.head%
+
+
+ %sveltekit.body%
+
+
diff --git a/examples/sveltekit/kitchen-sink/src/components/BlogPostItem.svelte b/examples/sveltekit/kitchen-sink/src/components/BlogPostItem.svelte
new file mode 100644
index 000000000..5557310d5
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/components/BlogPostItem.svelte
@@ -0,0 +1,38 @@
+
+
+
+
+
+ {#if featuredImage}
+
+ {/if}
+
+
+
+
+ {@html excerpt}
+
+
+ Read more
+
diff --git a/examples/sveltekit/kitchen-sink/src/components/Header.svelte b/examples/sveltekit/kitchen-sink/src/components/Header.svelte
new file mode 100644
index 000000000..96c2878e4
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/components/Header.svelte
@@ -0,0 +1,15 @@
+
+
+
diff --git a/examples/sveltekit/kitchen-sink/src/hooks.server.js b/examples/sveltekit/kitchen-sink/src/hooks.server.js
new file mode 100644
index 000000000..fd6a32612
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/hooks.server.js
@@ -0,0 +1,14 @@
+import { dev } from '$app/environment';
+
+export const handle = async ({ event, resolve }) => {
+ if (
+ dev &&
+ event.url.pathname === '/.well-known/appspecific/com.chrome.devtools.json'
+ ) {
+ return new Response(undefined, { status: 404 });
+ }
+
+ return resolve(event, {
+ filterSerializedResponseHeaders: () => true, // basically get all headers
+ });
+};
diff --git a/examples/sveltekit/kitchen-sink/src/queries/getArchive.js b/examples/sveltekit/kitchen-sink/src/queries/getArchive.js
new file mode 100644
index 000000000..fc59b7f14
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/getArchive.js
@@ -0,0 +1,68 @@
+import gql from 'graphql-tag';
+
+export const GET_ARCHIVE = gql`
+ query GetArchivePage($uri: String!) {
+ nodeByUri(uri: $uri) {
+ ... on Category {
+ name
+ posts {
+ edges {
+ node {
+ id
+ title
+ content
+ date
+ uri
+ featuredImage {
+ node {
+ id
+ sourceUrl
+ altText
+ mediaDetails {
+ width
+ height
+ }
+ }
+ }
+ author {
+ node {
+ name
+ }
+ }
+ }
+ }
+ }
+ }
+ ... on Tag {
+ name
+ posts {
+ edges {
+ node {
+ id
+ title
+ content
+ date
+ uri
+ featuredImage {
+ node {
+ id
+ sourceUrl
+ altText
+ mediaDetails {
+ width
+ height
+ }
+ }
+ }
+ author {
+ node {
+ name
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+`;
diff --git a/examples/sveltekit/kitchen-sink/src/queries/getLayout.js b/examples/sveltekit/kitchen-sink/src/queries/getLayout.js
new file mode 100644
index 000000000..f278ee1af
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/getLayout.js
@@ -0,0 +1,10 @@
+import { gql } from 'graphql-tag';
+
+export const GET_LAYOUT = gql`
+ query GetLayout {
+ generalSettings {
+ title
+ description
+ }
+ }
+`;
diff --git a/examples/sveltekit/kitchen-sink/src/queries/getPage.js b/examples/sveltekit/kitchen-sink/src/queries/getPage.js
new file mode 100644
index 000000000..76646f1a5
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/getPage.js
@@ -0,0 +1,27 @@
+import gql from 'graphql-tag';
+
+export const GET_PAGE = gql`
+ query GetPage($databaseId: ID!, $asPreview: Boolean = false) {
+ page(id: $databaseId, idType: DATABASE_ID, asPreview: $asPreview) {
+ title
+ content
+ date
+ author {
+ node {
+ name
+ }
+ }
+ featuredImage {
+ node {
+ id
+ sourceUrl
+ altText
+ mediaDetails {
+ width
+ height
+ }
+ }
+ }
+ }
+ }
+`;
diff --git a/examples/sveltekit/kitchen-sink/src/queries/getPost.js b/examples/sveltekit/kitchen-sink/src/queries/getPost.js
new file mode 100644
index 000000000..30ba7b8d7
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/getPost.js
@@ -0,0 +1,27 @@
+import gql from 'graphql-tag';
+
+export const GET_POST = gql`
+ query GetPost($databaseId: ID!, $asPreview: Boolean = false) {
+ post(id: $databaseId, idType: DATABASE_ID, asPreview: $asPreview) {
+ title
+ content
+ date
+ author {
+ node {
+ name
+ }
+ }
+ featuredImage {
+ node {
+ id
+ sourceUrl
+ altText
+ mediaDetails {
+ width
+ height
+ }
+ }
+ }
+ }
+ }
+`;
diff --git a/examples/sveltekit/kitchen-sink/src/queries/getPosts.js b/examples/sveltekit/kitchen-sink/src/queries/getPosts.js
new file mode 100644
index 000000000..9cfcdd4e1
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/getPosts.js
@@ -0,0 +1,33 @@
+import gql from 'graphql-tag';
+
+export const GET_POSTS = gql`
+ query GetPosts {
+ posts {
+ edges {
+ node {
+ id
+ title
+ content
+ date
+ uri
+ featuredImage {
+ node {
+ id
+ sourceUrl
+ altText
+ mediaDetails {
+ width
+ height
+ }
+ }
+ }
+ author {
+ node {
+ name
+ }
+ }
+ }
+ }
+ }
+ }
+`;
diff --git a/examples/sveltekit/kitchen-sink/src/queries/templateQueries/archive.js b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/archive.js
new file mode 100644
index 000000000..a1829ce0f
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/archive.js
@@ -0,0 +1,11 @@
+import { GET_ARCHIVE } from '../getArchive.js';
+
+export const queries = [
+ {
+ name: 'getCategory',
+ query: GET_ARCHIVE,
+ variables: ({ uri }) => ({
+ uri,
+ }),
+ },
+];
diff --git a/examples/sveltekit/kitchen-sink/src/queries/templateQueries/home.js b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/home.js
new file mode 100644
index 000000000..c8bec2b39
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/home.js
@@ -0,0 +1,8 @@
+import { GET_POSTS } from '../getPosts.js';
+
+export const queries = [
+ {
+ name: 'getPosts',
+ query: GET_POSTS,
+ },
+];
diff --git a/examples/sveltekit/kitchen-sink/src/queries/templateQueries/index.js b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/index.js
new file mode 100644
index 000000000..270d3efa9
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/index.js
@@ -0,0 +1,6 @@
+import { queries as single } from './single.js';
+import { queries as page } from './page.js';
+import { queries as archive } from './archive.js';
+import { queries as home } from './home.js';
+
+export default { single, page, archive, home };
diff --git a/examples/sveltekit/kitchen-sink/src/queries/templateQueries/page.js b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/page.js
new file mode 100644
index 000000000..80fac5bc6
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/page.js
@@ -0,0 +1,12 @@
+import { GET_PAGE } from '../getPage.js';
+
+export const queries = [
+ {
+ name: 'getPage',
+ query: GET_PAGE,
+ variables: ({ databaseId }, ctx) => ({
+ databaseId,
+ asPreview: ctx?.asPreview,
+ }),
+ },
+];
diff --git a/examples/sveltekit/kitchen-sink/src/queries/templateQueries/single.js b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/single.js
new file mode 100644
index 000000000..952390ad5
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/queries/templateQueries/single.js
@@ -0,0 +1,12 @@
+import { GET_POST } from '../getPost.js';
+
+export const queries = [
+ {
+ name: 'getPost',
+ query: GET_POST,
+ variables: ({ databaseId }, ctx) => ({
+ databaseId,
+ asPreview: ctx?.asPreview,
+ }),
+ },
+];
diff --git a/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+layout.server.js b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+layout.server.js
new file mode 100644
index 000000000..2858bb8ba
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+layout.server.js
@@ -0,0 +1,25 @@
+import { print } from 'graphql';
+import { createDefaultClient, setGraphQLClient } from '@faustjs/sveltekit';
+import { GET_LAYOUT } from '../../queries/getLayout.js';
+import { WORDPRESS_URL } from '$env/static/private';
+
+export const load = async () => {
+ const client = createDefaultClient(WORDPRESS_URL);
+ setGraphQLClient(client);
+
+ if (client) {
+ try {
+ const { data } = await client.request(print(GET_LAYOUT));
+
+ return {
+ layoutData: data,
+ };
+ } catch (error) {
+ console.error('Error fetching layout data:', error);
+ }
+ }
+
+ return {
+ layoutData: null,
+ };
+};
diff --git a/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+layout.svelte b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+layout.svelte
new file mode 100644
index 000000000..966cab52e
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+layout.svelte
@@ -0,0 +1,11 @@
+
+
+
+
+ {@render children()}
+
\ No newline at end of file
diff --git a/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.js b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.js
new file mode 100644
index 000000000..ab81a48d0
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.js
@@ -0,0 +1,10 @@
+export const load = async (event) => {
+ const { data } = event;
+
+ const template = await import(`$wp/${data.templateData.template.id}.svelte`);
+
+ return {
+ ...data,
+ template: template.default,
+ };
+};
diff --git a/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.server.js b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.server.js
new file mode 100644
index 000000000..161c788b0
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.server.js
@@ -0,0 +1,63 @@
+import {
+ createDefaultClient,
+ setGraphQLClient,
+ uriToTemplate,
+} from '@faustjs/sveltekit';
+import { WORDPRESS_URL } from '$env/static/private';
+import { WP_PREVIEW_SECRET } from '$env/static/private';
+import availableQueries from '../../queries/templateQueries/index.js';
+import { fetchTemplateQueries } from '@faustjs/data-fetching';
+import { getAuthString } from '../../utils/getAuthString.js';
+
+export const load = async (event) => {
+ const {
+ params: { identifier },
+ url,
+ fetch,
+ } = event;
+
+ const searchParams = url?.searchParams;
+
+ // Determine if we are in preview mode based on the URL parameter and the secret
+ const isPreview =
+ searchParams.get('preview') === 'true' &&
+ WP_PREVIEW_SECRET === searchParams.get('secret');
+
+ const headers = isPreview ? { Authorization: getAuthString() } : undefined;
+
+ const client = createDefaultClient(WORDPRESS_URL, headers);
+ setGraphQLClient(client);
+
+ const variables = isPreview
+ ? {
+ id: identifier,
+ asPreview: true,
+ }
+ : { uri: identifier || '/' };
+
+ const templateData = await uriToTemplate({
+ fetch,
+ graphqlClient: client,
+ ...variables,
+ });
+
+ // Fetch template-specific queries using the same mechanism as Next.js
+ let queriesData = null;
+ try {
+ queriesData = await fetchTemplateQueries({
+ availableQueries,
+ templateData,
+ client,
+ locale: templateData?.seedNode?.locale,
+ });
+ } catch (error) {
+ console.error('Error fetching template queries:', error);
+ // Don't throw error, just continue with null queriesData
+ queriesData = null;
+ }
+
+ return {
+ templateData,
+ queriesData,
+ };
+};
diff --git a/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.svelte b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.svelte
new file mode 100644
index 000000000..ebd777c90
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/routes/[...identifier]/+page.svelte
@@ -0,0 +1,5 @@
+
+
+
diff --git a/examples/sveltekit/kitchen-sink/src/routes/api/templates/+server.js b/examples/sveltekit/kitchen-sink/src/routes/api/templates/+server.js
new file mode 100644
index 000000000..0bab26bae
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/routes/api/templates/+server.js
@@ -0,0 +1,31 @@
+import { readdir } from 'node:fs/promises';
+import { join } from 'node:path';
+import { json } from '@sveltejs/kit';
+const TEMPLATE_PATH = 'wp-templates';
+
+export const GET = async ({ url }) => {
+ const uri = url.searchParams.get('uri');
+
+ if (!uri) {
+ return new Response('Missing URI', { status: 400 });
+ }
+
+ const files = await readdir(join('src', TEMPLATE_PATH));
+
+ const templates = [];
+
+ for (const file of files) {
+ if (file.startsWith('+')) {
+ continue;
+ }
+
+ const slug = file.replace('.svelte', '');
+
+ templates.push({
+ id: slug,
+ path: join('/', TEMPLATE_PATH, slug),
+ });
+ }
+
+ return json(templates);
+};
diff --git a/examples/sveltekit/kitchen-sink/src/styles/globals.css b/examples/sveltekit/kitchen-sink/src/styles/globals.css
new file mode 100644
index 000000000..d4b507858
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/styles/globals.css
@@ -0,0 +1 @@
+@import 'tailwindcss';
diff --git a/examples/sveltekit/kitchen-sink/src/utils/getAuthString.js b/examples/sveltekit/kitchen-sink/src/utils/getAuthString.js
new file mode 100644
index 000000000..81c9e2214
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/utils/getAuthString.js
@@ -0,0 +1,9 @@
+import { WP_APP_PASSWORD } from '$env/static/private';
+import { WP_USERNAME } from '$env/static/private';
+
+// Forming the authentication string for WordPress App Password
+// More info: https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/
+
+export const getAuthString = () =>
+ 'Basic ' +
+ Buffer.from(WP_USERNAME + ':' + WP_APP_PASSWORD).toString('base64');
diff --git a/examples/sveltekit/kitchen-sink/src/wp-templates/archive.svelte b/examples/sveltekit/kitchen-sink/src/wp-templates/archive.svelte
new file mode 100644
index 000000000..04ab21085
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/wp-templates/archive.svelte
@@ -0,0 +1,32 @@
+
+
+
+
{name || 'Archive'}
+
+ {#if posts?.edges?.length > 0}
+ {#each posts.edges as item (item.node.id)}
+
+ {/each}
+ {:else if posts?.edges?.length === 0}
+
+
No Posts Found
+
There are no posts to display at this time.
+
+ {:else}
+
+
Loading Posts...
+
+ Fetching the latest posts from WordPress...
+
+
+ {/if}
+
+
\ No newline at end of file
diff --git a/examples/sveltekit/kitchen-sink/src/wp-templates/home.svelte b/examples/sveltekit/kitchen-sink/src/wp-templates/home.svelte
new file mode 100644
index 000000000..37eab4804
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/wp-templates/home.svelte
@@ -0,0 +1,31 @@
+
+
+
+ Home
+
+
+{#if posts?.edges?.length > 0}
+ {#each posts.edges as item (item.node.id)}
+
+ {/each}
+{:else if posts?.edges?.length === 0}
+
+
No Posts Found
+
There are no posts to display at this time.
+
+{:else}
+
+
Loading Posts...
+
+ Fetching the latest posts from WordPress...
+
+
+{/if}
+
diff --git a/examples/sveltekit/kitchen-sink/src/wp-templates/index.svelte b/examples/sveltekit/kitchen-sink/src/wp-templates/index.svelte
new file mode 100644
index 000000000..a6e144824
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/wp-templates/index.svelte
@@ -0,0 +1,39 @@
+
+
+
+ Template Not Found
+
+
+
+
+
+ Template Not Found
+
+
+ No specific template was found for the {contentType} type.
+ This content is being displayed using the default fallback template.
+
+
+
+
+
+
+
+ Debug Information
+
+
+
{JSON.stringify(templateData, null, 2)}
+
+
+
diff --git a/examples/sveltekit/kitchen-sink/src/wp-templates/page.svelte b/examples/sveltekit/kitchen-sink/src/wp-templates/page.svelte
new file mode 100644
index 000000000..edea3ea30
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/wp-templates/page.svelte
@@ -0,0 +1,31 @@
+
+
+
+ {title || 'Page'}
+
+
+
+
+
+ {title || 'Page Title'}
+
+
+
+ {#if featuredImage}
+
+ {/if}
+
+ {@html content || 'Page content would appear here...'}
+
+
diff --git a/examples/sveltekit/kitchen-sink/src/wp-templates/single.svelte b/examples/sveltekit/kitchen-sink/src/wp-templates/single.svelte
new file mode 100644
index 000000000..27ae3d19a
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/src/wp-templates/single.svelte
@@ -0,0 +1,30 @@
+
+
+
+ {title || 'Single Post'}
+
+
+
+
+
+ {title || 'Post Title'}
+
+
+
+ {#if featuredImage}
+
+ {/if}
+
+ {@html content || 'Post content would appear here...'}
+
+
diff --git a/examples/sveltekit/kitchen-sink/static/favicon.png b/examples/sveltekit/kitchen-sink/static/favicon.png
new file mode 100644
index 000000000..825b9e65a
Binary files /dev/null and b/examples/sveltekit/kitchen-sink/static/favicon.png differ
diff --git a/examples/sveltekit/kitchen-sink/svelte.config.js b/examples/sveltekit/kitchen-sink/svelte.config.js
new file mode 100644
index 000000000..3722c7ed4
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/svelte.config.js
@@ -0,0 +1,20 @@
+import adapter from '@sveltejs/adapter-auto';
+import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
+
+const config = {
+ // Consult https://svelte.dev/docs/kit/integrations
+ // for more information about preprocessors
+ preprocess: vitePreprocess(),
+ kit: {
+ // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
+ // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
+ // See https://svelte.dev/docs/kit/adapters for more information about adapters.
+ adapter: adapter(),
+ alias: {
+ $wp: 'src/wp-templates',
+ $components: 'src/components',
+ },
+ },
+};
+
+export default config;
diff --git a/examples/sveltekit/kitchen-sink/vite.config.ts b/examples/sveltekit/kitchen-sink/vite.config.ts
new file mode 100644
index 000000000..6daefe409
--- /dev/null
+++ b/examples/sveltekit/kitchen-sink/vite.config.ts
@@ -0,0 +1,7 @@
+import { sveltekit } from '@sveltejs/kit/vite';
+import { defineConfig } from 'vite';
+import tailwindcss from '@tailwindcss/vite';
+
+export default defineConfig({
+ plugins: [tailwindcss(), sveltekit()],
+});
diff --git a/packages/sveltekit/templateHierarchy.js b/packages/sveltekit/templateHierarchy.js
index e9497fbe9..a82cae0e3 100644
--- a/packages/sveltekit/templateHierarchy.js
+++ b/packages/sveltekit/templateHierarchy.js
@@ -15,7 +15,13 @@ import { error } from '@sveltejs/kit';
* @param {import('../template-hierarchy/types.js').UriToTemplateOptions} options - The options object
* @returns {Promise} The resolved template data
*/
-export async function uriToTemplate({ fetch, uri, graphqlClient }) {
+export async function uriToTemplate({
+ fetch,
+ uri,
+ graphqlClient,
+ id,
+ asPreview,
+}) {
/** @type {import('../template-hierarchy/types.js').TemplateData} */
const returnData = {
uri,
@@ -23,6 +29,7 @@ export async function uriToTemplate({ fetch, uri, graphqlClient }) {
availableTemplates: undefined,
possibleTemplates: undefined,
template: undefined,
+ seedNode: undefined,
};
// Get the GraphQL client - use provided one or get configured one
@@ -30,16 +37,22 @@ export async function uriToTemplate({ fetch, uri, graphqlClient }) {
const { data, error: errorMessage } = await getSeedQuery({
uri,
graphqlClient: client,
+ id,
+ asPreview,
});
returnData.seedQuery = { data, error: errorMessage };
+ const seedNode = data?.nodeByUri || data?.contentNode;
+
+ returnData.seedNode = seedNode ?? error;
+
if (errorMessage) {
console.error('Error fetching seedQuery:', errorMessage);
throw error(500, 'Error fetching seedQuery');
}
- if (!data?.nodeByUri) {
+ if (!seedNode) {
console.error('HTTP/404 - Not Found in WordPress:', uri);
throw error(404, 'Not Found');
}
@@ -60,7 +73,7 @@ export async function uriToTemplate({ fetch, uri, graphqlClient }) {
throw error(500, 'No available templates');
}
- const possibleTemplates = getPossibleTemplates(data.nodeByUri);
+ const possibleTemplates = getPossibleTemplates(seedNode);
returnData.possibleTemplates = possibleTemplates;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7e18df114..3d1ecb3d0 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -79,10 +79,10 @@ importers:
version: link:../../../packages/template-hierarchy
'@tailwindcss/vite':
specifier: ^4.1.12
- version: 4.1.12(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ version: 4.1.12(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
astro:
specifier: ^5.1.1
- version: 5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3)
+ version: 5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3)(yaml@2.8.1)
graphql:
specifier: ^16.9.0
version: 16.11.0
@@ -107,7 +107,7 @@ importers:
version: link:../../../packages/template-hierarchy
astro:
specifier: ^5.1.1
- version: 5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3)
+ version: 5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3)(yaml@2.8.1)
graphql:
specifier: ^16.9.0
version: 16.11.0
@@ -193,6 +193,55 @@ importers:
specifier: ^15.1.3
version: 15.4.5(eslint@8.57.1)(typescript@5.8.3)
+ examples/sveltekit/kitchen-sink:
+ dependencies:
+ '@tailwindcss/vite':
+ specifier: ^4.1.12
+ version: 4.1.12(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
+ '@urql/core':
+ specifier: ^5.1.1
+ version: 5.2.0(graphql@16.11.0)
+ '@urql/exchange-persisted':
+ specifier: ^4.3.1
+ version: 4.3.1(@urql/core@5.2.0(graphql@16.11.0))
+ deepmerge:
+ specifier: ^4.3.1
+ version: 4.3.1
+ graphql:
+ specifier: ^16.11.0
+ version: 16.11.0
+ tailwindcss:
+ specifier: ^4.1.12
+ version: 4.1.12
+ devDependencies:
+ '@faustjs/data-fetching':
+ specifier: workspace:*
+ version: link:../../../packages/data-fetching
+ '@faustjs/sveltekit':
+ specifier: workspace:*
+ version: link:../../../packages/sveltekit
+ '@faustjs/template-hierarchy':
+ specifier: workspace:*
+ version: link:../../../packages/template-hierarchy
+ '@sveltejs/adapter-auto':
+ specifier: ^6.0.0
+ version: 6.1.0(@sveltejs/kit@2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))
+ '@sveltejs/kit':
+ specifier: ^2.16.0
+ version: 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
+ '@sveltejs/vite-plugin-svelte':
+ specifier: ^5.0.0
+ version: 5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
+ svelte:
+ specifier: ^5.0.0
+ version: 5.38.1
+ svelte-check:
+ specifier: ^4.0.0
+ version: 4.3.1(picomatch@4.0.3)(svelte@5.38.1)(typescript@5.8.3)
+ vite:
+ specifier: ^6.2.6
+ version: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
+
examples/sveltekit/template-hierarchy:
dependencies:
'@urql/core':
@@ -216,13 +265,13 @@ importers:
version: link:../../../packages/template-hierarchy
'@sveltejs/adapter-auto':
specifier: ^6.0.0
- version: 6.1.0(@sveltejs/kit@2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))
+ version: 6.1.0(@sveltejs/kit@2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))
'@sveltejs/kit':
specifier: ^2.16.0
- version: 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ version: 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
'@sveltejs/vite-plugin-svelte':
specifier: ^5.0.0
- version: 5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ version: 5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
svelte:
specifier: ^5.0.0
version: 5.38.1
@@ -231,7 +280,7 @@ importers:
version: 4.3.1(picomatch@4.0.3)(svelte@5.38.1)(typescript@5.8.3)
vite:
specifier: ^6.2.6
- version: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)
+ version: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
packages/astro:
dependencies:
@@ -243,7 +292,7 @@ importers:
version: link:../template-hierarchy
astro:
specifier: ^5.0.0
- version: 5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3)
+ version: 5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3)(yaml@2.8.1)
graphql:
specifier: ^16.8.1
version: 16.11.0
@@ -287,7 +336,7 @@ importers:
version: link:../template-hierarchy
'@sveltejs/kit':
specifier: ^2.0.0
- version: 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ version: 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
graphql:
specifier: ^16.8.1
version: 16.11.0
@@ -4186,6 +4235,11 @@ packages:
resolution: {integrity: sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==}
engines: {node: '>=18'}
+ yaml@2.8.1:
+ resolution: {integrity: sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==}
+ engines: {node: '>= 14.6'}
+ hasBin: true
+
yargs-parser@21.1.1:
resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==}
engines: {node: '>=12'}
@@ -5083,15 +5137,15 @@ snapshots:
dependencies:
acorn: 8.14.1
- '@sveltejs/adapter-auto@6.1.0(@sveltejs/kit@2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))':
+ '@sveltejs/adapter-auto@6.1.0(@sveltejs/kit@2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))':
dependencies:
- '@sveltejs/kit': 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ '@sveltejs/kit': 2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
- '@sveltejs/kit@2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))':
+ '@sveltejs/kit@2.28.0(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))':
dependencies:
'@standard-schema/spec': 1.0.0
'@sveltejs/acorn-typescript': 1.0.5(acorn@8.14.1)
- '@sveltejs/vite-plugin-svelte': 5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ '@sveltejs/vite-plugin-svelte': 5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
'@types/cookie': 0.6.0
acorn: 8.14.1
cookie: 0.6.0
@@ -5104,27 +5158,27 @@ snapshots:
set-cookie-parser: 2.7.1
sirv: 3.0.1
svelte: 5.38.1
- vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)
+ vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
- '@sveltejs/vite-plugin-svelte-inspector@4.0.1(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))':
+ '@sveltejs/vite-plugin-svelte-inspector@4.0.1(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))':
dependencies:
- '@sveltejs/vite-plugin-svelte': 5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ '@sveltejs/vite-plugin-svelte': 5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
debug: 4.4.1
svelte: 5.38.1
- vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)
+ vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
transitivePeerDependencies:
- supports-color
- '@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))':
+ '@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))':
dependencies:
- '@sveltejs/vite-plugin-svelte-inspector': 4.0.1(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ '@sveltejs/vite-plugin-svelte-inspector': 4.0.1(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)))(svelte@5.38.1)(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
debug: 4.4.1
deepmerge: 4.3.1
kleur: 4.1.5
magic-string: 0.30.17
svelte: 5.38.1
- vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)
- vitefu: 1.1.1(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
+ vitefu: 1.1.1(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
transitivePeerDependencies:
- supports-color
@@ -5279,12 +5333,12 @@ snapshots:
postcss: 8.5.6
tailwindcss: 4.1.11
- '@tailwindcss/vite@4.1.12(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))':
+ '@tailwindcss/vite@4.1.12(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))':
dependencies:
'@tailwindcss/node': 4.1.12
'@tailwindcss/oxide': 4.1.12
tailwindcss: 4.1.12
- vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)
+ vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
'@tybys/wasm-util@0.10.0':
dependencies:
@@ -5665,7 +5719,7 @@ snapshots:
ast-types-flow@0.0.8: {}
- astro@5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3):
+ astro@5.12.8(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.8.3)(yaml@2.8.1):
dependencies:
'@astrojs/compiler': 2.12.2
'@astrojs/internal-helpers': 0.7.1
@@ -5721,8 +5775,8 @@ snapshots:
unist-util-visit: 5.0.0
unstorage: 1.16.1
vfile: 6.0.3
- vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)
- vitefu: 1.1.1(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1))
+ vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
+ vitefu: 1.1.1(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1))
xxhash-wasm: 1.1.0
yargs-parser: 21.1.1
yocto-spinner: 0.2.3
@@ -8713,7 +8767,7 @@ snapshots:
'@types/unist': 3.0.3
vfile-message: 4.0.3
- vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1):
+ vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1):
dependencies:
esbuild: 0.25.8
fdir: 6.4.6(picomatch@4.0.3)
@@ -8725,10 +8779,11 @@ snapshots:
fsevents: 2.3.3
jiti: 2.5.1
lightningcss: 1.30.1
+ yaml: 2.8.1
- vitefu@1.1.1(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)):
+ vitefu@1.1.1(vite@6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)):
optionalDependencies:
- vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)
+ vite: 6.3.5(jiti@2.5.1)(lightningcss@1.30.1)(yaml@2.8.1)
web-namespaces@2.0.1: {}
@@ -8823,6 +8878,9 @@ snapshots:
yallist@5.0.0: {}
+ yaml@2.8.1:
+ optional: true
+
yargs-parser@21.1.1: {}
yocto-queue@0.1.0: {}