From 501844108a08fd1c49708178680bd97b6aef5b08 Mon Sep 17 00:00:00 2001 From: Alexander Kaufmann Date: Wed, 31 Jan 2024 15:24:31 +0100 Subject: [PATCH] API Generator: Add missing `scope` argument and filter to `BySlug` query (#1643) --------- Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com> --- .changeset/three-eagles-cheat.md | 5 +++++ demo/api/schema.gql | 2 +- demo/api/src/news/generated/news.resolver.ts | 4 ++-- packages/api/cms-api/src/generator/generate-crud.ts | 7 +++++-- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/three-eagles-cheat.md diff --git a/.changeset/three-eagles-cheat.md b/.changeset/three-eagles-cheat.md new file mode 100644 index 0000000000..800ef714e8 --- /dev/null +++ b/.changeset/three-eagles-cheat.md @@ -0,0 +1,5 @@ +--- +"@comet/cms-api": patch +--- + +API Generator: Add missing `scope` argument and filter to `BySlug` query diff --git a/demo/api/schema.gql b/demo/api/schema.gql index 6709484995..7f6ea2eec7 100644 --- a/demo/api/schema.gql +++ b/demo/api/schema.gql @@ -640,7 +640,7 @@ type Query { damFolder(id: ID!): DamFolder! damFolderByNameAndParentId(scope: DamScopeInput!, name: String!, parentId: ID): DamFolder news(id: ID!): News! - newsBySlug(slug: String!): News + newsBySlug(slug: String!, scope: NewsContentScopeInput!): News newsList(offset: Int! = 0, limit: Int! = 25, scope: NewsContentScopeInput!, search: String, filter: NewsFilter, sort: [NewsSort!]): PaginatedNews! mainMenu(scope: PageTreeNodeScopeInput!): MainMenu! topMenu(scope: PageTreeNodeScopeInput!): [PageTreeNode!]! diff --git a/demo/api/src/news/generated/news.resolver.ts b/demo/api/src/news/generated/news.resolver.ts index b2bf198aab..a77cde09d4 100644 --- a/demo/api/src/news/generated/news.resolver.ts +++ b/demo/api/src/news/generated/news.resolver.ts @@ -31,8 +31,8 @@ export class NewsResolver { } @Query(() => News, { nullable: true }) - async newsBySlug(@Args("slug") slug: string): Promise { - const news = await this.repository.findOne({ slug }); + async newsBySlug(@Args("slug") slug: string, @Args("scope", { type: () => NewsContentScope }) scope: NewsContentScope): Promise { + const news = await this.repository.findOne({ slug, scope }); return news ?? null; } diff --git a/packages/api/cms-api/src/generator/generate-crud.ts b/packages/api/cms-api/src/generator/generate-crud.ts index 398ed926f2..0df4b39d95 100644 --- a/packages/api/cms-api/src/generator/generate-crud.ts +++ b/packages/api/cms-api/src/generator/generate-crud.ts @@ -746,8 +746,11 @@ function generateResolver({ generatorOptions, metadata }: { generatorOptions: Cr hasSlugProp ? ` @Query(() => ${metadata.className}, { nullable: true }) - async ${instanceNameSingular}BySlug(@Args("slug") slug: string): Promise<${metadata.className} | null> { - const ${instanceNameSingular} = await this.repository.findOne({ slug }); + async ${instanceNameSingular}BySlug( + @Args("slug") slug: string + ${scopeProp ? `, @Args("scope", { type: () => ${scopeProp.type} }) scope: ${scopeProp.type}` : ""} + ): Promise<${metadata.className} | null> { + const ${instanceNameSingular} = await this.repository.findOne({ slug${scopeProp ? `, scope` : ""}}); return ${instanceNameSingular} ?? null; }