Skip to content

Commit

Permalink
Add options for workspace name and dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
hlubek committed Jul 24, 2024
1 parent 1f3952e commit bdb699a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/server/utils/dataLoader.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import log from 'loglevel';
import { headers as nextHeaders } from 'next/headers';
import { cache } from 'react';
import { stringify } from 'qs';
import { cache } from 'react';

import {
ApiErrors,
DataLoaderOptions,
DocumentResult,
NeosData,
OptionalOption,
QueryOptions,
QueryResult,
SiteData,
} from '../../types';
Expand Down Expand Up @@ -151,7 +152,7 @@ export const loadSiteProps = async <CustomSiteData extends SiteData = SiteData>(
export const loadQueryResult = async <M, D>(
queryName: string,
params: any,
opts?: DataLoaderOptions & OptionalOption
opts?: DataLoaderOptions & OptionalOption & QueryOptions
) => {
const apiUrl = process.env.NEOS_BASE_URL;
if (!apiUrl && opts?.optional) {
Expand All @@ -162,7 +163,12 @@ export const loadQueryResult = async <M, D>(
}

const startTime = Date.now();
const fetchUrl = apiUrl + '/neos/content-api/query/' + encodeURIComponent(queryName) + '?' + stringify({ params });
const queryParams = stringify({
params,
workspaceName: opts?.workspaceName,
dimensions: opts?.dimensions,
});
const fetchUrl = apiUrl + '/neos/content-api/query/' + encodeURIComponent(queryName) + '?' + queryParams;

log.debug('fetching data from content API from URL', fetchUrl);

Expand Down
11 changes: 11 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,14 @@ export type QueryResult<D, M> = {
data: D[];
meta: M;
};

export type QueryOptions = {
/**
* Optional workspace name for the node context in the query.
*/
workspaceName?: string;
/**
* Optional dimensions for the node context in the query.
*/
dimensions?: Record<string, string[]>;
};

0 comments on commit bdb699a

Please sign in to comment.