apps/api: do not cache graphql responses with errors
This commit is contained in:
parent
f695835c61
commit
2fea400060
@ -1,5 +1,5 @@
|
||||
import { queryTTL } from './lib/config';
|
||||
import type { GQLRequest } from './types';
|
||||
import type { GQLRequest, GQLResponse } from './types';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import {
|
||||
All,
|
||||
@ -42,13 +42,14 @@ export class ProxyController {
|
||||
method: req.method,
|
||||
});
|
||||
|
||||
if (!response.ok)
|
||||
const data = (await response.json()) as GQLResponse;
|
||||
|
||||
if (!response.ok || data?.error || data?.errors?.length)
|
||||
throw new HttpException(
|
||||
response.statusText,
|
||||
response.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
const ttl = queryTTL[operationName];
|
||||
if (data && ttl !== false)
|
||||
await this.cacheManager.set(key, data, { ttl: ttl || env.CACHE_TTL });
|
||||
|
||||
@ -3,3 +3,9 @@ export type GQLRequest = {
|
||||
query: string;
|
||||
variables: string;
|
||||
};
|
||||
|
||||
export type GQLResponse = {
|
||||
data: unknown;
|
||||
error?: unknown;
|
||||
errors?: unknown[];
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user