mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
return author name only
This commit is contained in:
parent
fa3e6fe341
commit
5d07e554e2
6 changed files with 36 additions and 17 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
JoinColumn,
|
JoinColumn,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
} from 'typeorm'
|
} from 'typeorm'
|
||||||
import { User } from './user'
|
import { User } from './user'
|
||||||
|
|
||||||
|
|
@ -37,9 +39,9 @@ export class Post {
|
||||||
@Column('text', { nullable: true })
|
@Column('text', { nullable: true })
|
||||||
thought?: string | null
|
thought?: string | null
|
||||||
|
|
||||||
@Column('timestamptz')
|
@CreateDateColumn({ type: 'timestamptz' })
|
||||||
createdAt!: Date
|
createdAt!: Date
|
||||||
|
|
||||||
@Column('timestamptz')
|
@UpdateDateColumn({ type: 'timestamptz' })
|
||||||
updatedAt!: Date
|
updatedAt!: Date
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -515,6 +515,7 @@ export type CreatePostError = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum CreatePostErrorCode {
|
export enum CreatePostErrorCode {
|
||||||
|
BadRequest = 'BAD_REQUEST',
|
||||||
Unauthorized = 'UNAUTHORIZED'
|
Unauthorized = 'UNAUTHORIZED'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2408,12 +2409,12 @@ export type ParseResult = {
|
||||||
|
|
||||||
export type Post = {
|
export type Post = {
|
||||||
__typename?: 'Post';
|
__typename?: 'Post';
|
||||||
author: User;
|
author: Scalars['String'];
|
||||||
content: Scalars['String'];
|
content: Scalars['String'];
|
||||||
createdAt: Scalars['Date'];
|
createdAt: Scalars['Date'];
|
||||||
highlights?: Maybe<Array<Highlight>>;
|
highlights?: Maybe<Array<Highlight>>;
|
||||||
id: Scalars['ID'];
|
id: Scalars['ID'];
|
||||||
libraryItems: Array<Article>;
|
libraryItems?: Maybe<Array<Article>>;
|
||||||
ownedByViewer: Scalars['Boolean'];
|
ownedByViewer: Scalars['Boolean'];
|
||||||
thought?: Maybe<Scalars['String']>;
|
thought?: Maybe<Scalars['String']>;
|
||||||
thumbnail?: Maybe<Scalars['String']>;
|
thumbnail?: Maybe<Scalars['String']>;
|
||||||
|
|
@ -7059,12 +7060,12 @@ export type PageInfoResolvers<ContextType = ResolverContext, ParentType extends
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PostResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['Post'] = ResolversParentTypes['Post']> = {
|
export type PostResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['Post'] = ResolversParentTypes['Post']> = {
|
||||||
author?: Resolver<ResolversTypes['User'], ParentType, ContextType>;
|
author?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||||
content?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
content?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||||
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
|
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
|
||||||
highlights?: Resolver<Maybe<Array<ResolversTypes['Highlight']>>, ParentType, ContextType>;
|
highlights?: Resolver<Maybe<Array<ResolversTypes['Highlight']>>, ParentType, ContextType>;
|
||||||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||||
libraryItems?: Resolver<Array<ResolversTypes['Article']>, ParentType, ContextType>;
|
libraryItems?: Resolver<Maybe<Array<ResolversTypes['Article']>>, ParentType, ContextType>;
|
||||||
ownedByViewer?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
|
ownedByViewer?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
|
||||||
thought?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
thought?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||||
thumbnail?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
thumbnail?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||||
|
|
|
||||||
|
|
@ -460,6 +460,7 @@ type CreatePostError {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CreatePostErrorCode {
|
enum CreatePostErrorCode {
|
||||||
|
BAD_REQUEST
|
||||||
UNAUTHORIZED
|
UNAUTHORIZED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1842,12 +1843,12 @@ input ParseResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Post {
|
type Post {
|
||||||
author: User!
|
author: String!
|
||||||
content: String!
|
content: String!
|
||||||
createdAt: Date!
|
createdAt: Date!
|
||||||
highlights: [Highlight!]
|
highlights: [Highlight!]
|
||||||
id: ID!
|
id: ID!
|
||||||
libraryItems: [Article!]!
|
libraryItems: [Article!]
|
||||||
ownedByViewer: Boolean!
|
ownedByViewer: Boolean!
|
||||||
thought: String
|
thought: String
|
||||||
thumbnail: String
|
thumbnail: String
|
||||||
|
|
|
||||||
|
|
@ -791,26 +791,32 @@ export const functionResolvers = {
|
||||||
recommendedAt: (recommendation: Recommendation) => recommendation.createdAt,
|
recommendedAt: (recommendation: Recommendation) => recommendation.createdAt,
|
||||||
},
|
},
|
||||||
Post: {
|
Post: {
|
||||||
author(post: Post, _: never, ctx: ResolverContext) {
|
async author(post: Post, _: never, ctx: ResolverContext) {
|
||||||
return ctx.dataLoaders.users.load(post.userId)
|
const author = await ctx.dataLoaders.users.load(post.userId)
|
||||||
|
return author?.name
|
||||||
},
|
},
|
||||||
ownedByViewer(post: Post, _: never, ctx: ResolverContext) {
|
ownedByViewer(post: Post, _: never, ctx: ResolverContext) {
|
||||||
console.log('ownedByViewer: ctx.claims?.uid', ctx.claims?.uid)
|
|
||||||
return post.userId === ctx.claims?.uid
|
return post.userId === ctx.claims?.uid
|
||||||
},
|
},
|
||||||
libraryItems(
|
async libraryItems(
|
||||||
post: { libraryItemIds: string[] },
|
post: { libraryItemIds: string[] },
|
||||||
_: never,
|
_: never,
|
||||||
ctx: ResolverContext
|
ctx: ResolverContext
|
||||||
) {
|
) {
|
||||||
return ctx.dataLoaders.libraryItems.loadMany(post.libraryItemIds)
|
const items = await ctx.dataLoaders.libraryItems.loadMany(
|
||||||
|
post.libraryItemIds
|
||||||
|
)
|
||||||
|
return items.filter((item) => !!item)
|
||||||
},
|
},
|
||||||
highlights(
|
async highlights(
|
||||||
post: { highlightIds: string[] },
|
post: { highlightIds: string[] },
|
||||||
_: never,
|
_: never,
|
||||||
ctx: ResolverContext
|
ctx: ResolverContext
|
||||||
) {
|
) {
|
||||||
return ctx.dataLoaders.highlights.loadMany(post.highlightIds)
|
const highlights = await ctx.dataLoaders.highlights.loadMany(
|
||||||
|
post.highlightIds
|
||||||
|
)
|
||||||
|
return highlights.filter((highlight) => !!highlight)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
...resultResolveTypeResolver('Login'),
|
...resultResolveTypeResolver('Login'),
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,14 @@ export const createPostResolver = authorized<
|
||||||
const { title, content, highlightIds, libraryItemIds, thought, thumbnail } =
|
const { title, content, highlightIds, libraryItemIds, thought, thumbnail } =
|
||||||
input
|
input
|
||||||
|
|
||||||
|
if (libraryItemIds.length === 0) {
|
||||||
|
log.error('Invalid args', { libraryItemIds })
|
||||||
|
|
||||||
|
return {
|
||||||
|
errorCodes: [CreatePostErrorCode.BadRequest],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const postToCreate = {
|
const postToCreate = {
|
||||||
userId: uid,
|
userId: uid,
|
||||||
title,
|
title,
|
||||||
|
|
|
||||||
|
|
@ -3343,11 +3343,11 @@ const schema = gql`
|
||||||
id: ID!
|
id: ID!
|
||||||
title: String!
|
title: String!
|
||||||
content: String!
|
content: String!
|
||||||
author: User!
|
author: String!
|
||||||
ownedByViewer: Boolean!
|
ownedByViewer: Boolean!
|
||||||
thumbnail: String
|
thumbnail: String
|
||||||
thought: String
|
thought: String
|
||||||
libraryItems: [Article!]!
|
libraryItems: [Article!]
|
||||||
highlights: [Highlight!]
|
highlights: [Highlight!]
|
||||||
createdAt: Date!
|
createdAt: Date!
|
||||||
updatedAt: Date!
|
updatedAt: Date!
|
||||||
|
|
@ -3374,6 +3374,7 @@ const schema = gql`
|
||||||
|
|
||||||
enum CreatePostErrorCode {
|
enum CreatePostErrorCode {
|
||||||
UNAUTHORIZED
|
UNAUTHORIZED
|
||||||
|
BAD_REQUEST
|
||||||
}
|
}
|
||||||
|
|
||||||
input UpdatePostInput {
|
input UpdatePostInput {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue