-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Add API extension command
- Loading branch information
1 parent
455698f
commit 41675a4
Showing
16 changed files
with
676 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
449 changes: 449 additions & 0 deletions
449
packages/cli/src/commands/add/api-extension/add-api-extension.ts
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
packages/cli/src/commands/add/api-extension/templates/api-extensions.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { DocumentNode } from 'graphql/language/index'; | ||
import gql from 'graphql-tag'; | ||
|
||
const adminApiExtensionDocuments: DocumentNode[] = []; | ||
|
||
export const adminApiExtensions = gql` | ||
${adminApiExtensionDocuments.join('\n')} | ||
`; |
65 changes: 65 additions & 0 deletions
65
packages/cli/src/commands/add/api-extension/templates/crud-resolver.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; | ||
import { DeletionResponse, Permission } from '@vendure/common/lib/generated-types'; | ||
import { Allow, Ctx, PaginatedList, RequestContext, Transaction, VendureEntity } from '@vendure/core'; | ||
|
||
class TemplateEntity extends VendureEntity {} | ||
|
||
class TemplateService { | ||
findAll(ctx: RequestContext, options?: any): Promise<PaginatedList<TemplateEntity>> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
findOne(ctx: RequestContext, id: string): Promise<TemplateEntity | null> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
create(ctx: RequestContext, input: any): Promise<TemplateEntity> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
update(ctx: RequestContext, input: any): Promise<TemplateEntity> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
delete(ctx: RequestContext, id: string): Promise<DeletionResponse> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} | ||
|
||
@Resolver() | ||
export class EntityAdminResolver { | ||
constructor(private templateService: TemplateService) {} | ||
|
||
@Query() | ||
@Allow(Permission.SuperAdmin) | ||
async entity(@Ctx() ctx: RequestContext, @Args() args: any): Promise<TemplateEntity | null> { | ||
return this.templateService.findOne(ctx, args.id); | ||
} | ||
|
||
@Query() | ||
@Allow(Permission.SuperAdmin) | ||
async entities(@Ctx() ctx: RequestContext, @Args() args: any): Promise<PaginatedList<TemplateEntity>> { | ||
return this.templateService.findAll(ctx, args.options || undefined); | ||
} | ||
|
||
@Mutation() | ||
@Transaction() | ||
@Allow(Permission.SuperAdmin) | ||
async createEntity(@Ctx() ctx: RequestContext, @Args() args: any): Promise<TemplateEntity> { | ||
return this.templateService.create(ctx, args.input); | ||
} | ||
|
||
@Mutation() | ||
@Transaction() | ||
@Allow(Permission.SuperAdmin) | ||
async updateEntity(@Ctx() ctx: RequestContext, @Args() args: any): Promise<TemplateEntity> { | ||
return this.templateService.update(ctx, args.input); | ||
} | ||
|
||
@Mutation() | ||
@Transaction() | ||
@Allow(Permission.SuperAdmin) | ||
async deleteEntity(@Ctx() ctx: RequestContext, @Args() args: any): Promise<DeletionResponse> { | ||
return this.templateService.delete(ctx, args.id); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/cli/src/commands/add/api-extension/templates/simple-resolver.template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql'; | ||
import { Permission } from '@vendure/common/lib/generated-types'; | ||
import { Allow, Ctx, RequestContext } from '@vendure/core'; | ||
|
||
class TemplateService {} | ||
|
||
@Resolver() | ||
export class SimpleAdminResolver { | ||
constructor(private templateService: TemplateService) {} | ||
|
||
@Query() | ||
@Allow(Permission.SuperAdmin) | ||
async exampleQuery(@Ctx() ctx: RequestContext, @Args() args: { id: string }): Promise<boolean> { | ||
return true; | ||
} | ||
|
||
@Mutation() | ||
@Allow(Permission.SuperAdmin) | ||
async exampleMutation(@Ctx() ctx: RequestContext, @Args() args: { id: string }): Promise<boolean> { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.