Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
- Formatting
- [ ] Abstract duplicated code
  • Loading branch information
eddeee888 committed Feb 26, 2023
1 parent 565f12c commit 4291915
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ export class BaseResolversVisitor<
const fieldsToOmit = this._federation
.filterFieldNames(Object.keys(fields))
.map(fieldName => {
// TODO: eddeee888 this is duplicated from createResolversFields. Abstract to reuse
const field = fields[fieldName];
const baseType = getBaseType(field.type);
const isMapped = this.config.mappers[baseType.name];
Expand Down
84 changes: 41 additions & 43 deletions packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1430,22 +1430,22 @@ export type ResolverFn<TResult, TParent, TContext, TArgs> = (
const content = await plugin(testSchema, [], {}, { outputFile: 'graphql.ts' });

expect(tsContent.content).toBeSimilarStringTo(`
export type CccFoo = {
__typename?: 'CCCFoo';
foo: Scalars['String'];
};
export type CccFoo = {
__typename?: 'CCCFoo';
foo: Scalars['String'];
};
`);
expect(tsContent.content).toBeSimilarStringTo(`
export type CccBar = {
__typename?: 'CCCBar';
bar: Scalars['String'];
};
export type CccBar = {
__typename?: 'CCCBar';
bar: Scalars['String'];
};
`);

expect(content.content).toBeSimilarStringTo(`
export type ResolversUnionTypes = {
CCCUnion: ( CccFoo ) | ( CccBar );
}
export type ResolversUnionTypes = {
CCCUnion: ( CccFoo ) | ( CccBar );
};
`);
expect(content.content).toBeSimilarStringTo(`
/** Mapping between all available schema types and the resolvers types */
Expand Down Expand Up @@ -1784,44 +1784,42 @@ export type ResolverFn<TResult, TParent, TContext, TArgs> = (
const content = await plugin(testSchema, [], {}, { outputFile: 'graphql.ts' });

expect(content.content).toBeSimilarStringTo(`
export type ResolversUnionTypes = {
UserPayload: ( UserResult ) | ( StandardError );
PostsPayload: ( PostsResult ) | ( StandardError );
};
export type ResolversUnionTypes = {
UserPayload: ( UserResult ) | ( StandardError );
PostsPayload: ( PostsResult ) | ( StandardError );
};
`);

expect(content.content).toBeSimilarStringTo(`
/** Mapping between all available schema types and the resolvers types */
export type ResolversTypes = {
Query: ResolverTypeWrapper<{}>;
ID: ResolverTypeWrapper<Scalars['ID']>;
StandardError: ResolverTypeWrapper<StandardError>;
String: ResolverTypeWrapper<Scalars['String']>;
User: ResolverTypeWrapper<User>;
UserResult: ResolverTypeWrapper<UserResult>;
UserPayload: ResolverTypeWrapper<ResolversUnionTypes['UserPayload']>;
Post: ResolverTypeWrapper<Post>;
PostsResult: ResolverTypeWrapper<PostsResult>;
PostsPayload: ResolverTypeWrapper<ResolversUnionTypes['PostsPayload']>;
Boolean: ResolverTypeWrapper<Scalars['Boolean']>;
};
export type ResolversTypes = {
Query: ResolverTypeWrapper<{}>;
ID: ResolverTypeWrapper<Scalars['ID']>;
StandardError: ResolverTypeWrapper<StandardError>;
String: ResolverTypeWrapper<Scalars['String']>;
User: ResolverTypeWrapper<User>;
UserResult: ResolverTypeWrapper<UserResult>;
UserPayload: ResolverTypeWrapper<ResolversUnionTypes['UserPayload']>;
Post: ResolverTypeWrapper<Post>;
PostsResult: ResolverTypeWrapper<PostsResult>;
PostsPayload: ResolverTypeWrapper<ResolversUnionTypes['PostsPayload']>;
Boolean: ResolverTypeWrapper<Scalars['Boolean']>;
};
`);

expect(content.content).toBeSimilarStringTo(`
/** Mapping between all available schema types and the resolvers parents */
export type ResolversParentTypes = {
Query: {};
ID: Scalars['ID'];
StandardError: StandardError;
String: Scalars['String'];
User: User;
UserResult: UserResult;
UserPayload: ResolversUnionTypes['UserPayload'];
Post: Post;
PostsResult: PostsResult;
PostsPayload: ResolversUnionTypes['PostsPayload'];
Boolean: Scalars['Boolean'];
};
export type ResolversParentTypes = {
Query: {};
ID: Scalars['ID'];
StandardError: StandardError;
String: Scalars['String'];
User: User;
UserResult: UserResult;
UserPayload: ResolversUnionTypes['UserPayload'];
Post: Post;
PostsResult: PostsResult;
PostsPayload: ResolversUnionTypes['PostsPayload'];
Boolean: Scalars['Boolean'];
};
`);
});

Expand Down

0 comments on commit 4291915

Please sign in to comment.