- Created a new cache-proxy application using NestJS, including essential files such as Dockerfile, .gitignore, and .eslintrc.js. - Implemented core application structure with AppModule, ProxyModule, and ProxyController for handling GraphQL requests. - Configured caching with Redis and established environment variable management using Zod for validation. - Added utility functions for query handling and time management, enhancing the application's functionality. - Included README.md for project documentation and setup instructions.
23 lines
632 B
TypeScript
23 lines
632 B
TypeScript
import { GQLResponse } from 'src/proxy/types';
|
|
|
|
export function getQueryType(query: string) {
|
|
const actionMatch = query.match(/\b(query|mutation)\b/u);
|
|
const action = actionMatch ? (actionMatch[1] as 'query' | 'mutation') : null;
|
|
|
|
const entityMatch = query.match(
|
|
/\b(mutation|query)\s+\w*([A-Z][A-Za-z0-9_]+)/u,
|
|
);
|
|
const entity = entityMatch ? entityMatch[2] : null;
|
|
|
|
return { action, entity };
|
|
}
|
|
|
|
export function extractDocumentId(data: GQLResponse) {
|
|
if (!data?.data) return null;
|
|
|
|
const firstKey = Object.keys(data.data)[0];
|
|
if (!firstKey) return null;
|
|
|
|
return data.data[firstKey]?.documentId || null;
|
|
}
|