diff --git a/.prettierignore b/.prettierignore index 8f92f6248..1c83f7348 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,5 @@ .prettierignore .docusaurus/ /.nx/cache -/.nx/workspace-data \ No newline at end of file +/.nx/workspace-data +**/examples/**/*.gql \ No newline at end of file diff --git a/packages/query-graphql/__tests__/decorators/relation.decorator.spec.ts b/packages/query-graphql/__tests__/decorators/relation.decorator.spec.ts index 85d83e4fb..a3366a017 100644 --- a/packages/query-graphql/__tests__/decorators/relation.decorator.spec.ts +++ b/packages/query-graphql/__tests__/decorators/relation.decorator.spec.ts @@ -9,7 +9,14 @@ import { UnPagedRelation } from '@ptc-org/nestjs-query-graphql' -import { CursorConnection, FilterableCursorConnection, FilterableOffsetConnection, getRelations } from '../../src/decorators' +import { + CursorConnection, + FilterableCursorConnection, + FilterableOffsetConnection, + getRelations, + RelationOneDecoratorOpts +} from '../../src/decorators' +import { RelationManyDecoratorOpts } from 'packages/query-graphql/src/decorators/relation.decorator' @ObjectType() class TestRelation {} @@ -26,6 +33,23 @@ describe('@Relation', () => { const relations = getRelations(TestDTO) expect(relations).toEqual({ one: { test: { DTO: TestRelation, allowFiltering: false, ...relationOpts } } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @Relation('test', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ one: { test: { DTO: TestRelation, allowFiltering: false, ...relationOpts } } }) + }) }) describe('@FilterableRelation', () => { @@ -40,6 +64,23 @@ describe('@FilterableRelation', () => { const relations = getRelations(TestDTO) expect(relations).toEqual({ one: { test: { DTO: TestRelation, ...relationOpts, allowFiltering: true } } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @FilterableRelation('test', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ one: { test: { DTO: TestRelation, ...relationOpts, allowFiltering: true } } }) + }) }) describe('@UnPagedRelation', () => { @@ -58,6 +99,27 @@ describe('@UnPagedRelation', () => { } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @UnPagedRelation('tests', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ + many: { + tests: { DTO: TestRelation, ...relationOpts, allowFiltering: false, pagingStrategy: PagingStrategies.NONE } + } + }) + }) }) describe('@FilterableUnPagedRelation', () => { @@ -76,6 +138,27 @@ describe('@FilterableUnPagedRelation', () => { } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @FilterableUnPagedRelation('test', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ + many: { + test: { DTO: TestRelation, pagingStrategy: PagingStrategies.NONE, ...relationOpts, allowFiltering: true } + } + }) + }) }) describe('@OffsetConnection', () => { @@ -94,6 +177,27 @@ describe('@OffsetConnection', () => { } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @OffsetConnection('test', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ + many: { + test: { DTO: TestRelation, ...relationOpts, allowFiltering: false, pagingStrategy: PagingStrategies.OFFSET } + } + }) + }) }) describe('@FilterableOffsetConnection', () => { @@ -112,6 +216,27 @@ describe('@FilterableOffsetConnection', () => { } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @FilterableOffsetConnection('test', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ + many: { + test: { DTO: TestRelation, ...relationOpts, pagingStrategy: PagingStrategies.OFFSET, allowFiltering: true } + } + }) + }) }) describe('@CursorConnection', () => { @@ -130,6 +255,27 @@ describe('@CursorConnection', () => { } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @CursorConnection('test', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ + many: { + test: { DTO: TestRelation, ...relationOpts, allowFiltering: false, pagingStrategy: PagingStrategies.CURSOR } + } + }) + }) }) describe('@FilterableCursorConnection', () => { @@ -148,6 +294,27 @@ describe('@FilterableCursorConnection', () => { } }) }) + + it('should add the deprecationReason to the options', () => { + // Arrange + const relationFn = () => TestRelation + const relationOpts: Partial> = { + deprecationReason: 'Deprecated for no apparent reason.' + } + @ObjectType() + @FilterableCursorConnection('test', relationFn, relationOpts) + class TestDTO {} + + // Act + const relations = getRelations(TestDTO) + + // Assert + expect(relations).toEqual({ + many: { + test: { DTO: TestRelation, ...relationOpts, pagingStrategy: PagingStrategies.CURSOR, allowFiltering: true } + } + }) + }) }) describe('getRelations', () => { diff --git a/packages/query-graphql/src/resolvers/relations/read-relations.resolver.ts b/packages/query-graphql/src/resolvers/relations/read-relations.resolver.ts index b2841c79f..7bd109046 100644 --- a/packages/query-graphql/src/resolvers/relations/read-relations.resolver.ts +++ b/packages/query-graphql/src/resolvers/relations/read-relations.resolver.ts @@ -37,7 +37,12 @@ const ReadOneRelationMixin = @ResolverField( baseNameLower, () => relationDTO, - { nullable: relation.nullable, complexity: relation.complexity, description: relation?.description }, + { + nullable: relation.nullable, + complexity: relation.complexity, + description: relation?.description, + deprecationReason: relation?.deprecationReason + }, commonResolverOpts, { interceptors: [AuthorizerInterceptor(DTOClass)] } ) @@ -107,7 +112,12 @@ const ReadManyRelationMixin = @ResolverField( baseNameLower, () => CT.resolveType, - { nullable: relation.nullable, complexity: relation.complexity, description: relation?.description }, + { + nullable: relation.nullable, + complexity: relation.complexity, + description: relation?.description, + deprecationReason: relation?.deprecationReason + }, commonResolverOpts, { interceptors: [AuthorizerInterceptor(DTOClass)] } ) diff --git a/packages/query-graphql/src/resolvers/relations/relations.interface.ts b/packages/query-graphql/src/resolvers/relations/relations.interface.ts index 0259585de..9ae3ebd4a 100644 --- a/packages/query-graphql/src/resolvers/relations/relations.interface.ts +++ b/packages/query-graphql/src/resolvers/relations/relations.interface.ts @@ -1,4 +1,4 @@ -import { Complexity } from '@nestjs/graphql' +import { Complexity, FieldOptions } from '@nestjs/graphql' import { Class } from '@ptc-org/nestjs-query-core' import { AuthorizerOptions } from '../../auth' @@ -68,8 +68,6 @@ export type ResolverRelation = { */ description?: string - complexity?: Complexity - update?: Pick, 'description'> & ResolverRelationMethodOpts remove?: Pick, 'description'> & ResolverRelationMethodOpts /** @@ -82,7 +80,8 @@ export type ResolverRelation = { } & DTONamesOpts & ResolverMethodOpts & QueryArgsTypeOpts & - Pick + Pick & + Omit export type RelationTypeMap = Record