diff --git a/.changeset/shaggy-geese-matter.md b/.changeset/shaggy-geese-matter.md new file mode 100644 index 00000000..eaf5963b --- /dev/null +++ b/.changeset/shaggy-geese-matter.md @@ -0,0 +1,5 @@ +--- +'@eddeee888/gcg-typescript-resolver-files': patch +--- + +Fix issue where GraphQLScalarType is imported all the time, regardless of whether it's used diff --git a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/base.graphqls b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/base.graphqls index 24be76d7..ef385412 100644 --- a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/base.graphqls +++ b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/base.graphqls @@ -30,3 +30,4 @@ type PaginationResult { scalar DateTime scalar SomeRandomScalar +scalar CustomLogicScalar diff --git a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/resolvers/CustomLogicScalar.ts b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/resolvers/CustomLogicScalar.ts new file mode 100644 index 00000000..959400fc --- /dev/null +++ b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/resolvers/CustomLogicScalar.ts @@ -0,0 +1,3 @@ +import { DateResolver } from 'graphql-scalars'; +DateResolver.description = undefined; +export const CustomLogicScalar = DateResolver; diff --git a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/resolvers.generated.ts b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/resolvers.generated.ts index b6b8c5df..4bebe559 100644 --- a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/resolvers.generated.ts +++ b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/resolvers.generated.ts @@ -8,6 +8,7 @@ import { Profile } from './zoo/resolvers/Profile'; import { Topic } from './topic/resolvers/Topic'; import { TopicCreateResult } from './topic/resolvers/TopicCreateResult'; import { User } from './pet/resolvers/User'; +import { CustomLogicScalar } from './base/resolvers/CustomLogicScalar'; import { SomeRandomScalar } from './base/resolvers/SomeRandomScalar'; import { Error } from './base/resolvers/Error'; import { TopicCreatePayload } from './topic/resolvers/TopicCreatePayload'; @@ -26,6 +27,7 @@ export const resolvers: Resolvers = { Topic: Topic, TopicCreateResult: TopicCreateResult, User: User, + CustomLogicScalar: CustomLogicScalar, SomeRandomScalar: SomeRandomScalar, Error: Error, TopicCreatePayload: TopicCreatePayload, diff --git a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/typeDefs.generated.ts b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/typeDefs.generated.ts index 9bf7c7df..9c90fefd 100644 --- a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/typeDefs.generated.ts +++ b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/typeDefs.generated.ts @@ -285,15 +285,25 @@ export const typeDefs = { directives: [], loc: { start: 412, end: 435 }, }, + { + kind: 'ScalarTypeDefinition', + name: { + kind: 'Name', + value: 'CustomLogicScalar', + loc: { start: 444, end: 461 }, + }, + directives: [], + loc: { start: 437, end: 461 }, + }, { kind: 'ObjectTypeDefinition', - name: { kind: 'Name', value: 'Pet', loc: { start: 441, end: 444 } }, + name: { kind: 'Name', value: 'Pet', loc: { start: 467, end: 470 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'id', loc: { start: 449, end: 451 } }, + name: { kind: 'Name', value: 'id', loc: { start: 475, end: 477 } }, arguments: [], type: { kind: 'NonNullType', @@ -302,18 +312,18 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 453, end: 455 }, + loc: { start: 479, end: 481 }, }, - loc: { start: 453, end: 455 }, + loc: { start: 479, end: 481 }, }, - loc: { start: 453, end: 456 }, + loc: { start: 479, end: 482 }, }, directives: [], - loc: { start: 449, end: 456 }, + loc: { start: 475, end: 482 }, }, { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'name', loc: { start: 459, end: 463 } }, + name: { kind: 'Name', value: 'name', loc: { start: 485, end: 489 } }, arguments: [], type: { kind: 'NonNullType', @@ -322,21 +332,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 465, end: 471 }, + loc: { start: 491, end: 497 }, }, - loc: { start: 465, end: 471 }, + loc: { start: 491, end: 497 }, }, - loc: { start: 465, end: 472 }, + loc: { start: 491, end: 498 }, }, directives: [], - loc: { start: 459, end: 472 }, + loc: { start: 485, end: 498 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'primaryOwner', - loc: { start: 475, end: 487 }, + loc: { start: 501, end: 513 }, }, arguments: [], type: { @@ -346,27 +356,27 @@ export const typeDefs = { name: { kind: 'Name', value: 'User', - loc: { start: 489, end: 493 }, + loc: { start: 515, end: 519 }, }, - loc: { start: 489, end: 493 }, + loc: { start: 515, end: 519 }, }, - loc: { start: 489, end: 494 }, + loc: { start: 515, end: 520 }, }, directives: [], - loc: { start: 475, end: 494 }, + loc: { start: 501, end: 520 }, }, ], - loc: { start: 436, end: 496 }, + loc: { start: 462, end: 522 }, }, { kind: 'ObjectTypeExtension', - name: { kind: 'Name', value: 'User', loc: { start: 510, end: 514 } }, + name: { kind: 'Name', value: 'User', loc: { start: 536, end: 540 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'pets', loc: { start: 519, end: 523 } }, + name: { kind: 'Name', value: 'pets', loc: { start: 545, end: 549 } }, arguments: [], type: { kind: 'NonNullType', @@ -379,25 +389,25 @@ export const typeDefs = { name: { kind: 'Name', value: 'Pet', - loc: { start: 526, end: 529 }, + loc: { start: 552, end: 555 }, }, - loc: { start: 526, end: 529 }, + loc: { start: 552, end: 555 }, }, - loc: { start: 526, end: 530 }, + loc: { start: 552, end: 556 }, }, - loc: { start: 525, end: 531 }, + loc: { start: 551, end: 557 }, }, - loc: { start: 525, end: 532 }, + loc: { start: 551, end: 558 }, }, directives: [], - loc: { start: 519, end: 532 }, + loc: { start: 545, end: 558 }, }, ], - loc: { start: 498, end: 534 }, + loc: { start: 524, end: 560 }, }, { kind: 'ObjectTypeExtension', - name: { kind: 'Name', value: 'Query', loc: { start: 547, end: 552 } }, + name: { kind: 'Name', value: 'Query', loc: { start: 573, end: 578 } }, interfaces: [], directives: [], fields: [ @@ -406,7 +416,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'topicById', - loc: { start: 557, end: 566 }, + loc: { start: 583, end: 592 }, }, arguments: [ { @@ -414,7 +424,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'id', - loc: { start: 567, end: 569 }, + loc: { start: 593, end: 595 }, }, type: { kind: 'NonNullType', @@ -423,14 +433,14 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 571, end: 573 }, + loc: { start: 597, end: 599 }, }, - loc: { start: 571, end: 573 }, + loc: { start: 597, end: 599 }, }, - loc: { start: 571, end: 574 }, + loc: { start: 597, end: 600 }, }, directives: [], - loc: { start: 567, end: 574 }, + loc: { start: 593, end: 600 }, }, ], type: { @@ -440,21 +450,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicByIdPayload', - loc: { start: 577, end: 593 }, + loc: { start: 603, end: 619 }, }, - loc: { start: 577, end: 593 }, + loc: { start: 603, end: 619 }, }, - loc: { start: 577, end: 594 }, + loc: { start: 603, end: 620 }, }, directives: [], - loc: { start: 557, end: 594 }, + loc: { start: 583, end: 620 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'topicsCreatedByUser', - loc: { start: 597, end: 616 }, + loc: { start: 623, end: 642 }, }, arguments: [ { @@ -462,7 +472,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'input', - loc: { start: 617, end: 622 }, + loc: { start: 643, end: 648 }, }, type: { kind: 'NonNullType', @@ -471,14 +481,14 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicsCreatedByUserInput', - loc: { start: 624, end: 648 }, + loc: { start: 650, end: 674 }, }, - loc: { start: 624, end: 648 }, + loc: { start: 650, end: 674 }, }, - loc: { start: 624, end: 649 }, + loc: { start: 650, end: 675 }, }, directives: [], - loc: { start: 617, end: 649 }, + loc: { start: 643, end: 675 }, }, ], type: { @@ -488,21 +498,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicsCreatedByUserPayload', - loc: { start: 652, end: 678 }, + loc: { start: 678, end: 704 }, }, - loc: { start: 652, end: 678 }, + loc: { start: 678, end: 704 }, }, - loc: { start: 652, end: 679 }, + loc: { start: 678, end: 705 }, }, directives: [], - loc: { start: 597, end: 679 }, + loc: { start: 623, end: 705 }, }, ], - loc: { start: 535, end: 681 }, + loc: { start: 561, end: 707 }, }, { kind: 'ObjectTypeExtension', - name: { kind: 'Name', value: 'Mutation', loc: { start: 695, end: 703 } }, + name: { kind: 'Name', value: 'Mutation', loc: { start: 721, end: 729 } }, interfaces: [], directives: [], fields: [ @@ -511,7 +521,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'topicCreate', - loc: { start: 708, end: 719 }, + loc: { start: 734, end: 745 }, }, arguments: [ { @@ -519,7 +529,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'input', - loc: { start: 720, end: 725 }, + loc: { start: 746, end: 751 }, }, type: { kind: 'NonNullType', @@ -528,14 +538,14 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicCreateInput', - loc: { start: 727, end: 743 }, + loc: { start: 753, end: 769 }, }, - loc: { start: 727, end: 743 }, + loc: { start: 753, end: 769 }, }, - loc: { start: 727, end: 744 }, + loc: { start: 753, end: 770 }, }, directives: [], - loc: { start: 720, end: 744 }, + loc: { start: 746, end: 770 }, }, ], type: { @@ -545,21 +555,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicCreatePayload', - loc: { start: 747, end: 765 }, + loc: { start: 773, end: 791 }, }, - loc: { start: 747, end: 765 }, + loc: { start: 773, end: 791 }, }, - loc: { start: 747, end: 766 }, + loc: { start: 773, end: 792 }, }, directives: [], - loc: { start: 708, end: 766 }, + loc: { start: 734, end: 792 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'topicEdit', - loc: { start: 769, end: 778 }, + loc: { start: 795, end: 804 }, }, arguments: [ { @@ -567,7 +577,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'input', - loc: { start: 779, end: 784 }, + loc: { start: 805, end: 810 }, }, type: { kind: 'NonNullType', @@ -576,14 +586,14 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicEditInput', - loc: { start: 786, end: 800 }, + loc: { start: 812, end: 826 }, }, - loc: { start: 786, end: 800 }, + loc: { start: 812, end: 826 }, }, - loc: { start: 786, end: 801 }, + loc: { start: 812, end: 827 }, }, directives: [], - loc: { start: 779, end: 801 }, + loc: { start: 805, end: 827 }, }, ], type: { @@ -593,27 +603,27 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicEditPayload', - loc: { start: 804, end: 820 }, + loc: { start: 830, end: 846 }, }, - loc: { start: 804, end: 820 }, + loc: { start: 830, end: 846 }, }, - loc: { start: 804, end: 821 }, + loc: { start: 830, end: 847 }, }, directives: [], - loc: { start: 769, end: 821 }, + loc: { start: 795, end: 847 }, }, ], - loc: { start: 683, end: 823 }, + loc: { start: 709, end: 849 }, }, { kind: 'ObjectTypeDefinition', - name: { kind: 'Name', value: 'Topic', loc: { start: 830, end: 835 } }, + name: { kind: 'Name', value: 'Topic', loc: { start: 856, end: 861 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'id', loc: { start: 840, end: 842 } }, + name: { kind: 'Name', value: 'id', loc: { start: 866, end: 868 } }, arguments: [], type: { kind: 'NonNullType', @@ -622,18 +632,18 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 844, end: 846 }, + loc: { start: 870, end: 872 }, }, - loc: { start: 844, end: 846 }, + loc: { start: 870, end: 872 }, }, - loc: { start: 844, end: 847 }, + loc: { start: 870, end: 873 }, }, directives: [], - loc: { start: 840, end: 847 }, + loc: { start: 866, end: 873 }, }, { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'name', loc: { start: 850, end: 854 } }, + name: { kind: 'Name', value: 'name', loc: { start: 876, end: 880 } }, arguments: [], type: { kind: 'NonNullType', @@ -642,37 +652,37 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 856, end: 862 }, + loc: { start: 882, end: 888 }, }, - loc: { start: 856, end: 862 }, + loc: { start: 882, end: 888 }, }, - loc: { start: 856, end: 863 }, + loc: { start: 882, end: 889 }, }, directives: [], - loc: { start: 850, end: 863 }, + loc: { start: 876, end: 889 }, }, { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'url', loc: { start: 866, end: 869 } }, + name: { kind: 'Name', value: 'url', loc: { start: 892, end: 895 } }, arguments: [], type: { kind: 'NamedType', name: { kind: 'Name', value: 'String', - loc: { start: 871, end: 877 }, + loc: { start: 897, end: 903 }, }, - loc: { start: 871, end: 877 }, + loc: { start: 897, end: 903 }, }, directives: [], - loc: { start: 866, end: 877 }, + loc: { start: 892, end: 903 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'creator', - loc: { start: 880, end: 887 }, + loc: { start: 906, end: 913 }, }, arguments: [], type: { @@ -682,21 +692,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'User', - loc: { start: 889, end: 893 }, + loc: { start: 915, end: 919 }, }, - loc: { start: 889, end: 893 }, + loc: { start: 915, end: 919 }, }, - loc: { start: 889, end: 894 }, + loc: { start: 915, end: 920 }, }, directives: [], - loc: { start: 880, end: 894 }, + loc: { start: 906, end: 920 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'createdAt', - loc: { start: 897, end: 906 }, + loc: { start: 923, end: 932 }, }, arguments: [], type: { @@ -706,24 +716,24 @@ export const typeDefs = { name: { kind: 'Name', value: 'DateTime', - loc: { start: 908, end: 916 }, + loc: { start: 934, end: 942 }, }, - loc: { start: 908, end: 916 }, + loc: { start: 934, end: 942 }, }, - loc: { start: 908, end: 917 }, + loc: { start: 934, end: 943 }, }, directives: [], - loc: { start: 897, end: 917 }, + loc: { start: 923, end: 943 }, }, ], - loc: { start: 825, end: 919 }, + loc: { start: 851, end: 945 }, }, { kind: 'ObjectTypeDefinition', name: { kind: 'Name', value: 'TopicByIdResult', - loc: { start: 926, end: 941 }, + loc: { start: 952, end: 967 }, }, interfaces: [], directives: [], @@ -733,7 +743,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'result', - loc: { start: 946, end: 952 }, + loc: { start: 972, end: 978 }, }, arguments: [], type: { @@ -741,22 +751,22 @@ export const typeDefs = { name: { kind: 'Name', value: 'Topic', - loc: { start: 954, end: 959 }, + loc: { start: 980, end: 985 }, }, - loc: { start: 954, end: 959 }, + loc: { start: 980, end: 985 }, }, directives: [], - loc: { start: 946, end: 959 }, + loc: { start: 972, end: 985 }, }, ], - loc: { start: 921, end: 961 }, + loc: { start: 947, end: 987 }, }, { kind: 'UnionTypeDefinition', name: { kind: 'Name', value: 'TopicByIdPayload', - loc: { start: 969, end: 985 }, + loc: { start: 995, end: 1011 }, }, directives: [], types: [ @@ -765,28 +775,28 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicByIdResult', - loc: { start: 988, end: 1003 }, + loc: { start: 1014, end: 1029 }, }, - loc: { start: 988, end: 1003 }, + loc: { start: 1014, end: 1029 }, }, { kind: 'NamedType', name: { kind: 'Name', value: 'PayloadError', - loc: { start: 1006, end: 1018 }, + loc: { start: 1032, end: 1044 }, }, - loc: { start: 1006, end: 1018 }, + loc: { start: 1032, end: 1044 }, }, ], - loc: { start: 963, end: 1018 }, + loc: { start: 989, end: 1044 }, }, { kind: 'InputObjectTypeDefinition', name: { kind: 'Name', value: 'TopicsCreatedByUserInput', - loc: { start: 1026, end: 1050 }, + loc: { start: 1052, end: 1076 }, }, directives: [], fields: [ @@ -795,7 +805,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'userId', - loc: { start: 1055, end: 1061 }, + loc: { start: 1081, end: 1087 }, }, type: { kind: 'NonNullType', @@ -804,24 +814,24 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 1063, end: 1065 }, + loc: { start: 1089, end: 1091 }, }, - loc: { start: 1063, end: 1065 }, + loc: { start: 1089, end: 1091 }, }, - loc: { start: 1063, end: 1066 }, + loc: { start: 1089, end: 1092 }, }, directives: [], - loc: { start: 1055, end: 1066 }, + loc: { start: 1081, end: 1092 }, }, ], - loc: { start: 1020, end: 1068 }, + loc: { start: 1046, end: 1094 }, }, { kind: 'ObjectTypeDefinition', name: { kind: 'Name', value: 'TopicsCreatedByUserResult', - loc: { start: 1075, end: 1100 }, + loc: { start: 1101, end: 1126 }, }, interfaces: [], directives: [], @@ -831,7 +841,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'result', - loc: { start: 1105, end: 1111 }, + loc: { start: 1131, end: 1137 }, }, arguments: [], type: { @@ -845,28 +855,28 @@ export const typeDefs = { name: { kind: 'Name', value: 'Topic', - loc: { start: 1114, end: 1119 }, + loc: { start: 1140, end: 1145 }, }, - loc: { start: 1114, end: 1119 }, + loc: { start: 1140, end: 1145 }, }, - loc: { start: 1114, end: 1120 }, + loc: { start: 1140, end: 1146 }, }, - loc: { start: 1113, end: 1121 }, + loc: { start: 1139, end: 1147 }, }, - loc: { start: 1113, end: 1122 }, + loc: { start: 1139, end: 1148 }, }, directives: [], - loc: { start: 1105, end: 1122 }, + loc: { start: 1131, end: 1148 }, }, ], - loc: { start: 1070, end: 1124 }, + loc: { start: 1096, end: 1150 }, }, { kind: 'UnionTypeDefinition', name: { kind: 'Name', value: 'TopicsCreatedByUserPayload', - loc: { start: 1132, end: 1158 }, + loc: { start: 1158, end: 1184 }, }, directives: [], types: [ @@ -875,28 +885,28 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicsCreatedByUserResult', - loc: { start: 1161, end: 1186 }, + loc: { start: 1187, end: 1212 }, }, - loc: { start: 1161, end: 1186 }, + loc: { start: 1187, end: 1212 }, }, { kind: 'NamedType', name: { kind: 'Name', value: 'PayloadError', - loc: { start: 1189, end: 1201 }, + loc: { start: 1215, end: 1227 }, }, - loc: { start: 1189, end: 1201 }, + loc: { start: 1215, end: 1227 }, }, ], - loc: { start: 1126, end: 1201 }, + loc: { start: 1152, end: 1227 }, }, { kind: 'InputObjectTypeDefinition', name: { kind: 'Name', value: 'TopicCreateInput', - loc: { start: 1209, end: 1225 }, + loc: { start: 1235, end: 1251 }, }, directives: [], fields: [ @@ -905,7 +915,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'name', - loc: { start: 1230, end: 1234 }, + loc: { start: 1256, end: 1260 }, }, type: { kind: 'NonNullType', @@ -914,39 +924,39 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1236, end: 1242 }, + loc: { start: 1262, end: 1268 }, }, - loc: { start: 1236, end: 1242 }, + loc: { start: 1262, end: 1268 }, }, - loc: { start: 1236, end: 1243 }, + loc: { start: 1262, end: 1269 }, }, directives: [], - loc: { start: 1230, end: 1243 }, + loc: { start: 1256, end: 1269 }, }, { kind: 'InputValueDefinition', - name: { kind: 'Name', value: 'url', loc: { start: 1246, end: 1249 } }, + name: { kind: 'Name', value: 'url', loc: { start: 1272, end: 1275 } }, type: { kind: 'NamedType', name: { kind: 'Name', value: 'String', - loc: { start: 1251, end: 1257 }, + loc: { start: 1277, end: 1283 }, }, - loc: { start: 1251, end: 1257 }, + loc: { start: 1277, end: 1283 }, }, directives: [], - loc: { start: 1246, end: 1257 }, + loc: { start: 1272, end: 1283 }, }, ], - loc: { start: 1203, end: 1259 }, + loc: { start: 1229, end: 1285 }, }, { kind: 'ObjectTypeDefinition', name: { kind: 'Name', value: 'TopicCreateResult', - loc: { start: 1266, end: 1283 }, + loc: { start: 1292, end: 1309 }, }, interfaces: [], directives: [], @@ -956,7 +966,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'result', - loc: { start: 1288, end: 1294 }, + loc: { start: 1314, end: 1320 }, }, arguments: [], type: { @@ -966,24 +976,24 @@ export const typeDefs = { name: { kind: 'Name', value: 'Topic', - loc: { start: 1296, end: 1301 }, + loc: { start: 1322, end: 1327 }, }, - loc: { start: 1296, end: 1301 }, + loc: { start: 1322, end: 1327 }, }, - loc: { start: 1296, end: 1302 }, + loc: { start: 1322, end: 1328 }, }, directives: [], - loc: { start: 1288, end: 1302 }, + loc: { start: 1314, end: 1328 }, }, ], - loc: { start: 1261, end: 1304 }, + loc: { start: 1287, end: 1330 }, }, { kind: 'UnionTypeDefinition', name: { kind: 'Name', value: 'TopicCreatePayload', - loc: { start: 1312, end: 1330 }, + loc: { start: 1338, end: 1356 }, }, directives: [], types: [ @@ -992,34 +1002,34 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicCreateResult', - loc: { start: 1333, end: 1350 }, + loc: { start: 1359, end: 1376 }, }, - loc: { start: 1333, end: 1350 }, + loc: { start: 1359, end: 1376 }, }, { kind: 'NamedType', name: { kind: 'Name', value: 'PayloadError', - loc: { start: 1353, end: 1365 }, + loc: { start: 1379, end: 1391 }, }, - loc: { start: 1353, end: 1365 }, + loc: { start: 1379, end: 1391 }, }, ], - loc: { start: 1306, end: 1365 }, + loc: { start: 1332, end: 1391 }, }, { kind: 'InputObjectTypeDefinition', name: { kind: 'Name', value: 'TopicEditInput', - loc: { start: 1373, end: 1387 }, + loc: { start: 1399, end: 1413 }, }, directives: [], fields: [ { kind: 'InputValueDefinition', - name: { kind: 'Name', value: 'id', loc: { start: 1392, end: 1394 } }, + name: { kind: 'Name', value: 'id', loc: { start: 1418, end: 1420 } }, type: { kind: 'NonNullType', type: { @@ -1027,21 +1037,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 1396, end: 1398 }, + loc: { start: 1422, end: 1424 }, }, - loc: { start: 1396, end: 1398 }, + loc: { start: 1422, end: 1424 }, }, - loc: { start: 1396, end: 1399 }, + loc: { start: 1422, end: 1425 }, }, directives: [], - loc: { start: 1392, end: 1399 }, + loc: { start: 1418, end: 1425 }, }, { kind: 'InputValueDefinition', name: { kind: 'Name', value: 'name', - loc: { start: 1402, end: 1406 }, + loc: { start: 1428, end: 1432 }, }, type: { kind: 'NonNullType', @@ -1050,39 +1060,39 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1408, end: 1414 }, + loc: { start: 1434, end: 1440 }, }, - loc: { start: 1408, end: 1414 }, + loc: { start: 1434, end: 1440 }, }, - loc: { start: 1408, end: 1415 }, + loc: { start: 1434, end: 1441 }, }, directives: [], - loc: { start: 1402, end: 1415 }, + loc: { start: 1428, end: 1441 }, }, { kind: 'InputValueDefinition', - name: { kind: 'Name', value: 'url', loc: { start: 1418, end: 1421 } }, + name: { kind: 'Name', value: 'url', loc: { start: 1444, end: 1447 } }, type: { kind: 'NamedType', name: { kind: 'Name', value: 'String', - loc: { start: 1423, end: 1429 }, + loc: { start: 1449, end: 1455 }, }, - loc: { start: 1423, end: 1429 }, + loc: { start: 1449, end: 1455 }, }, directives: [], - loc: { start: 1418, end: 1429 }, + loc: { start: 1444, end: 1455 }, }, ], - loc: { start: 1367, end: 1431 }, + loc: { start: 1393, end: 1457 }, }, { kind: 'ObjectTypeDefinition', name: { kind: 'Name', value: 'TopicEditResult', - loc: { start: 1438, end: 1453 }, + loc: { start: 1464, end: 1479 }, }, interfaces: [], directives: [], @@ -1092,7 +1102,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'result', - loc: { start: 1458, end: 1464 }, + loc: { start: 1484, end: 1490 }, }, arguments: [], type: { @@ -1102,24 +1112,24 @@ export const typeDefs = { name: { kind: 'Name', value: 'Topic', - loc: { start: 1466, end: 1471 }, + loc: { start: 1492, end: 1497 }, }, - loc: { start: 1466, end: 1471 }, + loc: { start: 1492, end: 1497 }, }, - loc: { start: 1466, end: 1472 }, + loc: { start: 1492, end: 1498 }, }, directives: [], - loc: { start: 1458, end: 1472 }, + loc: { start: 1484, end: 1498 }, }, ], - loc: { start: 1433, end: 1474 }, + loc: { start: 1459, end: 1500 }, }, { kind: 'UnionTypeDefinition', name: { kind: 'Name', value: 'TopicEditPayload', - loc: { start: 1482, end: 1498 }, + loc: { start: 1508, end: 1524 }, }, directives: [], types: [ @@ -1128,28 +1138,28 @@ export const typeDefs = { name: { kind: 'Name', value: 'TopicEditResult', - loc: { start: 1501, end: 1516 }, + loc: { start: 1527, end: 1542 }, }, - loc: { start: 1501, end: 1516 }, + loc: { start: 1527, end: 1542 }, }, { kind: 'NamedType', name: { kind: 'Name', value: 'PayloadError', - loc: { start: 1519, end: 1531 }, + loc: { start: 1545, end: 1557 }, }, - loc: { start: 1519, end: 1531 }, + loc: { start: 1545, end: 1557 }, }, ], - loc: { start: 1476, end: 1531 }, + loc: { start: 1502, end: 1557 }, }, { kind: 'ObjectTypeExtension', name: { kind: 'Name', value: 'Subscription', - loc: { start: 1544, end: 1556 }, + loc: { start: 1570, end: 1582 }, }, interfaces: [], directives: [], @@ -1159,7 +1169,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'profileChanges', - loc: { start: 1561, end: 1575 }, + loc: { start: 1587, end: 1601 }, }, arguments: [], type: { @@ -1169,27 +1179,27 @@ export const typeDefs = { name: { kind: 'Name', value: 'Profile', - loc: { start: 1577, end: 1584 }, + loc: { start: 1603, end: 1610 }, }, - loc: { start: 1577, end: 1584 }, + loc: { start: 1603, end: 1610 }, }, - loc: { start: 1577, end: 1585 }, + loc: { start: 1603, end: 1611 }, }, directives: [], - loc: { start: 1561, end: 1585 }, + loc: { start: 1587, end: 1611 }, }, ], - loc: { start: 1532, end: 1587 }, + loc: { start: 1558, end: 1613 }, }, { kind: 'ObjectTypeDefinition', - name: { kind: 'Name', value: 'Profile', loc: { start: 1594, end: 1601 } }, + name: { kind: 'Name', value: 'Profile', loc: { start: 1620, end: 1627 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'id', loc: { start: 1606, end: 1608 } }, + name: { kind: 'Name', value: 'id', loc: { start: 1632, end: 1634 } }, arguments: [], type: { kind: 'NonNullType', @@ -1198,21 +1208,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 1610, end: 1612 }, + loc: { start: 1636, end: 1638 }, }, - loc: { start: 1610, end: 1612 }, + loc: { start: 1636, end: 1638 }, }, - loc: { start: 1610, end: 1613 }, + loc: { start: 1636, end: 1639 }, }, directives: [], - loc: { start: 1606, end: 1613 }, + loc: { start: 1632, end: 1639 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'user', - loc: { start: 1616, end: 1620 }, + loc: { start: 1642, end: 1646 }, }, arguments: [], type: { @@ -1222,27 +1232,27 @@ export const typeDefs = { name: { kind: 'Name', value: 'User', - loc: { start: 1622, end: 1626 }, + loc: { start: 1648, end: 1652 }, }, - loc: { start: 1622, end: 1626 }, + loc: { start: 1648, end: 1652 }, }, - loc: { start: 1622, end: 1627 }, + loc: { start: 1648, end: 1653 }, }, directives: [], - loc: { start: 1616, end: 1627 }, + loc: { start: 1642, end: 1653 }, }, ], - loc: { start: 1589, end: 1629 }, + loc: { start: 1615, end: 1655 }, }, { kind: 'ObjectTypeExtension', - name: { kind: 'Name', value: 'Query', loc: { start: 1642, end: 1647 } }, + name: { kind: 'Name', value: 'Query', loc: { start: 1668, end: 1673 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'me', loc: { start: 1652, end: 1654 } }, + name: { kind: 'Name', value: 'me', loc: { start: 1678, end: 1680 } }, arguments: [], type: { kind: 'NonNullType', @@ -1251,21 +1261,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'UserPayload', - loc: { start: 1656, end: 1667 }, + loc: { start: 1682, end: 1693 }, }, - loc: { start: 1656, end: 1667 }, + loc: { start: 1682, end: 1693 }, }, - loc: { start: 1656, end: 1668 }, + loc: { start: 1682, end: 1694 }, }, directives: [], - loc: { start: 1652, end: 1668 }, + loc: { start: 1678, end: 1694 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'userByAccountName', - loc: { start: 1671, end: 1688 }, + loc: { start: 1697, end: 1714 }, }, arguments: [ { @@ -1273,7 +1283,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'accountName', - loc: { start: 1689, end: 1700 }, + loc: { start: 1715, end: 1726 }, }, type: { kind: 'NonNullType', @@ -1282,14 +1292,14 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1702, end: 1708 }, + loc: { start: 1728, end: 1734 }, }, - loc: { start: 1702, end: 1708 }, + loc: { start: 1728, end: 1734 }, }, - loc: { start: 1702, end: 1709 }, + loc: { start: 1728, end: 1735 }, }, directives: [], - loc: { start: 1689, end: 1709 }, + loc: { start: 1715, end: 1735 }, }, ], type: { @@ -1299,27 +1309,27 @@ export const typeDefs = { name: { kind: 'Name', value: 'UserPayload', - loc: { start: 1712, end: 1723 }, + loc: { start: 1738, end: 1749 }, }, - loc: { start: 1712, end: 1723 }, + loc: { start: 1738, end: 1749 }, }, - loc: { start: 1712, end: 1724 }, + loc: { start: 1738, end: 1750 }, }, directives: [], - loc: { start: 1671, end: 1724 }, + loc: { start: 1697, end: 1750 }, }, ], - loc: { start: 1630, end: 1726 }, + loc: { start: 1656, end: 1752 }, }, { kind: 'ObjectTypeDefinition', - name: { kind: 'Name', value: 'User', loc: { start: 1733, end: 1737 } }, + name: { kind: 'Name', value: 'User', loc: { start: 1759, end: 1763 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'id', loc: { start: 1742, end: 1744 } }, + name: { kind: 'Name', value: 'id', loc: { start: 1768, end: 1770 } }, arguments: [], type: { kind: 'NonNullType', @@ -1328,21 +1338,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 1746, end: 1748 }, + loc: { start: 1772, end: 1774 }, }, - loc: { start: 1746, end: 1748 }, + loc: { start: 1772, end: 1774 }, }, - loc: { start: 1746, end: 1749 }, + loc: { start: 1772, end: 1775 }, }, directives: [], - loc: { start: 1742, end: 1749 }, + loc: { start: 1768, end: 1775 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'name', - loc: { start: 1752, end: 1756 }, + loc: { start: 1778, end: 1782 }, }, arguments: [], type: { @@ -1350,19 +1360,19 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1758, end: 1764 }, + loc: { start: 1784, end: 1790 }, }, - loc: { start: 1758, end: 1764 }, + loc: { start: 1784, end: 1790 }, }, directives: [], - loc: { start: 1752, end: 1764 }, + loc: { start: 1778, end: 1790 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'accountName', - loc: { start: 1767, end: 1778 }, + loc: { start: 1793, end: 1804 }, }, arguments: [], type: { @@ -1372,21 +1382,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1780, end: 1786 }, + loc: { start: 1806, end: 1812 }, }, - loc: { start: 1780, end: 1786 }, + loc: { start: 1806, end: 1812 }, }, - loc: { start: 1780, end: 1787 }, + loc: { start: 1806, end: 1813 }, }, directives: [], - loc: { start: 1767, end: 1787 }, + loc: { start: 1793, end: 1813 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'accountWebsite', - loc: { start: 1790, end: 1804 }, + loc: { start: 1816, end: 1830 }, }, arguments: [], type: { @@ -1394,19 +1404,19 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1806, end: 1812 }, + loc: { start: 1832, end: 1838 }, }, - loc: { start: 1806, end: 1812 }, + loc: { start: 1832, end: 1838 }, }, directives: [], - loc: { start: 1790, end: 1812 }, + loc: { start: 1816, end: 1838 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'accountTwitter', - loc: { start: 1815, end: 1829 }, + loc: { start: 1841, end: 1855 }, }, arguments: [], type: { @@ -1414,19 +1424,19 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1831, end: 1837 }, + loc: { start: 1857, end: 1863 }, }, - loc: { start: 1831, end: 1837 }, + loc: { start: 1857, end: 1863 }, }, directives: [], - loc: { start: 1815, end: 1837 }, + loc: { start: 1841, end: 1863 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'accountGitHub', - loc: { start: 1840, end: 1853 }, + loc: { start: 1866, end: 1879 }, }, arguments: [], type: { @@ -1434,19 +1444,19 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1855, end: 1861 }, + loc: { start: 1881, end: 1887 }, }, - loc: { start: 1855, end: 1861 }, + loc: { start: 1881, end: 1887 }, }, directives: [], - loc: { start: 1840, end: 1861 }, + loc: { start: 1866, end: 1887 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'accountLinkedIn', - loc: { start: 1864, end: 1879 }, + loc: { start: 1890, end: 1905 }, }, arguments: [], type: { @@ -1454,19 +1464,19 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1881, end: 1887 }, + loc: { start: 1907, end: 1913 }, }, - loc: { start: 1881, end: 1887 }, + loc: { start: 1907, end: 1913 }, }, directives: [], - loc: { start: 1864, end: 1887 }, + loc: { start: 1890, end: 1913 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'avatar', - loc: { start: 1890, end: 1896 }, + loc: { start: 1916, end: 1922 }, }, arguments: [], type: { @@ -1474,22 +1484,22 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 1898, end: 1904 }, + loc: { start: 1924, end: 1930 }, }, - loc: { start: 1898, end: 1904 }, + loc: { start: 1924, end: 1930 }, }, directives: [], - loc: { start: 1890, end: 1904 }, + loc: { start: 1916, end: 1930 }, }, ], - loc: { start: 1728, end: 1906 }, + loc: { start: 1754, end: 1932 }, }, { kind: 'ObjectTypeDefinition', name: { kind: 'Name', value: 'UserResult', - loc: { start: 1913, end: 1923 }, + loc: { start: 1939, end: 1949 }, }, interfaces: [], directives: [], @@ -1499,7 +1509,7 @@ export const typeDefs = { name: { kind: 'Name', value: 'result', - loc: { start: 1928, end: 1934 }, + loc: { start: 1954, end: 1960 }, }, arguments: [], type: { @@ -1507,22 +1517,22 @@ export const typeDefs = { name: { kind: 'Name', value: 'User', - loc: { start: 1936, end: 1940 }, + loc: { start: 1962, end: 1966 }, }, - loc: { start: 1936, end: 1940 }, + loc: { start: 1962, end: 1966 }, }, directives: [], - loc: { start: 1928, end: 1940 }, + loc: { start: 1954, end: 1966 }, }, ], - loc: { start: 1908, end: 1942 }, + loc: { start: 1934, end: 1968 }, }, { kind: 'UnionTypeDefinition', name: { kind: 'Name', value: 'UserPayload', - loc: { start: 1950, end: 1961 }, + loc: { start: 1976, end: 1987 }, }, directives: [], types: [ @@ -1531,31 +1541,31 @@ export const typeDefs = { name: { kind: 'Name', value: 'UserResult', - loc: { start: 1964, end: 1974 }, + loc: { start: 1990, end: 2000 }, }, - loc: { start: 1964, end: 1974 }, + loc: { start: 1990, end: 2000 }, }, { kind: 'NamedType', name: { kind: 'Name', value: 'PayloadError', - loc: { start: 1977, end: 1989 }, + loc: { start: 2003, end: 2015 }, }, - loc: { start: 1977, end: 1989 }, + loc: { start: 2003, end: 2015 }, }, ], - loc: { start: 1944, end: 1989 }, + loc: { start: 1970, end: 2015 }, }, { kind: 'ObjectTypeDefinition', - name: { kind: 'Name', value: 'Zoo', loc: { start: 1995, end: 1998 } }, + name: { kind: 'Name', value: 'Zoo', loc: { start: 2021, end: 2024 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'id', loc: { start: 2003, end: 2005 } }, + name: { kind: 'Name', value: 'id', loc: { start: 2029, end: 2031 } }, arguments: [], type: { kind: 'NonNullType', @@ -1564,21 +1574,21 @@ export const typeDefs = { name: { kind: 'Name', value: 'ID', - loc: { start: 2007, end: 2009 }, + loc: { start: 2033, end: 2035 }, }, - loc: { start: 2007, end: 2009 }, + loc: { start: 2033, end: 2035 }, }, - loc: { start: 2007, end: 2010 }, + loc: { start: 2033, end: 2036 }, }, directives: [], - loc: { start: 2003, end: 2010 }, + loc: { start: 2029, end: 2036 }, }, { kind: 'FieldDefinition', name: { kind: 'Name', value: 'name', - loc: { start: 2013, end: 2017 }, + loc: { start: 2039, end: 2043 }, }, arguments: [], type: { @@ -1588,27 +1598,27 @@ export const typeDefs = { name: { kind: 'Name', value: 'String', - loc: { start: 2019, end: 2025 }, + loc: { start: 2045, end: 2051 }, }, - loc: { start: 2019, end: 2025 }, + loc: { start: 2045, end: 2051 }, }, - loc: { start: 2019, end: 2026 }, + loc: { start: 2045, end: 2052 }, }, directives: [], - loc: { start: 2013, end: 2026 }, + loc: { start: 2039, end: 2052 }, }, ], - loc: { start: 1990, end: 2028 }, + loc: { start: 2016, end: 2054 }, }, { kind: 'ObjectTypeExtension', - name: { kind: 'Name', value: 'Profile', loc: { start: 2042, end: 2049 } }, + name: { kind: 'Name', value: 'Profile', loc: { start: 2068, end: 2075 } }, interfaces: [], directives: [], fields: [ { kind: 'FieldDefinition', - name: { kind: 'Name', value: 'zoo', loc: { start: 2054, end: 2057 } }, + name: { kind: 'Name', value: 'zoo', loc: { start: 2080, end: 2083 } }, arguments: [], type: { kind: 'NonNullType', @@ -1617,18 +1627,18 @@ export const typeDefs = { name: { kind: 'Name', value: 'Zoo', - loc: { start: 2059, end: 2062 }, + loc: { start: 2085, end: 2088 }, }, - loc: { start: 2059, end: 2062 }, + loc: { start: 2085, end: 2088 }, }, - loc: { start: 2059, end: 2063 }, + loc: { start: 2085, end: 2089 }, }, directives: [], - loc: { start: 2054, end: 2063 }, + loc: { start: 2080, end: 2089 }, }, ], - loc: { start: 2030, end: 2065 }, + loc: { start: 2056, end: 2091 }, }, ], - loc: { start: 0, end: 2066 }, + loc: { start: 0, end: 2092 }, } as unknown as DocumentNode; diff --git a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/types.generated.ts b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/types.generated.ts index 6d1eb345..90a333a6 100644 --- a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/types.generated.ts +++ b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/types.generated.ts @@ -35,6 +35,7 @@ export type Scalars = { Boolean: { input: boolean; output: boolean }; Int: { input: number; output: number }; Float: { input: number; output: number }; + CustomLogicScalar: { input: any; output: any }; DateTime: { input: Date | string; output: Date | string }; SomeRandomScalar: { input: any; output: any }; }; @@ -339,6 +340,9 @@ export type ResolversInterfaceTypes<_RefType extends Record> = /** Mapping between all available schema types and the resolvers types */ export type ResolversTypes = { + CustomLogicScalar: ResolverTypeWrapper< + Scalars['CustomLogicScalar']['output'] + >; DateTime: ResolverTypeWrapper; Error: ResolverTypeWrapper['Error']>; ErrorType: ErrorType; @@ -397,6 +401,7 @@ export type ResolversTypes = { /** Mapping between all available schema types and the resolvers parents */ export type ResolversParentTypes = { + CustomLogicScalar: Scalars['CustomLogicScalar']['output']; DateTime: Scalars['DateTime']['output']; Error: ResolversInterfaceTypes['Error']; Mutation: {}; @@ -438,6 +443,11 @@ export type ResolversParentTypes = { Boolean: Scalars['Boolean']['output']; }; +export interface CustomLogicScalarScalarConfig + extends GraphQLScalarTypeConfig { + name: 'CustomLogicScalar'; +} + export interface DateTimeScalarConfig extends GraphQLScalarTypeConfig { name: 'DateTime'; @@ -698,6 +708,7 @@ export type ZooResolvers< }; export type Resolvers = { + CustomLogicScalar?: GraphQLScalarType; DateTime?: GraphQLScalarType; Error?: ErrorResolvers; Mutation?: MutationResolvers; diff --git a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/test-setup.js b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/test-setup.js index 4b1e55dc..5f5aba07 100644 --- a/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/test-setup.js +++ b/packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/test-setup.js @@ -9,6 +9,15 @@ try { 'packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/topic/resolvers/TopicCreateResult.ts', 'packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/pet/resolvers/User.ts', + // Existing Scalar file, must not re-import GraphQLScalarType + { + file: 'packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/base/resolvers/CustomLogicScalar.ts', + content: `import { DateResolver} from 'graphql-scalars' + DateResolver.description = undefined; + export const CustomLogicScalar = DateResolver; + `, + }, + // Files in blacklisted modules should not be filled or added to resolvers.generated.ts 'packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/user/resolvers/User.ts', @@ -19,10 +28,20 @@ try { 'packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/schema/topic/resolvers/RandomFile_ShouldHaveEmptyContent.ts', ]; - files.forEach((file) => { - const dir = path.dirname(file); + files.forEach((item) => { + let filename; + let content = ''; + + if (typeof item === 'string') { + filename = item; + } else { + filename = item.file; + content = item.content; + } + + const dir = path.dirname(filename); fs.mkdirSync(dir, { recursive: true }); - fs.writeFileSync(file, ''); + fs.writeFileSync(filename, content); }); } catch (err) { console.error(err); diff --git a/packages/typescript-resolver-files/src/generateResolverFiles/addResolverMainFiles.ts b/packages/typescript-resolver-files/src/generateResolverFiles/addResolverMainFiles.ts index cc537088..a0008cab 100644 --- a/packages/typescript-resolver-files/src/generateResolverFiles/addResolverMainFiles.ts +++ b/packages/typescript-resolver-files/src/generateResolverFiles/addResolverMainFiles.ts @@ -85,7 +85,9 @@ export const addResolverMainFiles = ({ // Non Root Object fields that was generated if ( file.__filetype === 'objectType' || - file.__filetype === 'generalResolver' + file.__filetype === 'interfaceResolver' || + file.__filetype === 'unionResolver' || + file.__filetype === 'scalarResolver' ) { res[resolverMainFilename].importLines.push( printImportLine({ diff --git a/packages/typescript-resolver-files/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.spec.ts b/packages/typescript-resolver-files/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.spec.ts index 7006f310..642928af 100644 --- a/packages/typescript-resolver-files/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.spec.ts +++ b/packages/typescript-resolver-files/src/generateResolverFiles/getImportStatementWithExpectedNamedImport.spec.ts @@ -76,7 +76,7 @@ describe('getImportStatementWithExpectedNamedImport', () => { ); }); - it('returns import statement if found for generalResolver files', () => { + it('returns import statement if found for interfaceResolver files', () => { const project = new Project(); const sourceFile = project.createSourceFile( '/pathto/User.ts', @@ -88,7 +88,7 @@ describe('getImportStatementWithExpectedNamedImport', () => { ); const result = getImportStatementWithExpectedNamedImport(sourceFile, { - __filetype: 'generalResolver', + __filetype: 'interfaceResolver', content: '', mainImportIdentifier: 'user', meta: { diff --git a/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLInterfaceType.ts b/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLInterfaceType.ts index b8e5c0be..2e115b1f 100644 --- a/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLInterfaceType.ts +++ b/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLInterfaceType.ts @@ -38,7 +38,7 @@ export const handleGraphQLInterfaceType: GraphQLTypeHandler = ( const variableStatement = `export const ${resolverName}: ${resolverTypeString} = { /* Implement ${resolverName} interface logic here */ };`; result.files[fieldFilePath] = { - __filetype: 'generalResolver', + __filetype: 'interfaceResolver', content: ` ${resolverTypeImportDeclaration} ${variableStatement}`, diff --git a/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts b/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts index 30b57182..491834df 100644 --- a/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts +++ b/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLScalarType.ts @@ -49,7 +49,7 @@ export const handleGraphQLScalarType: GraphQLTypeHandler = ( });`; result.files[fieldFilePath] = { - __filetype: 'generalResolver', + __filetype: 'scalarResolver', content: ` ${resolverTypeImportDeclaration} ${variableStatement}`, diff --git a/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUnionType.ts b/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUnionType.ts index e00da729..6e4820fb 100644 --- a/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUnionType.ts +++ b/packages/typescript-resolver-files/src/generateResolverFiles/handleGraphQLUnionType.ts @@ -36,7 +36,7 @@ export const handleGraphQLUnionType: GraphQLTypeHandler = ( const variableStatement = `export const ${resolverName}: ${resolversTypeMeta.typeString} = { /* Implement ${resolverName} union logic here */ };`; result.files[fieldFilePath] = { - __filetype: 'generalResolver', + __filetype: 'unionResolver', content: ` ${resolverTypeImportDeclaration} ${variableStatement}`, diff --git a/packages/typescript-resolver-files/src/generateResolverFiles/postProcessFiles.ts b/packages/typescript-resolver-files/src/generateResolverFiles/postProcessFiles.ts index 416ea4e2..d1b881dc 100644 --- a/packages/typescript-resolver-files/src/generateResolverFiles/postProcessFiles.ts +++ b/packages/typescript-resolver-files/src/generateResolverFiles/postProcessFiles.ts @@ -56,8 +56,20 @@ export const postProcessFiles = ({ sourceFile.getFilePath() ); - ensureImportedType(sourceFile, resolverFile); - ensureExportedResolver(sourceFile, resolverFile); + const { addedVariableStatement } = ensureExportedResolver( + sourceFile, + resolverFile + ); + + if ( + resolverFile.__filetype !== 'scalarResolver' || + // For scalarResolver, only add `import { GraphQLScalarType } ...` if variable statement was added. + // This is because user could have used custom scalar. If so, we don't want to add unnecessary import + (resolverFile.__filetype === 'scalarResolver' && addedVariableStatement) + ) { + ensureImportedType(sourceFile, resolverFile); + } + if ( fixObjectTypeResolvers === 'smart' && resolverFile.__filetype === 'objectType' @@ -79,13 +91,16 @@ export const postProcessFiles = ({ const ensureExportedResolver = ( sourceFile: SourceFile, resolverFile: ResolverFile -): void => { +): { addedVariableStatement: boolean } => { + const result = { addedVariableStatement: false }; + const { variableStatement, isExported } = getVariableStatementWithExpectedIdentifier(sourceFile, resolverFile); if (!variableStatement) { // Did not find variable statement with expected identifier, add it to the end with a warning sourceFile.addStatements(resolverFile.meta.variableStatement); + result.addedVariableStatement = true; } else if (variableStatement && !isExported) { // If has identifier but not exported // Add export keyword to statement @@ -99,6 +114,8 @@ const ensureExportedResolver = ( } // else, if identifier's been exported do nothing } + + return result; }; /** diff --git a/packages/typescript-resolver-files/src/generateResolverFiles/types.ts b/packages/typescript-resolver-files/src/generateResolverFiles/types.ts index b2b9a48b..6ca00094 100644 --- a/packages/typescript-resolver-files/src/generateResolverFiles/types.ts +++ b/packages/typescript-resolver-files/src/generateResolverFiles/types.ts @@ -16,8 +16,38 @@ export interface StandardFile extends BaseVirtualFile { __filetype: 'file'; } -export interface GeneralResolverFile extends BaseVirtualFile { - __filetype: 'generalResolver'; +export interface InterfacelResolverFile extends BaseVirtualFile { + __filetype: 'interfaceResolver'; + meta: { + moduleName: string; + relativePathFromBaseToModule: string[]; + resolverTypeImportDeclaration: string; + variableStatement: string; + resolverType: { + baseImport: string; // e.g. `NodeResolvers` + final: string; + }; + normalizedResolverName: NormalizedResolverName; + }; +} + +export interface UnionResolverFile extends BaseVirtualFile { + __filetype: 'unionResolver'; + meta: { + moduleName: string; + relativePathFromBaseToModule: string[]; + resolverTypeImportDeclaration: string; + variableStatement: string; + resolverType: { + baseImport: string; // e.g. `NodeResolvers` + final: string; + }; + normalizedResolverName: NormalizedResolverName; + }; +} + +export interface ScalarResolverFile extends BaseVirtualFile { + __filetype: 'scalarResolver'; meta: { moduleName: string; relativePathFromBaseToModule: string[]; @@ -65,9 +95,11 @@ export interface ObjectTypeFile extends BaseVirtualFile { } export type ResolverFile = - | GeneralResolverFile | RootObjectTypeFieldResolverFile - | ObjectTypeFile; + | ObjectTypeFile + | InterfacelResolverFile + | UnionResolverFile + | ScalarResolverFile; export interface GenerateResolverFilesContext { config: {