Skip to content

Commit

Permalink
Chore : Shifting from String to EmailAddress in Graphql Schema (#2986)
Browse files Browse the repository at this point in the history
* Chore : Shifting from String to EmailAddress in Graphql Schema

* Forgot to include a file

* CodeRabbit suggestions

* coderabbit.ai improvements

* coderabbit.ai improvements:2
  • Loading branch information
Nikhilh26 authored Feb 4, 2025
1 parent ee24a95 commit ff6784b
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 20 deletions.
17 changes: 11 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `dat
"""
scalar DateTime

"""
A field whose value conforms to the standard internet email address format as specified in HTML Spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address.
"""
scalar EmailAddress

type Event {
"""
GraphQL connection to traverse through the agenda folders that contain agenda items constituting a part of the agenda for the event.
Expand Down Expand Up @@ -1747,7 +1752,7 @@ input MutationCreateUserInput {
educationGrade: UserEducationGrade

"""Email address of the user."""
emailAddress: String!
emailAddress: EmailAddress!

"""Employment status of the user."""
employmentStatus: UserEmploymentStatus
Expand Down Expand Up @@ -1982,7 +1987,7 @@ input MutationSignUpInput {
educationGrade: UserEducationGrade

"""Email address of the user."""
emailAddress: String!
emailAddress: EmailAddress!

"""Employment status of the user."""
employmentStatus: UserEmploymentStatus
Expand Down Expand Up @@ -2202,7 +2207,7 @@ input MutationUpdateCurrentUserInput {
educationGrade: UserEducationGrade

"""Email address of the user."""
emailAddress: String
emailAddress: EmailAddress

"""Employment status of the user."""
employmentStatus: UserEmploymentStatus
Expand Down Expand Up @@ -2419,7 +2424,7 @@ input MutationUpdateUserInput {
educationGrade: UserEducationGrade

"""Email address of the user."""
emailAddress: String
emailAddress: EmailAddress

"""Employment status of the user."""
employmentStatus: UserEmploymentStatus
Expand Down Expand Up @@ -2965,7 +2970,7 @@ input QueryPostInput {
""""""
input QuerySignInInput {
"""Email address of the user."""
emailAddress: String!
emailAddress: EmailAddress!

"""Password of the user to sign in to talawa."""
password: String!
Expand Down Expand Up @@ -3149,7 +3154,7 @@ type User {
educationGrade: UserEducationGrade

"""Email address of the user."""
emailAddress: String
emailAddress: EmailAddress

"""Employment status of the user."""
employmentStatus: UserEmploymentStatus
Expand Down
3 changes: 2 additions & 1 deletion src/graphql/inputs/MutationCreateUserInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export const MutationCreateUserInput = builder
description: "Primary education grade of the user.",
type: UserEducationGrade,
}),
emailAddress: t.string({
emailAddress: t.field({
description: "Email address of the user.",
required: true,
type: "EmailAddress",
}),
employmentStatus: t.field({
description: "Employment status of the user.",
Expand Down
3 changes: 2 additions & 1 deletion src/graphql/inputs/MutationSignUpInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ export const MutationSignUpInput = builder
description: "Primary education grade of the user.",
type: UserEducationGrade,
}),
emailAddress: t.string({
emailAddress: t.field({
description: "Email address of the user.",
required: true,
type: "EmailAddress",
}),
employmentStatus: t.field({
description: "Employment status of the user.",
Expand Down
3 changes: 2 additions & 1 deletion src/graphql/inputs/MutationUpdateCurrentUserInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ export const MutationUpdateCurrentUserInput = builder
description: "Primary education grade of the user.",
type: UserEducationGrade,
}),
emailAddress: t.string({
emailAddress: t.field({
description: "Email address of the user.",
type: "EmailAddress",
}),
employmentStatus: t.field({
description: "Employment status of the user.",
Expand Down
3 changes: 2 additions & 1 deletion src/graphql/inputs/MutationUpdateUserInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export const MutationUpdateUserInput = builder
description: "Primary education grade of the user.",
type: UserEducationGrade,
}),
emailAddress: t.string({
emailAddress: t.field({
description: "Email address of the user.",
type: "EmailAddress",
}),
employmentStatus: t.field({
description: "Employment status of the user.",
Expand Down
3 changes: 2 additions & 1 deletion src/graphql/inputs/QuerySignInInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export const QuerySignInInput = builder
.implement({
description: "",
fields: (t) => ({
emailAddress: t.string({
emailAddress: t.field({
description: "Email address of the user.",
required: true,
type: "EmailAddress",
}),
password: t.string({
description: "Password of the user to sign in to talawa.",
Expand Down
24 changes: 24 additions & 0 deletions src/graphql/scalars/EmailAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { EmailAddressResolver } from "graphql-scalars";
import { builder } from "~/src/graphql/builder";

/**
* A custom scalar type for validating email addresses according to RFC 5322.
* This ensures that all email fields in the schema are properly validated.
* More information at this link: {@link https://the-guild.dev/graphql/scalars/docs/scalars/email-address}
*/
export const EmailAddress = builder.addScalarType(
"EmailAddress",
EmailAddressResolver,
);

/**
* `EmailAddress` scalar type for pothos schema.
* The underscore prefix indicates this is an internal type definition.
* @example
* Valid: user@example.com
* Invalid: user@, user@.com, @example.com
*/
export type _EmailAddress = {
Input: string;
Output: string;
};
4 changes: 4 additions & 0 deletions src/graphql/scalars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import "./Date";
import "./DateTime";
import "./PhoneNumber";
import "./Upload";
import "./EmailAddress";

import type { _BigInt } from "./BigInt";
import type { _Date } from "./Date";
import type { DateTime } from "./DateTime";
import type { _EmailAddress } from "./EmailAddress";
import type { PhoneNumber } from "./PhoneNumber";
import type { Upload } from "./Upload";

Expand All @@ -19,6 +21,7 @@ export type CustomScalars = {
DateTime: DateTime;
PhoneNumber: PhoneNumber;
Upload: Upload;
EmailAddress: _EmailAddress;
};

/**
Expand All @@ -29,4 +32,5 @@ export type ClientCustomScalars = {
Date: string;
DateTime: string;
PhoneNumber: string;
EmailAddress: string;
};
3 changes: 2 additions & 1 deletion src/graphql/types/User/emailAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { User } from "./User";

User.implement({
fields: (t) => ({
emailAddress: t.string({
emailAddress: t.field({
description: "Email address of the user.",
resolve: async (parent, _args, ctx) => {
if (!ctx.currentClient.isAuthenticated) {
Expand Down Expand Up @@ -44,6 +44,7 @@ User.implement({

return parent.emailAddress;
},
type: "EmailAddress",
}),
}),
});
2 changes: 1 addition & 1 deletion src/routes/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const graphql = fastifyPlugin(async (fastify) => {
fastify,
isSubscription: true,
request,
socket,
socket: socket as unknown as WebSocket,
}),
// Intervals in milli-seconds to wait before sending the `GQL_CONNECTION_KEEP_ALIVE` message to the client to check if the connection is alive. This helps detect disconnected subscription clients and prevent unnecessary data transfer.
keepAlive: 1000 * 30,
Expand Down
Loading

0 comments on commit ff6784b

Please sign in to comment.