Skip to content

Commit

Permalink
API Generator: Add missing scope argument and filter to `<entity>By…
Browse files Browse the repository at this point in the history
…Slug` query (#1643)


---------

Co-authored-by: Johannes Obermair <[email protected]>
  • Loading branch information
kaufmo and johnnyomair authored Jan 31, 2024
1 parent 0f65467 commit 5018441
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-eagles-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-api": patch
---

API Generator: Add missing `scope` argument and filter to `<entity>BySlug` query
2 changes: 1 addition & 1 deletion demo/api/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]!
Expand Down
4 changes: 2 additions & 2 deletions demo/api/src/news/generated/news.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class NewsResolver {
}

@Query(() => News, { nullable: true })
async newsBySlug(@Args("slug") slug: string): Promise<News | null> {
const news = await this.repository.findOne({ slug });
async newsBySlug(@Args("slug") slug: string, @Args("scope", { type: () => NewsContentScope }) scope: NewsContentScope): Promise<News | null> {
const news = await this.repository.findOne({ slug, scope });

return news ?? null;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/api/cms-api/src/generator/generate-crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5018441

Please sign in to comment.