From ff30025920416ca228bdcf534e8eb376b3c3924b Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 4 Nov 2021 12:45:44 +0530 Subject: [PATCH 01/11] feat(): added enum case mapper --- .../factories/enum-definition.factory.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts b/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts index e2c22b2b8..3be004039 100644 --- a/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts +++ b/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts @@ -1,7 +1,11 @@ +import { upperCase } from 'lodash'; import { Injectable } from '@nestjs/common'; import { GraphQLEnumType } from 'graphql'; import { EnumMetadata } from '../metadata'; +export const mapToUppercase = (value: string): string => + upperCase(value).replace(' ', '_'); + export interface EnumDefinition { enumRef: object; type: GraphQLEnumType; @@ -19,7 +23,13 @@ export class EnumDefinitionFactory { description: metadata.description, values: Object.keys(enumValues).reduce((prevValue, key) => { const valueMap = metadata.valuesMap[key]; - prevValue[key] = { + + let graphqlKey = key; + if (metadata.mapToUppercase) { + graphqlKey = mapToUppercase(key); + } + + prevValue[graphqlKey] = { value: enumValues[key], description: valueMap?.description, deprecationReason: valueMap?.deprecationReason, From cc2526e4d35e0e70f9516580e53fe82dabd187df Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 4 Nov 2021 12:45:59 +0530 Subject: [PATCH 02/11] feat(): added enum metadata --- packages/graphql/lib/schema-builder/metadata/enum.metadata.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/graphql/lib/schema-builder/metadata/enum.metadata.ts b/packages/graphql/lib/schema-builder/metadata/enum.metadata.ts index ea05f820c..182cacdd9 100644 --- a/packages/graphql/lib/schema-builder/metadata/enum.metadata.ts +++ b/packages/graphql/lib/schema-builder/metadata/enum.metadata.ts @@ -12,4 +12,5 @@ export interface EnumMetadata { name: string; description?: string; valuesMap?: EnumMetadataValuesMap; + mapToUppercase?: boolean; } From 628e73c0ae1cdfb1889e9aa012f7231e94a7927d Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 4 Nov 2021 12:46:40 +0530 Subject: [PATCH 03/11] feat(): added register enum type factory option --- .../lib/type-factories/register-enum-type.factory.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/graphql/lib/type-factories/register-enum-type.factory.ts b/packages/graphql/lib/type-factories/register-enum-type.factory.ts index fc361539b..e4c07c0b7 100644 --- a/packages/graphql/lib/type-factories/register-enum-type.factory.ts +++ b/packages/graphql/lib/type-factories/register-enum-type.factory.ts @@ -25,6 +25,12 @@ export interface EnumOptions { * A map of options for the values of the enum. */ valuesMap?: EnumMetadataValuesMap; + + /** + * Automatically map enum to UPPER_CASE in the schema. + * Defaults to `false` + */ + mapToUppercase?: boolean; } /** @@ -41,6 +47,7 @@ export function registerEnumType( name: options.name, description: options.description, valuesMap: options.valuesMap || {}, + mapToUppercase: options.mapToUppercase || false, }), ); } From a2cc1c400260257150564b6595a3ddf7e8236f61 Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 10 Feb 2022 17:47:22 +0530 Subject: [PATCH 04/11] test(): added tests for enum capitalization --- .../apollo/tests/code-first/app.module.ts | 5 ++- .../tests/code-first/cats/cats.resolver.ts | 12 +++++- .../tests/code-first/enums/cat-type.enum.ts | 13 ++++++ .../tests/e2e/code-first-schema.spec.ts | 41 ++++++++++++++++++- .../tests/graphql/sort-auto-schema.module.ts | 2 + .../transform-auto-schema-file.module.ts | 2 + .../tests/utils/printed-schema.snapshot.ts | 16 ++++++++ 7 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 packages/apollo/tests/code-first/enums/cat-type.enum.ts diff --git a/packages/apollo/tests/code-first/app.module.ts b/packages/apollo/tests/code-first/app.module.ts index a5586e455..c993ff58a 100644 --- a/packages/apollo/tests/code-first/app.module.ts +++ b/packages/apollo/tests/code-first/app.module.ts @@ -2,6 +2,7 @@ import { Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import { ApolloDriverConfig } from '../../lib'; import { ApolloDriver } from '../../lib/drivers'; +import { CatsModule } from './cats/cats.module'; import { DirectionsModule } from './directions/directions.module'; import { RecipesModule } from './recipes/recipes.module'; @@ -9,8 +10,8 @@ import { RecipesModule } from './recipes/recipes.module'; imports: [ RecipesModule, DirectionsModule, - GraphQLModule.forRoot({ - driver: ApolloDriver, + CatsModule, + GraphQLModule.forRoot({ debug: false, installSubscriptionHandlers: true, autoSchemaFile: true, diff --git a/packages/apollo/tests/code-first/cats/cats.resolver.ts b/packages/apollo/tests/code-first/cats/cats.resolver.ts index 8bfd7dcaf..214b260d5 100644 --- a/packages/apollo/tests/code-first/cats/cats.resolver.ts +++ b/packages/apollo/tests/code-first/cats/cats.resolver.ts @@ -1,4 +1,5 @@ -import { Query, Resolver } from '@nestjs/graphql'; +import { Query, Resolver, Args } from '@nestjs/graphql'; +import { CatType } from '../enums/cat-type.enum'; @Resolver() export class CatsResolver { @@ -6,4 +7,13 @@ export class CatsResolver { getAnimalName(): string { return 'cat'; } + + @Resolver() + @Query((returns) => CatType) + catType( + @Args({ name: 'catType', type: () => CatType }) + catType: CatType, + ): CatType { + return catType; + } } diff --git a/packages/apollo/tests/code-first/enums/cat-type.enum.ts b/packages/apollo/tests/code-first/enums/cat-type.enum.ts new file mode 100644 index 000000000..aa160fed5 --- /dev/null +++ b/packages/apollo/tests/code-first/enums/cat-type.enum.ts @@ -0,0 +1,13 @@ +import { registerEnumType } from '@nestjs/graphql'; + +export enum CatType { + PersianCat = 'persian-cat', + MaineCoon = 'maine-coon', + Ragdoll = 'ragdoll', +} + +registerEnumType(CatType, { + name: 'CatType', + description: 'Distinguish cats', + mapToUppercase: true, +}); diff --git a/packages/apollo/tests/e2e/code-first-schema.spec.ts b/packages/apollo/tests/e2e/code-first-schema.spec.ts index 3b337bb57..540dcc4ad 100644 --- a/packages/apollo/tests/e2e/code-first-schema.spec.ts +++ b/packages/apollo/tests/e2e/code-first-schema.spec.ts @@ -29,6 +29,7 @@ import { getSubscriptionByName, } from '../utils/introspection-schema.utils'; import { printedSchemaSnapshot } from '../utils/printed-schema.snapshot'; +import { CatsResolver } from '../code-first/cats/cats.resolver'; describe('Code-first - schema factory', () => { let schemaFactory: GraphQLSchemaFactory; @@ -50,6 +51,7 @@ describe('Code-first - schema factory', () => { [ RecipesResolver, DirectionsResolver, + CatsResolver, AbstractResolver, IRecipesResolver, ], @@ -68,10 +70,10 @@ describe('Code-first - schema factory', () => { printedSchemaSnapshot, ); }); - it('should define 5 queries', async () => { + it('should define 6 queries', async () => { const type = getQuery(introspectionSchema); - expect(type.fields.length).toEqual(5); + expect(type.fields.length).toEqual(6); expect(type.fields.map((item) => item.name)).toEqual( expect.arrayContaining([ 'recipes', @@ -79,6 +81,7 @@ describe('Code-first - schema factory', () => { 'categories', 'move', 'recipe', + 'catType', ]), ); }); @@ -154,6 +157,40 @@ describe('Code-first - schema factory', () => { ); }); + it('should define "CatType" enum to use CAPITALIZED_UNDERSCORE', () => { + const type = introspectionSchema.types.find( + ({ name }) => name === 'CatType', + ); + + expect(type).toEqual( + expect.objectContaining({ + kind: TypeKind.ENUM, + name: 'CatType', + description: 'Distinguish cats', + enumValues: [ + { + deprecationReason: null, + description: null, + isDeprecated: false, + name: 'PERSIAN_CAT', + }, + { + deprecationReason: null, + description: null, + isDeprecated: false, + name: 'MAINE_COON', + }, + { + deprecationReason: null, + description: null, + isDeprecated: false, + name: 'RAGDOLL', + }, + ], + }), + ); + }); + it('should define "SearchResultUnion" union', () => { const type = introspectionSchema.types.find( ({ name }) => name === 'SearchResultUnion', diff --git a/packages/apollo/tests/graphql/sort-auto-schema.module.ts b/packages/apollo/tests/graphql/sort-auto-schema.module.ts index 5e2d74c95..d7c0e330c 100644 --- a/packages/apollo/tests/graphql/sort-auto-schema.module.ts +++ b/packages/apollo/tests/graphql/sort-auto-schema.module.ts @@ -3,11 +3,13 @@ import { GraphQLModule } from '@nestjs/graphql'; import { ApolloDriver } from '../../lib/drivers'; import { DirectionsModule } from '../code-first/directions/directions.module'; import { RecipesModule } from '../code-first/recipes/recipes.module'; +import { CatsModule } from '../code-first/cats/cats.module'; @Module({ imports: [ RecipesModule, DirectionsModule, + CatsModule, GraphQLModule.forRoot({ driver: ApolloDriver, autoSchemaFile: 'schema.graphql', diff --git a/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts b/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts index 63931344a..e663a6060 100644 --- a/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts +++ b/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts @@ -4,11 +4,13 @@ import { GraphQLSchema, lexicographicSortSchema } from 'graphql'; import { ApolloDriver } from '../../lib/drivers'; import { DirectionsModule } from '../code-first/directions/directions.module'; import { RecipesModule } from '../code-first/recipes/recipes.module'; +import { CatsModule } from '../code-first/cats/cats.module'; @Module({ imports: [ RecipesModule, DirectionsModule, + CatsModule, GraphQLModule.forRoot({ driver: ApolloDriver, autoSchemaFile: 'schema.graphql', diff --git a/packages/apollo/tests/utils/printed-schema.snapshot.ts b/packages/apollo/tests/utils/printed-schema.snapshot.ts index d851c5dc7..7865f39e2 100644 --- a/packages/apollo/tests/utils/printed-schema.snapshot.ts +++ b/packages/apollo/tests/utils/printed-schema.snapshot.ts @@ -75,6 +75,7 @@ type Query { take: Int = 25 ): [Recipe!]! move(direction: Direction!): Direction! + catType(catType: CatType!): CatType! } """Search result description""" @@ -90,6 +91,13 @@ enum Direction { Sideways @deprecated(reason: "Replaced with Left or Right") } +"""Distinguish cats""" +enum CatType { + PERSIAN_CAT + MAINE_COON + RAGDOLL +} + type Mutation { addRecipe(newRecipeData: NewRecipeInput!): Recipe! removeRecipe(id: String!): Boolean! @@ -113,6 +121,13 @@ export const sortedPrintedSchemaSnapshot = `# ---------------------------------- # THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) # ------------------------------------------------------ +"""Distinguish cats""" +enum CatType { + MAINE_COON + PERSIAN_CAT + RAGDOLL +} + type Category { description: String! name: String! @@ -162,6 +177,7 @@ input NewRecipeInput { } type Query { + catType(catType: CatType!): CatType! categories: [Category!]! move(direction: Direction!): Direction! From 89afa7beeb24d946d851c5c5d5881cc04db496b3 Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 4 Nov 2021 20:45:41 +0530 Subject: [PATCH 05/11] refactor: change name of variable --- .../lib/schema-builder/factories/enum-definition.factory.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts b/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts index 3be004039..cfe7dba9c 100644 --- a/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts +++ b/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts @@ -24,12 +24,12 @@ export class EnumDefinitionFactory { values: Object.keys(enumValues).reduce((prevValue, key) => { const valueMap = metadata.valuesMap[key]; - let graphqlKey = key; + let enumKey = key; if (metadata.mapToUppercase) { - graphqlKey = mapToUppercase(key); + enumKey = mapToUppercase(key); } - prevValue[graphqlKey] = { + prevValue[enumKey] = { value: enumValues[key], description: valueMap?.description, deprecationReason: valueMap?.deprecationReason, From 7df98e09d4e1031a3b7dd4fbfb97be988eda072e Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Sun, 23 Jan 2022 09:33:50 +0530 Subject: [PATCH 06/11] fix(code-first): use replaceAll for uppercase mapper --- .../lib/schema-builder/factories/enum-definition.factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts b/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts index cfe7dba9c..d6993db65 100644 --- a/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts +++ b/packages/graphql/lib/schema-builder/factories/enum-definition.factory.ts @@ -4,7 +4,7 @@ import { GraphQLEnumType } from 'graphql'; import { EnumMetadata } from '../metadata'; export const mapToUppercase = (value: string): string => - upperCase(value).replace(' ', '_'); + upperCase(value).replaceAll(' ', '_'); export interface EnumDefinition { enumRef: object; From 498775e537f1dda2492e0357d79311433eebf0ea Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 10 Feb 2022 17:49:03 +0530 Subject: [PATCH 07/11] test(): added tests for enum capitalization --- packages/apollo/tests/code-first/cats/cats.resolver.ts | 4 ++++ packages/apollo/tests/code-first/enums/cat-type.enum.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/packages/apollo/tests/code-first/cats/cats.resolver.ts b/packages/apollo/tests/code-first/cats/cats.resolver.ts index 214b260d5..907d4ac52 100644 --- a/packages/apollo/tests/code-first/cats/cats.resolver.ts +++ b/packages/apollo/tests/code-first/cats/cats.resolver.ts @@ -1,4 +1,8 @@ +<<<<<<< HEAD import { Query, Resolver, Args } from '@nestjs/graphql'; +======= +import { Args, Query, Resolver } from '@nestjs/graphql'; +>>>>>>> 7624329 (chore(code-first): update imports to workspace paths) import { CatType } from '../enums/cat-type.enum'; @Resolver() diff --git a/packages/apollo/tests/code-first/enums/cat-type.enum.ts b/packages/apollo/tests/code-first/enums/cat-type.enum.ts index aa160fed5..f51d741c4 100644 --- a/packages/apollo/tests/code-first/enums/cat-type.enum.ts +++ b/packages/apollo/tests/code-first/enums/cat-type.enum.ts @@ -1,5 +1,8 @@ import { registerEnumType } from '@nestjs/graphql'; +<<<<<<< HEAD +======= +>>>>>>> 7624329 (chore(code-first): update imports to workspace paths) export enum CatType { PersianCat = 'persian-cat', MaineCoon = 'maine-coon', From f49701940ddd383f85a709fee971de91d0ba56e4 Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Tue, 25 Jan 2022 01:52:38 +0530 Subject: [PATCH 08/11] fix(code-first): respect new apollo loader --- packages/apollo/tests/code-first/app.module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/apollo/tests/code-first/app.module.ts b/packages/apollo/tests/code-first/app.module.ts index c993ff58a..cb1df6f62 100644 --- a/packages/apollo/tests/code-first/app.module.ts +++ b/packages/apollo/tests/code-first/app.module.ts @@ -11,7 +11,8 @@ import { RecipesModule } from './recipes/recipes.module'; RecipesModule, DirectionsModule, CatsModule, - GraphQLModule.forRoot({ + GraphQLModule.forRoot({ + driver: ApolloDriver, debug: false, installSubscriptionHandlers: true, autoSchemaFile: true, From 406113ad0c351f9f3cf6d5b1b9c9c81193811b1e Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Tue, 25 Jan 2022 02:08:08 +0530 Subject: [PATCH 09/11] refactor(code-first): rearrange import --- packages/apollo/tests/e2e/code-first-schema.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apollo/tests/e2e/code-first-schema.spec.ts b/packages/apollo/tests/e2e/code-first-schema.spec.ts index 540dcc4ad..26ac6d6c5 100644 --- a/packages/apollo/tests/e2e/code-first-schema.spec.ts +++ b/packages/apollo/tests/e2e/code-first-schema.spec.ts @@ -20,6 +20,7 @@ import { SampleOrphanedType } from '../code-first/other/sample-orphaned.type'; import { IRecipesResolver } from '../code-first/recipes/irecipes.resolver'; import { Recipe } from '../code-first/recipes/models/recipe'; import { RecipesResolver } from '../code-first/recipes/recipes.resolver'; +import { CatsResolver } from '../code-first/cats/cats.resolver'; import { getMutation, getMutationByName, @@ -29,7 +30,6 @@ import { getSubscriptionByName, } from '../utils/introspection-schema.utils'; import { printedSchemaSnapshot } from '../utils/printed-schema.snapshot'; -import { CatsResolver } from '../code-first/cats/cats.resolver'; describe('Code-first - schema factory', () => { let schemaFactory: GraphQLSchemaFactory; From c2f9576b987e29c9fc1ec1b287051ccfa0911b62 Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 10 Feb 2022 22:46:32 +0530 Subject: [PATCH 10/11] test(code-first): added tests for enum capitalization --- .../tests/code-first/cats/cats.resolver.ts | 5 ----- .../tests/code-first/enums/cat-type.enum.ts | 5 ++--- .../apollo/tests/e2e/code-first-schema.spec.ts | 16 ++++++++++++++-- .../tests/graphql/sort-auto-schema.module.ts | 2 +- .../graphql/transform-auto-schema-file.module.ts | 2 +- .../tests/utils/printed-schema.snapshot.ts | 6 ++++++ 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/apollo/tests/code-first/cats/cats.resolver.ts b/packages/apollo/tests/code-first/cats/cats.resolver.ts index 907d4ac52..95cf34c83 100644 --- a/packages/apollo/tests/code-first/cats/cats.resolver.ts +++ b/packages/apollo/tests/code-first/cats/cats.resolver.ts @@ -1,8 +1,4 @@ -<<<<<<< HEAD -import { Query, Resolver, Args } from '@nestjs/graphql'; -======= import { Args, Query, Resolver } from '@nestjs/graphql'; ->>>>>>> 7624329 (chore(code-first): update imports to workspace paths) import { CatType } from '../enums/cat-type.enum'; @Resolver() @@ -12,7 +8,6 @@ export class CatsResolver { return 'cat'; } - @Resolver() @Query((returns) => CatType) catType( @Args({ name: 'catType', type: () => CatType }) diff --git a/packages/apollo/tests/code-first/enums/cat-type.enum.ts b/packages/apollo/tests/code-first/enums/cat-type.enum.ts index f51d741c4..60e2ee75f 100644 --- a/packages/apollo/tests/code-first/enums/cat-type.enum.ts +++ b/packages/apollo/tests/code-first/enums/cat-type.enum.ts @@ -1,12 +1,11 @@ import { registerEnumType } from '@nestjs/graphql'; -<<<<<<< HEAD -======= ->>>>>>> 7624329 (chore(code-first): update imports to workspace paths) export enum CatType { PersianCat = 'persian-cat', MaineCoon = 'maine-coon', Ragdoll = 'ragdoll', + SomeNewAwesomeCat = 'some-new-awesome-cat', + SomeWEIRDCat = 'some-weird-cat', } registerEnumType(CatType, { diff --git a/packages/apollo/tests/e2e/code-first-schema.spec.ts b/packages/apollo/tests/e2e/code-first-schema.spec.ts index 26ac6d6c5..ffb9e02b6 100644 --- a/packages/apollo/tests/e2e/code-first-schema.spec.ts +++ b/packages/apollo/tests/e2e/code-first-schema.spec.ts @@ -70,10 +70,10 @@ describe('Code-first - schema factory', () => { printedSchemaSnapshot, ); }); - it('should define 6 queries', async () => { + it('should define 7 queries', async () => { const type = getQuery(introspectionSchema); - expect(type.fields.length).toEqual(6); + expect(type.fields.length).toEqual(7); expect(type.fields.map((item) => item.name)).toEqual( expect.arrayContaining([ 'recipes', @@ -186,6 +186,18 @@ describe('Code-first - schema factory', () => { isDeprecated: false, name: 'RAGDOLL', }, + { + deprecationReason: null, + description: null, + isDeprecated: false, + name: 'SOME_NEW_AWESOME_CAT', + }, + { + deprecationReason: null, + description: null, + isDeprecated: false, + name: 'SOME_WEIRD_CAT', + }, ], }), ); diff --git a/packages/apollo/tests/graphql/sort-auto-schema.module.ts b/packages/apollo/tests/graphql/sort-auto-schema.module.ts index d7c0e330c..ff0ff0b7a 100644 --- a/packages/apollo/tests/graphql/sort-auto-schema.module.ts +++ b/packages/apollo/tests/graphql/sort-auto-schema.module.ts @@ -9,7 +9,7 @@ import { CatsModule } from '../code-first/cats/cats.module'; imports: [ RecipesModule, DirectionsModule, - CatsModule, + CatsModule.register('useClass'), GraphQLModule.forRoot({ driver: ApolloDriver, autoSchemaFile: 'schema.graphql', diff --git a/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts b/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts index e663a6060..923de0cce 100644 --- a/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts +++ b/packages/apollo/tests/graphql/transform-auto-schema-file.module.ts @@ -10,7 +10,7 @@ import { CatsModule } from '../code-first/cats/cats.module'; imports: [ RecipesModule, DirectionsModule, - CatsModule, + CatsModule.register('useClass'), GraphQLModule.forRoot({ driver: ApolloDriver, autoSchemaFile: 'schema.graphql', diff --git a/packages/apollo/tests/utils/printed-schema.snapshot.ts b/packages/apollo/tests/utils/printed-schema.snapshot.ts index 7865f39e2..811d65085 100644 --- a/packages/apollo/tests/utils/printed-schema.snapshot.ts +++ b/packages/apollo/tests/utils/printed-schema.snapshot.ts @@ -75,6 +75,7 @@ type Query { take: Int = 25 ): [Recipe!]! move(direction: Direction!): Direction! + getAnimalName: String! catType(catType: CatType!): CatType! } @@ -96,6 +97,8 @@ enum CatType { PERSIAN_CAT MAINE_COON RAGDOLL + SOME_NEW_AWESOME_CAT + SOME_WEIRD_CAT } type Mutation { @@ -126,6 +129,8 @@ enum CatType { MAINE_COON PERSIAN_CAT RAGDOLL + SOME_NEW_AWESOME_CAT + SOME_WEIRD_CAT } type Category { @@ -179,6 +184,7 @@ input NewRecipeInput { type Query { catType(catType: CatType!): CatType! categories: [Category!]! + getAnimalName: String! move(direction: Direction!): Direction! """get recipe by id""" From b5b647b56c964a2524bf03c461850f74a38ab99c Mon Sep 17 00:00:00 2001 From: Kasun Vithanage Date: Thu, 10 Feb 2022 23:00:04 +0530 Subject: [PATCH 11/11] test(code-first): added more testcases to enum case mapper --- packages/apollo/tests/code-first/enums/cat-type.enum.ts | 1 + packages/apollo/tests/e2e/code-first-schema.spec.ts | 6 ++++++ packages/apollo/tests/utils/printed-schema.snapshot.ts | 2 ++ 3 files changed, 9 insertions(+) diff --git a/packages/apollo/tests/code-first/enums/cat-type.enum.ts b/packages/apollo/tests/code-first/enums/cat-type.enum.ts index 60e2ee75f..8f2fda287 100644 --- a/packages/apollo/tests/code-first/enums/cat-type.enum.ts +++ b/packages/apollo/tests/code-first/enums/cat-type.enum.ts @@ -6,6 +6,7 @@ export enum CatType { Ragdoll = 'ragdoll', SomeNewAwesomeCat = 'some-new-awesome-cat', SomeWEIRDCat = 'some-weird-cat', + anotherAwesomeCat = 'another-awesome-cat', } registerEnumType(CatType, { diff --git a/packages/apollo/tests/e2e/code-first-schema.spec.ts b/packages/apollo/tests/e2e/code-first-schema.spec.ts index ffb9e02b6..7a8e601da 100644 --- a/packages/apollo/tests/e2e/code-first-schema.spec.ts +++ b/packages/apollo/tests/e2e/code-first-schema.spec.ts @@ -198,6 +198,12 @@ describe('Code-first - schema factory', () => { isDeprecated: false, name: 'SOME_WEIRD_CAT', }, + { + deprecationReason: null, + description: null, + isDeprecated: false, + name: 'ANOTHER_AWESOME_CAT', + }, ], }), ); diff --git a/packages/apollo/tests/utils/printed-schema.snapshot.ts b/packages/apollo/tests/utils/printed-schema.snapshot.ts index 811d65085..bff3ba0fb 100644 --- a/packages/apollo/tests/utils/printed-schema.snapshot.ts +++ b/packages/apollo/tests/utils/printed-schema.snapshot.ts @@ -99,6 +99,7 @@ enum CatType { RAGDOLL SOME_NEW_AWESOME_CAT SOME_WEIRD_CAT + ANOTHER_AWESOME_CAT } type Mutation { @@ -126,6 +127,7 @@ export const sortedPrintedSchemaSnapshot = `# ---------------------------------- """Distinguish cats""" enum CatType { + ANOTHER_AWESOME_CAT MAINE_COON PERSIAN_CAT RAGDOLL