Skip to content

Commit

Permalink
Improve perf by avoid running preEmitDiagnostics per file (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 authored Nov 19, 2024
1 parent 4bf8ddf commit b4c501c
Show file tree
Hide file tree
Showing 28 changed files with 1,165 additions and 753 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-students-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eddeee888/gcg-typescript-resolver-files': patch
---

Update internals to use faster approach to run static analysis
8 changes: 5 additions & 3 deletions packages/typescript-resolver-files-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"rimraf -g \"packages/typescript-resolver-files-e2e/src/**/rslvrs/\"",
"rimraf -g \"packages/typescript-resolver-files-e2e/src/**/*.generated.*\"",
"rimraf -g \"packages/typescript-resolver-files-e2e/src/**/*.gen.*\"",
"node packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/test-setup.js"
"node packages/typescript-resolver-files-e2e/src/test-mappers-vs-schema-types/testSetup.js",
"node packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/testSetup.js"
],
"parallel": false
},
Expand Down Expand Up @@ -74,7 +75,8 @@
"test-mappers-vs-schema-types": {
"commands": [
"rimraf -g \"packages/typescript-resolver-files-e2e/src/test-mappers-vs-schema-types/**/resolvers/\"",
"rimraf -g \"packages/typescript-resolver-files-e2e/src/test-mappers-vs-schema-types/**/*.generated.*\""
"rimraf -g \"packages/typescript-resolver-files-e2e/src/test-mappers-vs-schema-types/**/*.generated.*\"",
"node packages/typescript-resolver-files-e2e/src/test-mappers-vs-schema-types/testSetup.js"
],
"parallel": false
},
Expand Down Expand Up @@ -138,7 +140,7 @@
"commands": [
"rimraf -g \"packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/**/resolvers/\"",
"rimraf -g \"packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/**/*.generated.*\"",
"node packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/test-setup.js"
"node packages/typescript-resolver-files-e2e/src/test-resolvers-auto-wireup/testSetup.js"
],
"parallel": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ type Topic {
createdAt: DateTime!
creator: User!
id: ID!
likedBy: [User!]!
likedByNullable: [User]
mostRelatedTopic: Topic
name: String!
relatedTopics: [Topic!]!
url: String
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import type { TopicResolvers } from './../../types.generated';
export const Topic: TopicResolvers = {
/* Implement Topic resolver logic here */
id: ({ id }) => id,
createdAt: async (_parent, _arg, _ctx) => {
/* existing implementation, must keep */
return '2024-01-01T00:00:00.000Z';
},
creator: ({ creator }, _arg, _ctx) => {
/* Topic.creator resolver is required because Topic.creator and TopicMapper.creator are not compatible */
return creator;
},
name: async (_parent, _arg, _ctx) => {
/* Topic.name resolver is required because Topic.name exists but TopicMapper.name does not */
},
url: async (_parent, _arg, _ctx) => {
/* Topic.url resolver is required because Topic.url exists but TopicMapper.url does not */
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ extend type Mutation {

type Topic {
id: ID!
createdAt: DateTime!
creator: User!
likedBy: [User!]!
likedByNullable: [User]
mostRelatedTopic: Topic
name: String!
relatedTopics: [Topic!]!
url: String
creator: User!
createdAt: DateTime!
}

type TopicByIdResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { UserMapper } from '../user/user.graphqls.mappers';

export type TopicMapper = {
id: string;
creator: string;
mostRelatedTopic?: TopicMapper;
relatedTopics: TopicMapper[];
likedBy: UserMapper[];
likedByNullable: null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -388,47 +388,102 @@ export const typeDefs = {
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'name' },
name: { kind: 'Name', value: 'createdAt' },
arguments: [],
type: {
kind: 'NonNullType',
type: {
kind: 'NamedType',
name: { kind: 'Name', value: 'String' },
name: { kind: 'Name', value: 'DateTime' },
},
},
directives: [],
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'url' },
name: { kind: 'Name', value: 'creator' },
arguments: [],
type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } },
type: {
kind: 'NonNullType',
type: { kind: 'NamedType', name: { kind: 'Name', value: 'User' } },
},
directives: [],
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'creator' },
name: { kind: 'Name', value: 'likedBy' },
arguments: [],
type: {
kind: 'NonNullType',
type: {
kind: 'ListType',
type: {
kind: 'NonNullType',
type: {
kind: 'NamedType',
name: { kind: 'Name', value: 'User' },
},
},
},
},
directives: [],
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'likedByNullable' },
arguments: [],
type: {
kind: 'ListType',
type: { kind: 'NamedType', name: { kind: 'Name', value: 'User' } },
},
directives: [],
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'createdAt' },
name: { kind: 'Name', value: 'mostRelatedTopic' },
arguments: [],
type: { kind: 'NamedType', name: { kind: 'Name', value: 'Topic' } },
directives: [],
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'name' },
arguments: [],
type: {
kind: 'NonNullType',
type: {
kind: 'NamedType',
name: { kind: 'Name', value: 'DateTime' },
name: { kind: 'Name', value: 'String' },
},
},
directives: [],
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'relatedTopics' },
arguments: [],
type: {
kind: 'NonNullType',
type: {
kind: 'ListType',
type: {
kind: 'NonNullType',
type: {
kind: 'NamedType',
name: { kind: 'Name', value: 'Topic' },
},
},
},
},
directives: [],
},
{
kind: 'FieldDefinition',
name: { kind: 'Name', value: 'url' },
arguments: [],
type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } },
directives: [],
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ProfileMetaMapper,
} from './user/profile.mappers';
import { CatMapper, DogMapper } from './pet/schema.mappers';
import { TopicMapper } from './topic/topic.mappers';
import { UserMapper } from './user/user.graphqls.mappers';
export type Maybe<T> = T | null | undefined;
export type InputMaybe<T> = T | null | undefined;
Expand Down Expand Up @@ -145,7 +146,11 @@ export type Topic = {
createdAt: Scalars['DateTime']['output'];
creator: User;
id: Scalars['ID']['output'];
likedBy: Array<User>;
likedByNullable?: Maybe<Array<Maybe<User>>>;
mostRelatedTopic?: Maybe<Topic>;
name: Scalars['String']['output'];
relatedTopics: Array<Topic>;
url?: Maybe<Scalars['String']['output']>;
};

Expand Down Expand Up @@ -371,9 +376,7 @@ export type ResolversTypes = {
ProfileMeta: ResolverTypeWrapper<ProfileMetaMapper>;
Query: ResolverTypeWrapper<{}>;
Subscription: ResolverTypeWrapper<{}>;
Topic: ResolverTypeWrapper<
Omit<Topic, 'creator'> & { creator: ResolversTypes['User'] }
>;
Topic: ResolverTypeWrapper<TopicMapper>;
TopicByIdPayload: ResolverTypeWrapper<
ResolversUnionTypes<ResolversTypes>['TopicByIdPayload']
>;
Expand Down Expand Up @@ -433,7 +436,7 @@ export type ResolversParentTypes = {
ProfileMeta: ProfileMetaMapper;
Query: {};
Subscription: {};
Topic: Omit<Topic, 'creator'> & { creator: ResolversParentTypes['User'] };
Topic: TopicMapper;
TopicByIdPayload: ResolversUnionTypes<ResolversParentTypes>['TopicByIdPayload'];
TopicByIdResult: Omit<TopicByIdResult, 'result'> & {
result?: Maybe<ResolversParentTypes['Topic']>;
Expand Down Expand Up @@ -605,7 +608,23 @@ export type TopicResolvers<
createdAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
creator?: Resolver<ResolversTypes['User'], ParentType, ContextType>;
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
likedBy?: Resolver<Array<ResolversTypes['User']>, ParentType, ContextType>;
likedByNullable?: Resolver<
Maybe<Array<Maybe<ResolversTypes['User']>>>,
ParentType,
ContextType
>;
mostRelatedTopic?: Resolver<
Maybe<ResolversTypes['Topic']>,
ParentType,
ContextType
>;
name?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
relatedTopics?: Resolver<
Array<ResolversTypes['Topic']>,
ParentType,
ContextType
>;
url?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { createTestSetup } = require('../utils/createTestSetup');

createTestSetup({
baseDir:
'packages/typescript-resolver-files-e2e/src/test-mappers-vs-schema-types/',
files: [
{
file: 'modules/topic/resolvers/Topic.ts',
content: `import type { TopicResolvers } from './../../types.generated';
export const Topic: TopicResolvers = {
id: ({ id }) => id,
createdAt: async (_parent, _arg, _ctx) => {
/* existing implementation, must keep */
return '2024-01-01T00:00:00.000Z';
},
};`,
},
],
});
Loading

0 comments on commit b4c501c

Please sign in to comment.