Skip to content

Commit c60faab

Browse files
committed
chore: add operation name
1 parent 623f4d4 commit c60faab

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/index.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export class Authorizer {
201201
variables: {
202202
data,
203203
},
204+
operationName: 'forgotPassword',
204205
});
205206
return forgotPasswordResp?.errors?.length
206207
? this.errorResponse(forgotPasswordResp.errors)
@@ -214,7 +215,8 @@ export class Authorizer {
214215
try {
215216
const res = await this.graphqlQuery({
216217
query:
217-
'query { meta { version client_id is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_linkedin_login_enabled is_apple_login_enabled is_twitter_login_enabled is_microsoft_login_enabled is_twitch_login_enabled is_roblox_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled is_multi_factor_auth_enabled is_mobile_basic_authentication_enabled is_phone_verification_enabled } }',
218+
'query meta { meta { version client_id is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_linkedin_login_enabled is_apple_login_enabled is_twitter_login_enabled is_microsoft_login_enabled is_twitch_login_enabled is_roblox_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled is_multi_factor_auth_enabled is_mobile_basic_authentication_enabled is_phone_verification_enabled } }',
219+
operationName: 'meta',
218220
});
219221

220222
return res?.errors?.length
@@ -230,8 +232,9 @@ export class Authorizer {
230232
): Promise<Types.ApiResponse<Types.User>> => {
231233
try {
232234
const profileRes = await this.graphqlQuery({
233-
query: `query { profile { ${userFragment} } }`,
235+
query: `query profile { profile { ${userFragment} } }`,
234236
headers,
237+
operationName: 'profile',
235238
});
236239

237240
return profileRes?.errors?.length
@@ -254,6 +257,7 @@ export class Authorizer {
254257
variables: {
255258
params,
256259
},
260+
operationName: 'getSession',
257261
});
258262
return res?.errors?.length
259263
? this.errorResponse(res.errors)
@@ -336,6 +340,7 @@ export class Authorizer {
336340
mutation login($data: LoginRequest!) { login(params: $data) { ${authTokenFragment}}}
337341
`,
338342
variables: { data },
343+
operationName: 'login',
339344
});
340345

341346
return res?.errors?.length
@@ -351,8 +356,9 @@ export class Authorizer {
351356
): Promise<Types.ApiResponse<Types.GenericResponse>> => {
352357
try {
353358
const res = await this.graphqlQuery({
354-
query: ' mutation { logout { message } } ',
359+
query: 'mutation logout { logout { message } }',
355360
headers,
361+
operationName: 'logout',
356362
});
357363
return res?.errors?.length
358364
? this.errorResponse(res.errors)
@@ -375,6 +381,7 @@ export class Authorizer {
375381
mutation magicLinkLogin($data: MagicLinkLoginRequest!) { magic_link_login(params: $data) { message }}
376382
`,
377383
variables: { data },
384+
operationName: 'magicLinkLogin',
378385
});
379386

380387
return res?.errors?.length
@@ -423,6 +430,7 @@ export class Authorizer {
423430
mutation resendOtp($data: ResendOTPRequest!) { resend_otp(params: $data) { message }}
424431
`,
425432
variables: { data },
433+
operationName: 'resendOtp',
426434
});
427435

428436
return res?.errors?.length
@@ -443,6 +451,7 @@ export class Authorizer {
443451
variables: {
444452
data,
445453
},
454+
operationName: 'resetPassword',
446455
});
447456
return resetPasswordRes?.errors?.length
448457
? this.errorResponse(resetPasswordRes.errors)
@@ -516,6 +525,7 @@ export class Authorizer {
516525
mutation signup($data: SignUpRequest!) { signup(params: $data) { ${authTokenFragment}}}
517526
`,
518527
variables: { data },
528+
operationName: 'signup',
519529
});
520530

521531
return res?.errors?.length
@@ -538,6 +548,7 @@ export class Authorizer {
538548
variables: {
539549
data,
540550
},
551+
operationName: 'updateProfile',
541552
});
542553

543554
return updateProfileRes?.errors?.length
@@ -555,6 +566,7 @@ export class Authorizer {
555566
const res = await this.graphqlQuery({
556567
query: 'mutation deactivateAccount { deactivate_account { message } }',
557568
headers,
569+
operationName: 'deactivateAccount',
558570
});
559571
return res?.errors?.length
560572
? this.errorResponse(res.errors)
@@ -574,6 +586,7 @@ export class Authorizer {
574586
variables: {
575587
params,
576588
},
589+
operationName: 'validateJWTToken',
577590
});
578591

579592
return res?.errors?.length
@@ -593,6 +606,7 @@ export class Authorizer {
593606
variables: {
594607
params,
595608
},
609+
operationName: 'validateSession',
596610
});
597611

598612
return res?.errors?.length
@@ -612,6 +626,7 @@ export class Authorizer {
612626
mutation verifyEmail($data: VerifyEmailRequest!) { verify_email(params: $data) { ${authTokenFragment}}}
613627
`,
614628
variables: { data },
629+
operationName: 'verifyEmail',
615630
});
616631

617632
return res?.errors?.length
@@ -631,6 +646,7 @@ export class Authorizer {
631646
mutation resendVerifyEmail($data: ResendVerifyEmailRequest!) { resend_verify_email(params: $data) { message }}
632647
`,
633648
variables: { data },
649+
operationName: 'resendVerifyEmail',
634650
});
635651

636652
return res?.errors?.length
@@ -650,6 +666,7 @@ export class Authorizer {
650666
mutation verifyOtp($data: VerifyOTPRequest!) { verify_otp(params: $data) { ${authTokenFragment}}}
651667
`,
652668
variables: { data },
669+
operationName: 'verifyOtp',
653670
});
654671

655672
return res?.errors?.length
@@ -666,12 +683,16 @@ export class Authorizer {
666683
data: Types.GraphqlQueryRequest,
667684
): Promise<Types.GrapQlResponseType> => {
668685
const fetcher = getFetcher();
686+
const body: Record<string, unknown> = {
687+
query: data.query,
688+
variables: data.variables || {},
689+
};
690+
if (data.operationName) {
691+
body.operationName = data.operationName;
692+
}
669693
const res = await fetcher(`${this.config.authorizerURL}/graphql`, {
670694
method: 'POST',
671-
body: JSON.stringify({
672-
query: data.query,
673-
variables: data.variables || {},
674-
}),
695+
body: JSON.stringify(body),
675696
headers: {
676697
...this.config.extraHeaders,
677698
...(data.headers || {}),

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ export interface GraphqlQueryRequest {
387387
query: string;
388388
variables?: Record<string, any>;
389389
headers?: Headers;
390+
/** When set, sent as the GraphQL `operationName` field (helps servers identify the operation for logging and metrics). */
391+
operationName?: string;
390392
}
391393

392394
// Deprecated types (for backward compatibility)

0 commit comments

Comments
 (0)