From 5c755a94ca4363cb3dea60512acaaf653fdcd863 Mon Sep 17 00:00:00 2001 From: Ankit Varshney Date: Fri, 19 Jan 2024 18:25:47 +0530 Subject: [PATCH] 'fix --- schema.graphql | 3 +-- src/resolvers/User/post.ts | 16 +++++++++++++++- src/typeDefs/queries.ts | 1 - src/typeDefs/types.ts | 2 +- src/types/generatedGraphQLTypes.ts | 11 ++--------- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/schema.graphql b/schema.graphql index 16653a5ec5..2e825e4e84 100644 --- a/schema.graphql +++ b/schema.graphql @@ -826,7 +826,6 @@ type Query { organizationsMemberConnection(first: Int, orderBy: UserOrderByInput, orgId: ID!, skip: Int, where: UserWhereInput): UserConnection! plugin(orgId: ID!): [Plugin] post(id: ID!): Post - postByUser(userId: ID!): [Post] postsByOrganization(id: ID!, orderBy: PostOrderByInput): [Post] postsByOrganizationConnection(first: Int, id: ID!, orderBy: PostOrderByInput, skip: Int, where: PostWhereInput): PostConnection registeredEventsByUser(id: ID, orderBy: EventOrderByInput): [Event] @@ -984,7 +983,7 @@ type User { organizationsBlockedBy: [Organization] phone: UserPhone pluginCreationAllowed: Boolean! - post: Post + post: [Post] registeredEvents: [Event] tagsAssignedWith(after: String, before: String, first: PositiveInt, last: PositiveInt, organizationId: ID): UserTagsConnection tokenVersion: Int! diff --git a/src/resolvers/User/post.ts b/src/resolvers/User/post.ts index 6bb2aed1b4..0f75a32c0c 100644 --- a/src/resolvers/User/post.ts +++ b/src/resolvers/User/post.ts @@ -1 +1,15 @@ -export const post \ No newline at end of file +import { Post } from "../../models"; +import type { UserResolvers } from "../../types/generatedGraphQLTypes"; +/** + * This resolver function will fetch and return the post created by the user from database. + * @param parent - An object that is the return value of the resolver for this field's parent. + * @returns An array which conatins the post created by the user. + */ + +export const post: UserResolvers["post"] = async (parent) => { + const post = await Post.find({ + createrId: parent._id, + }).lean(); + + return post; +}; diff --git a/src/typeDefs/queries.ts b/src/typeDefs/queries.ts index d2a6e5ba49..f890e73e22 100644 --- a/src/typeDefs/queries.ts +++ b/src/typeDefs/queries.ts @@ -75,7 +75,6 @@ export const queries = gql` post(id: ID!): Post postsByOrganization(id: ID!, orderBy: PostOrderByInput): [Post] - postByUser(userId: ID!): [Post] postsByOrganizationConnection( id: ID! diff --git a/src/typeDefs/types.ts b/src/typeDefs/types.ts index cae0db5be0..0622c9cce8 100644 --- a/src/typeDefs/types.ts +++ b/src/typeDefs/types.ts @@ -375,7 +375,7 @@ export const types = gql` educationGrade: EducationGrade email: EmailAddress! employmentStatus: EmploymentStatus - post: Post + post: [Post] eventAdmin: [Event] firstName: String! gender: Gender diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index 81d5fa1767..496921f517 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -1345,7 +1345,6 @@ export type Query = { organizationsMemberConnection: UserConnection; plugin?: Maybe>>; post?: Maybe; - postByUser?: Maybe>>; postsByOrganization?: Maybe>>; postsByOrganizationConnection?: Maybe; registeredEventsByUser?: Maybe>>; @@ -1473,11 +1472,6 @@ export type QueryPostArgs = { }; -export type QueryPostByUserArgs = { - userId: Scalars['ID']['input']; -}; - - export type QueryPostsByOrganizationArgs = { id: Scalars['ID']['input']; orderBy?: InputMaybe; @@ -1675,7 +1669,7 @@ export type User = { organizationsBlockedBy?: Maybe>>; phone?: Maybe; pluginCreationAllowed: Scalars['Boolean']['output']; - post?: Maybe; + post?: Maybe>>; registeredEvents?: Maybe>>; tagsAssignedWith?: Maybe; tokenVersion: Scalars['Int']['output']; @@ -2794,7 +2788,6 @@ export type QueryResolvers>; plugin?: Resolver>>, ParentType, ContextType, RequireFields>; post?: Resolver, ParentType, ContextType, RequireFields>; - postByUser?: Resolver>>, ParentType, ContextType, RequireFields>; postsByOrganization?: Resolver>>, ParentType, ContextType, RequireFields>; postsByOrganizationConnection?: Resolver, ParentType, ContextType, RequireFields>; registeredEventsByUser?: Resolver>>, ParentType, ContextType, Partial>; @@ -2871,7 +2864,7 @@ export type UserResolvers>>, ParentType, ContextType>; phone?: Resolver, ParentType, ContextType>; pluginCreationAllowed?: Resolver; - post?: Resolver, ParentType, ContextType>; + post?: Resolver>>, ParentType, ContextType>; registeredEvents?: Resolver>>, ParentType, ContextType>; tagsAssignedWith?: Resolver, ParentType, ContextType, Partial>; tokenVersion?: Resolver;