From 100d43cc3684834a2f795df075b2f28f92732e56 Mon Sep 17 00:00:00 2001 From: Sandeep Kumar Sharma Date: Thu, 21 Sep 2023 18:50:25 +0530 Subject: [PATCH] fix: add gql request name support --- projects/graphql-client/src/graphql-config.ts | 1 + .../graphql-client/src/graphql-request.service.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/projects/graphql-client/src/graphql-config.ts b/projects/graphql-client/src/graphql-config.ts index 0342b864a..88fd3d9a9 100644 --- a/projects/graphql-client/src/graphql-config.ts +++ b/projects/graphql-client/src/graphql-config.ts @@ -35,6 +35,7 @@ export interface GraphQlMutationHandler extends GraphQlHand export interface GraphQlRequestOptions { cacheability?: GraphQlRequestCacheability; isolated?: boolean; + name?: string; } export const enum GraphQlRequestCacheability { diff --git a/projects/graphql-client/src/graphql-request.service.ts b/projects/graphql-client/src/graphql-request.service.ts index 01a8aa23e..547c11f38 100644 --- a/projects/graphql-client/src/graphql-request.service.ts +++ b/projects/graphql-client/src/graphql-request.service.ts @@ -145,7 +145,7 @@ export class GraphQlRequestService { options: GraphQlRequestOptions ): Observable { return type === GraphQlHandlerType.Mutation - ? this.executeMutation(requestString) + ? this.executeMutation(requestString, options) : this.executeQuery(requestString, options); } @@ -155,7 +155,7 @@ export class GraphQlRequestService { ): Observable { return this.apollo .query({ - query: gql(requestString), + query: gql(`query ${options?.name ?? ''} ${requestString}`), errorPolicy: 'all', fetchPolicy: options.cacheability }) @@ -169,10 +169,13 @@ export class GraphQlRequestService { ); } - private executeMutation>(requestString: string): Observable { + private executeMutation>( + requestString: string, + options: GraphQlRequestOptions + ): Observable { return this.apollo .mutate({ - mutation: gql(`mutation ${requestString}`) + mutation: gql(`mutation ${options?.name ?? ''} ${requestString}`) }) .pipe( tap(response => {