Skip to content

Commit

Permalink
Add GraphQL-Scalars [Fixes part of #1082] (#1085)
Browse files Browse the repository at this point in the history
* Change scalars

* Revert Upload Scalar

* Move scalar Upload to congen config

* Move from Timestamp to DateTime

* Move mongo to datetime

* Revert "Move mongo to datetime"

This reverts commit e58516f.

* Move ID to ObjectID

* Revert ObjectID
  • Loading branch information
EshaanAgg authored Feb 26, 2023
1 parent c0409d9 commit 83f22af
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 153 deletions.
3 changes: 2 additions & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
schema: ["./src/typeDefs/**/*.ts"],
// Points to our schema and the additional scalar Upload which is added by Apollo-Server at runtime
schema: ["./src/typeDefs/**/*.ts", "scalar Upload"],

generates: {
"./src/types/generatedGraphQLTypes.ts": {
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"firebase-admin": "^10.3.0",
"graphql": "^15.8.0",
"graphql-depth-limit": "^1.1.0",
"graphql-scalars": "^1.20.1",
"graphql-upload": "^12.0.0",
"helmet": "^4.6.0",
"i18n": "^0.13.4",
Expand Down
20 changes: 20 additions & 0 deletions src/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import { Mutation } from "./Mutation";
import { Organization } from "./Organization";
import { Query } from "./Query";
import { Subscription } from "./Subscription";
import {
DateResolver,
DateTimeResolver,
EmailAddressResolver,
LatitudeResolver,
LongitudeResolver,
PhoneNumberResolver,
TimeResolver,
URLResolver,
} from "graphql-scalars";

export const resolvers: Resolvers = {
DirectChat,
Expand All @@ -19,4 +29,14 @@ export const resolvers: Resolvers = {
Organization,
Query,
Subscription,

// graphql-scalar resolver
Date: DateResolver,
DateTime: DateTimeResolver,
EmailAddress: EmailAddressResolver,
Latitude: LatitudeResolver,
Longitude: LongitudeResolver,
PhoneNumber: PhoneNumberResolver,
Time: TimeResolver,
URL: URLResolver,
};
70 changes: 35 additions & 35 deletions src/typeDefs/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ export const inputs = gql`
input EventInput {
title: String!
description: String!
startDate: String!
endDate: String
startTime: String
endTime: String
startDate: Date!
endDate: Date
startTime: Time
endTime: Time
allDay: Boolean!
recurring: Boolean!
recurrance: Recurrance
isPublic: Boolean!
isRegisterable: Boolean!
location: String
latitude: Float
longitude: Float
latitude: Latitude
longitude: Longitude
organizationId: ID!
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export const inputs = gql`
}
input LoginInput {
email: String!
email: EmailAddress!
password: String!
}
Expand All @@ -124,7 +124,7 @@ export const inputs = gql`
attendees: String
isPublic: Boolean!
visibleInSearch: Boolean!
apiUrl: String
apiUrl: URL
image: String
tags: [String!]!
}
Expand All @@ -151,20 +151,20 @@ export const inputs = gql`
description_contains: String
description_starts_with: String
apiUrl: String
apiUrl_not: String
apiUrl_in: [String!]
apiUrl_not_in: [String!]
apiUrl_contains: String
apiUrl_starts_with: String
apiUrl: URL
apiUrl_not: URL
apiUrl_in: [URL!]
apiUrl_not_in: [URL!]
apiUrl_contains: URL
apiUrl_starts_with: URL
visibleInSearch: Boolean
isPublic: Boolean
}
input OTPInput {
email: String!
email: EmailAddress!
}
input PluginFieldInput {
Expand All @@ -184,8 +184,8 @@ export const inputs = gql`
_id: ID
text: String!
title: String
imageUrl: String
videoUrl: String
imageUrl: URL
videoUrl: URL
organizationId: ID!
}
Expand Down Expand Up @@ -219,7 +219,7 @@ export const inputs = gql`
input TaskInput {
title: String!
description: String
deadline: String
deadline: DateTime
}
input UpdateEventInput {
Expand All @@ -229,14 +229,14 @@ export const inputs = gql`
recurrance: Recurrance
isPublic: Boolean
isRegisterable: Boolean
startDate: String
endDate: String
startDate: Date
endDate: Date
location: String
latitude: Float
longitude: Float
latitude: Latitude
longitude: Longitude
allDay: Boolean
startTime: String
endTime: String
startTime: Time
endTime: Time
}
# input UpdateEventProjectInput {
Expand All @@ -254,13 +254,13 @@ export const inputs = gql`
input UpdateTaskInput {
title: String
description: String
deadline: String
deadline: DateTime
}
input UpdateUserInput {
firstName: String
lastName: String
email: String
email: EmailAddress
}
input UpdateUserTypeInput {
Expand All @@ -276,7 +276,7 @@ export const inputs = gql`
input UserInput {
firstName: String!
lastName: String!
email: String!
email: EmailAddress!
password: String!
appLanguageCode: String
organizationUserBelongsToId: ID
Expand Down Expand Up @@ -304,12 +304,12 @@ export const inputs = gql`
lastName_contains: String
lastName_starts_with: String
email: String
email_not: String
email_in: [String!]
email_not_in: [String!]
email_contains: String
email_starts_with: String
email: EmailAddress
email_not: EmailAddress
email_in: [EmailAddress!]
email_not_in: [EmailAddress!]
email_contains: EmailAddress
email_starts_with: EmailAddress
appLanguageCode: String
appLanguageCode_not: String
Expand All @@ -325,7 +325,7 @@ export const inputs = gql`
input PostUpdateInput {
text: String
title: String
imageUrl: String
videoUrl: String
imageUrl: URL
videoUrl: URL
}
`;
10 changes: 9 additions & 1 deletion src/typeDefs/scalars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@ import { gql } from "apollo-server-core";

// Place fields alphabetically to ensure easier lookup and navigation.
export const scalars = gql`
scalar Upload
scalar Date
scalar DateTime
scalar EmailAddress
scalar Latitude
scalar Longitude
scalar ID
scalar PhoneNumber
scalar Time
scalar URL
`;
Loading

0 comments on commit 83f22af

Please sign in to comment.