Skip to content

Commit

Permalink
Add test to reproduce the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed May 22, 2024
1 parent 3a31dbe commit 27a81a2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/functional/generic-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ describe("Generic types", () => {
let schema: GraphQLSchema;
let schemaIntrospection: IntrospectionSchema;

beforeAll(async () => {
beforeEach(async () => {
function Base<TType extends object>(TTypeClass: ClassType<TType>) {
@ObjectType()
class BaseClass {
Expand Down
51 changes: 51 additions & 0 deletions tests/functional/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2545,4 +2545,55 @@ describe("Resolvers", () => {
expect(dynamicField2).toBeDefined();
});
});

describe("Shared generic resolver", () => {
beforeEach(async () => {
getMetadataStorage().clear();
});

it("should handle arguments correctly on multiple buildSchema runs", async () => {
@ObjectType()
class TestResponse {
@Field()
data!: string;
}

@ArgsType()
class TestArgs {
@Field(() => Int, { defaultValue: 0 })
testField!: number;
}

function makeResolverClass() {
@Resolver(() => TestResponse)
abstract class TestResolver {
@Query(() => TestResponse)
async exampleQuery(@Args() args: TestArgs): Promise<TestResponse> {
return {
data: `resolver ${args.testField}`,
};
}
}

return TestResolver;
}

@Resolver()
class TestResolver extends makeResolverClass() {}

const fistSchemaInfo = await getSchemaInfo({
resolvers: [TestResolver],
});

expect(fistSchemaInfo.queryType.fields).toHaveLength(1);
expect(fistSchemaInfo.queryType.fields[0].args).toHaveLength(1);

const secondSchemaInfo = await getSchemaInfo({
resolvers: [TestResolver],
});

expect(secondSchemaInfo.queryType.fields).toHaveLength(1);
expect(secondSchemaInfo.queryType.fields[0].args).toHaveLength(1);
});
});
});

0 comments on commit 27a81a2

Please sign in to comment.