MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
8.03k stars 676 forks source link

fix(metadata): restore original metadata to enable repeated buildSchema executions #1691

Closed syonthomas closed 4 months ago

syonthomas commented 4 months ago

Overview

This PR addresses the issue described in #1321, where the function buildExtendedResolversMetadata alters instance properties, causing multiple calls to buildSchema to exhibit unexpected behavior.

Problem Statement

The primary problem is that buildExtendedResolversMetadata modifies the following instance properties of MetadataStorage:

This mutation leads to issues when buildSchema is called multiple times, such as missing arguments in subsequent schema builds, as noted in the original issue.

Solution

The proposed solution in this PR involves preserving the original state of MetadataStorage. On successive calls to buildSchema, the original instance of MetadataStorage is restored, ensuring that repeated schema builds do not encounter the unintended side effects of modified metadata.

Implementation Details

syonthomas commented 4 months ago

Further testing showed that this solution has a race condition and does not work for more than two buildSchema runs. I have another solution ready, but I will wait a couple of days to refresh the PR to see if this solution finally works.

MichalLytek commented 4 months ago

@syonthomas Actually I've managed to fix this last week in a more reasonable fashion. Created a PR now, which supersede this PR 🔒

https://github.com/MichalLytek/type-graphql/pull/1698