Skip to content

Commit

Permalink
Merge branch 'fix-feed-id-opts' of github.com:dailydotdev/daily-api i…
Browse files Browse the repository at this point in the history
…nto fix-feed-id-opts
  • Loading branch information
capJavert committed May 29, 2024
2 parents 98b98e7 + 92e976c commit 6a74441
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
21 changes: 21 additions & 0 deletions __tests__/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ beforeEach(async () => {

afterAll(() => disposeGraphQLTesting(state));

describe('query tags', () => {
const QUERY = `{
tags {
value
}
}`;

it('should return all tags', async () => {
const res = await client.query(QUERY);
expect(res.data).toMatchObject({
tags: [
{ value: 'webdev' },
{ value: 'development' },
{ value: 'fullstack' },
{ value: 'rust' },
{ value: 'golang' },
],
});
});
});

describe('query popularTags', () => {
const QUERY = `{
popularTags {
Expand Down
7 changes: 6 additions & 1 deletion src/schema/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { parseResolveInfo, ResolveTree } from 'graphql-parse-resolve-info';
import { GQLEmptyResponse } from './common';
import { MoreThanOrEqual } from 'typeorm';

interface GQLKeyword {
export interface GQLKeyword {
value: string;
status: KeywordStatus;
occurrences: number;
flags?: KeywordFlagsPublic;
createdAt?: Date;
}

interface GQLKeywordSearchResults {
Expand Down Expand Up @@ -66,6 +67,10 @@ export const typeDefs = /* GraphQL */ `
The keyword's flags
"""
flags: KeywordFlagsPublic
"""
Date when the keyword was created
"""
createdAt: DateTime
}
"""
Expand Down
17 changes: 17 additions & 0 deletions src/schema/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { TagRecommendation } from '../entity/TagRecommendation';
import { In, Not } from 'typeorm';
import { ValidationError } from 'apollo-server-errors';
import { SubmissionFailErrorMessage } from '../errors';
import graphorm from '../graphorm';
import { GQLKeyword } from './keywords';

interface GQLTag {
name: string;
Expand Down Expand Up @@ -57,6 +59,11 @@ export const typeDefs = /* GraphQL */ `
}
extend type Query {
"""
Get all tags
"""
tags: [Keyword]
"""
Get the most popular tags
"""
Expand Down Expand Up @@ -89,6 +96,16 @@ export const typeDefs = /* GraphQL */ `
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const resolvers: IResolvers<any, Context> = traceResolvers({
Query: {
tags: (_, __, ctx, info): Promise<GQLKeyword[]> =>
graphorm.query<GQLKeyword>(ctx, info, (builder) => {
builder.queryBuilder = builder.queryBuilder
.where({
status: 'allow',
})
.limit(1000);

return builder;
}),
popularTags: async (source, args, ctx): Promise<GQLTag[]> => {
const hits = await ctx.getRepository(Keyword).find({
select: ['value'],
Expand Down

0 comments on commit 6a74441

Please sign in to comment.