From faa41039feea7891840767ed99733af95d00ed1f Mon Sep 17 00:00:00 2001 From: Patryk Andrzejewski Date: Thu, 20 Oct 2022 13:55:55 +0200 Subject: [PATCH] Add policy for use name instead of slug (#2402) --- src/graphql/client.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/graphql/client.ts b/src/graphql/client.ts index 72c3e4769..1b474d65e 100644 --- a/src/graphql/client.ts +++ b/src/graphql/client.ts @@ -46,6 +46,25 @@ export const apolloClient = new ApolloClient({ Shop: { keyFields: [], }, + AttributeValue: { + fields: { + /** + * Since, API sometimes creates an empty slug, + * We need to handle that case also on front-end, + * so after fix that problem in the API, the UI will ablle + * to handle it. + * + * If the slug is empty, use the name + */ + slug: (givenSlug, { readField }) => { + if (!givenSlug) { + return readField("name"); + } + + return givenSlug; + }, + }, + }, } as TypedTypePolicies, }), link,