diff --git a/__tests__/tags.ts b/__tests__/tags.ts index 8ebb48a18..4ddb64a3c 100644 --- a/__tests__/tags.ts +++ b/__tests__/tags.ts @@ -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 { diff --git a/src/schema/keywords.ts b/src/schema/keywords.ts index c7de27c2f..c3cd62e55 100644 --- a/src/schema/keywords.ts +++ b/src/schema/keywords.ts @@ -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 { @@ -66,6 +67,10 @@ export const typeDefs = /* GraphQL */ ` The keyword's flags """ flags: KeywordFlagsPublic + """ + Date when the keyword was created + """ + createdAt: DateTime } """ diff --git a/src/schema/tags.ts b/src/schema/tags.ts index 5f684d7d4..160b8a472 100644 --- a/src/schema/tags.ts +++ b/src/schema/tags.ts @@ -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; @@ -57,6 +59,11 @@ export const typeDefs = /* GraphQL */ ` } extend type Query { + """ + Get all tags + """ + tags: [Keyword] + """ Get the most popular tags """ @@ -89,6 +96,16 @@ export const typeDefs = /* GraphQL */ ` // eslint-disable-next-line @typescript-eslint/no-explicit-any export const resolvers: IResolvers = traceResolvers({ Query: { + tags: (_, __, ctx, info): Promise => + graphorm.query(ctx, info, (builder) => { + builder.queryBuilder = builder.queryBuilder + .where({ + status: 'allow', + }) + .limit(1000); + + return builder; + }), popularTags: async (source, args, ctx): Promise => { const hits = await ctx.getRepository(Keyword).find({ select: ['value'],