Skip to content

Commit

Permalink
Merge branch 'main' into exhibition-highlight-tour-display-type
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpmccormick authored Jan 9, 2025
2 parents 727e9d1 + 14c46ca commit 9c5d750
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 193 deletions.
12 changes: 10 additions & 2 deletions pipeline/src/helpers/getGraphQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ export const allowedTypes = [
'visual-story',
'project',
'season',
];
] as const;
export type AddressablesAllowedTypes = (typeof allowedTypes)[number];

export const isAddressablesAllowedTypes = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type: any
): type is AddressablesAllowedTypes => {
return allowedTypes.includes(type);
};

export const getGraphQuery = ({
type,
isDetailed,
}: {
type: (typeof allowedTypes)[number];
type: AddressablesAllowedTypes;
isDetailed?: boolean;
}) => {
switch (type) {
Expand Down
26 changes: 26 additions & 0 deletions pipeline/src/scripts/documentIds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AddressablesAllowedTypes } from '@weco/content-pipeline/src/helpers/getGraphQuery';

const documentIds: { [key: string]: string | undefined } = {
article: 'ZdSMbREAACQA3j30',
webcomic: 'XkV9dREAAAPkNP0b',
event: 'ZfhSyxgAACQAkLPZ',
venue: 'Wsttgx8AAJeSNmJ4',
exhibition: 'Yzv9ChEAABfUrkVp',
book: 'ZijgihEAACMAtL-',
page: 'YdXSvhAAAIAW7YXQ',
'visual-story': 'Zs8EuRAAAB4APxrA',
'exhibition-text': 'Zs8mohAAAB4AP4sc',
'exhibition-highlight-tour': 'ZthrZRIAACQALvCC',
project: 'Ys1-xEAACEAguyS',
season: 'X84FvhIAACUAqiqp',
};

export const getDocumentId = ({
type,
id,
}: {
type: AddressablesAllowedTypes;
id?: string;
}): string | undefined => {
return id || documentIds[type];
};
166 changes: 64 additions & 102 deletions pipeline/src/scripts/testGraphQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import util from 'util';
import yargs from 'yargs';

import {
AddressablesAllowedTypes,
allowedTypes,
getGraphQuery,
isAddressablesAllowedTypes,
} from '@weco/content-pipeline/src/helpers/getGraphQuery';
import { createPrismicClient } from '@weco/content-pipeline/src/services/prismic';

import { getDocumentId } from './documentIds';

const { type, isDetailed, id } = yargs(process.argv.slice(2))
.usage('Usage: $0 --type [string] --isDetailed [boolean] --id [string]')
.options({
Expand All @@ -16,129 +20,87 @@ const { type, isDetailed, id } = yargs(process.argv.slice(2))
})
.parseSync();

const getGraphQueryName = ({
type,
isDetailed,
}: {
type: AddressablesAllowedTypes;
isDetailed?: boolean;
}) => {
switch (type) {
case 'article':
return isDetailed ? 'articlesQuery' : 'addressablesArticlesQuery';

case 'webcomic':
return 'webcomicsQuery';

case 'event':
return isDetailed ? 'eventDocumentsQuery' : 'addressablesEventsQuery';

case 'venue':
return 'venueQuery';

case 'exhibition':
return 'addressablesExhibitionsQuery';

case 'book':
return 'addressablesBooksQuery';

case 'page':
return 'addressablesPagesQuery';

case 'visual-story':
return 'addressablesVisualStoriesQuery';

case 'exhibition-text':
return 'addressablesExhibitionTextsQuery';

case 'exhibition-highlight-tour':
return 'addressablesExhibitionHighlightToursQuery';

case 'project':
return 'addressablesProjectsQuery';

case 'season':
return 'addressablesSeasonsQuery';

default:
console.error(`Allowed types are ${allowedTypes.join(', ')}.`);
process.exit(1);
}
};

async function main() {
if (!type) {
if (!isAddressablesAllowedTypes(type)) {
console.error(
`Please pass in the type you'd like to fetch, from this list ${allowedTypes.join(', ')}.\n e.g. --type=article`
);
process.exit(1);
}

const client = createPrismicClient();

const getGraphInfo = ({
type,
isDetailed,
id,
}: {
type: (typeof allowedTypes)[number];
isDetailed?: boolean;
id?: string;
}) => {
switch (type) {
case 'article':
return {
graphQueryName: isDetailed
? 'articlesQuery'
: 'addressablesArticlesQuery',
id: id || 'ZdSMbREAACQA3j30',
};

case 'webcomic':
return {
graphQueryName: 'webcomicsQuery',
id: id || 'XkV9dREAAAPkNP0b',
};

case 'event':
return {
graphQueryName: isDetailed
? 'eventDocumentsQuery'
: 'addressablesEventsQuery',
id: id || 'ZfhSyxgAACQAkLPZ',
};

case 'venue':
return {
graphQueryName: 'venueQuery',
id: id || 'Wsttgx8AAJeSNmJ4',
};

case 'exhibition':
return {
graphQueryName: 'addressablesExhibitionsQuery',
id: id || 'Yzv9ChEAABfUrkVp',
};

case 'book':
return {
graphQueryName: 'addressablesBooksQuery',
id: id || 'ZijgihEAACMAtL-k',
};

case 'page':
return {
graphQueryName: 'addressablesPagesQuery',
id: id || 'YdXSvhAAAIAW7YXQ',
};

case 'visual-story':
return {
graphQueryName: 'addressablesVisualStoriesQuery',
id: id || 'Zs8EuRAAAB4APxrA',
};

case 'exhibition-text':
return {
graphQueryName: 'addressablesExhibitionTextsQuery',
id: id || 'Zs8mohAAAB4AP4sc',
};

case 'exhibition-highlight-tour':
return {
graphQueryName: 'addressablesExhibitionHighlightToursQuery',
id: id || 'ZthrZRIAACQALvCC',
};

case 'project':
return {
graphQueryName: 'addressablesProjectsQuery',
id: id || 'Ys1-OxEAACEAguyS',
};

case 'season':
return {
graphQueryName: 'addressablesSeasonsQuery',
id: id || 'X84FvhIAACUAqiqp',
};

default:
console.error(`Allowed types are ${allowedTypes.join(', ')}.`);
process.exit(1);
}
};

const graphInfo = getGraphInfo({ type, isDetailed, id });
const documentId = getDocumentId({ type, id });
const graphQueryName = getGraphQueryName({ type, isDetailed });
const graphQuery = getGraphQuery({ type, isDetailed });

if (!graphInfo || !graphQuery) {
if (!documentId || !graphQueryName || !graphQuery) {
console.error('Something went wrong with queryResult', {
graphInfo,
documentId,
graphQueryName,
hasGraphQuery: !!graphQuery,
});
process.exit(1);
}

const doc = await client.getByID(graphInfo.id, {
const client = createPrismicClient();

const doc = await client.getByID(documentId, {
graphQuery: graphQuery.replace(/\n(\s+)/g, '\n'),
});

console.log(
util.inspect(doc, { showHidden: false, depth: null, colors: true })
);
console.log(
`\n\x1b[4mThis is the result from ${graphInfo.graphQueryName}.\x1b[0m\n`
);
console.log(`\n\x1b[4mThis is the result from ${graphQueryName}.\x1b[0m\n`);
}

main();
Loading

0 comments on commit 9c5d750

Please sign in to comment.