Repository: MichalLytek/type-graphql
Pull request #1597 (2024-01-03 15:47:15)

fix:(ci): workflows that depends on another workflow
- Fixed workflows that depends on another workflow
- `actions/checkout` always clone the corresponding `ref` to avoid clashes with `master`
- Cancel parallel workflows (`concurrency`) if the corresponding workflow must be run uniquely (e.g. `release` and `license`)

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/MichalLytek/type-graphql/pull/1597?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Micha%C5%82+Lytek) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`e28a028`)](https://app.codecov.io/gh/MichalLytek/type-graphql/commit/e28a028e557ea8717f0b31db55bf6cbf958bb474?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Micha%C5%82+Lytek) 95.50% compared to head [(`d31bfde`)](https://app.codecov.io/gh/MichalLytek/type-graphql/pull/1597?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Micha%C5%82+Lytek) 95.50%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master    #1597   +/-   ##
=======================================
  Coverage   95.50%   95.50%           
=======================================
  Files         113      113           
  Lines        1848     1848           
  Branches      364      364           
=======================================
  Hits         1765     1765           
  Misses         83       83           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/MichalLytek/type-graphql/pull/1597?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Micha%C5%82+Lytek).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Micha%C5%82+Lytek).

carlocorradini: Lol CodeQL fails.
I'll update all workflows following the recommendations from https://github.blog/2023-08-09-four-tips-to-keep-your-github-actions-workflows-secure/
carlocorradini: @MichalLytek Done 🛡

Patch:
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index 8b04dc0e..866d376b 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -26,8 +26,10 @@ jobs:
           fetch-depth: 0
 
       - name: Check Git tag format
+        env:
+          TYPE_GRAPHQL_REF_NAME: ${{ github.ref_name }}
         run: |
-          _tag="${{ github.ref_name }}"
+          _tag="$TYPE_GRAPHQL_REF_NAME"
           if ! printf "%s\n" "$_tag" | grep -q -P '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.(0|[1-9][0-9]*))?$'; then
             printf '[ERROR]: Git tag (%s) wrong format\n' "$_tag"
             exit 1
@@ -49,14 +51,18 @@ jobs:
 
       - name: Remove leading v* from GitHub version
         id: version_github
+        env:
+          TYPE_GRAPHQL_VERSION: ${{ steps.version_v_github.outputs.release }}
         run: |
-          _version="${{ steps.version_v_github.outputs.release }}"
+          _version="$TYPE_GRAPHQL_VERSION"
           printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT"
 
       - name: Read Git tag version
         id: version_gittag
+        env:
+          TYPE_GRAPHQL_REF_NAME: ${{ github.ref_name }}
         run: |
-          _version="${{ github.ref_name }}"
+          _version="$TYPE_GRAPHQL_REF_NAME"
           printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT"
 
       - name: Compare package.json with Git tag
@@ -76,16 +82,24 @@ jobs:
           lenient: false
 
       - name: Check package.json == Git tag
+        env:
+          TYPE_GRAPHQL_COMPARISON: ${{ steps.comparison_package_gittag.outputs.comparison-result }}
+          TYPE_GRAPHQL_VERSION_PACKAGE: ${{ steps.version_package.outputs.value }}
+          TYPE_GRAPHQL_VERSION_TAG: ${{ steps.version_gittag.outputs.value }}
         run: |
-          if [ ! "${{ steps.comparison_package_gittag.outputs.comparison-result }}" = "=" ]; then
-            printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "${{ steps.version_package.outputs.value }}" "${{ steps.version_gittag.outputs.value }}"
+          if [ ! "$TYPE_GRAPHQL_COMPARISON" = "=" ]; then
+            printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "$TYPE_GRAPHQL_VERSION_PACKAGE" "$TYPE_GRAPHQL_VERSION_TAG"
             exit 1
           fi
 
       - name: Check Git tag > GitHub
+        env:
+          TYPE_GRAPHQL_COMPARISON: ${{ steps.comparison_gittag_github.outputs.comparison-result }}
+          TYPE_GRAPHQL_VERSION_TAG: ${{ steps.version_gittag.outputs.value }}
+          TYPE_GRAPHQL_VERSION_GITHUB: ${{ steps.version_github.outputs.value }}
         run: |
-          if [ ! "${{ steps.comparison_gittag_github.outputs.comparison-result }}" = ">" ]; then
-            printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "${{ steps.version_gittag.outputs.value }}" "${{ steps.version_github.outputs.value }}"
+          if [ ! "$TYPE_GRAPHQL_COMPARISON" = ">" ]; then
+            printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "$TYPE_GRAPHQL_VERSION_TAG" "$TYPE_GRAPHQL_VERSION_GITHUB"
             exit 1
           fi
 
diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml
index 37f9e840..ce153193 100644
--- a/.github/workflows/license.yml
+++ b/.github/workflows/license.yml
@@ -4,6 +4,10 @@ on:
   schedule:
     - cron: "0 0 1 1 *"
 
+concurrency:
+  group: ${{ github.workflow }}
+  cancel-in-progress: true
+
 jobs:
   license:
     runs-on: ubuntu-latest
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 615de0f4..eb39d40e 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -10,20 +10,22 @@ on:
       - master
 
 concurrency:
-  group: ${{ github.workflow }}-${{ github.ref }}
+  group: ${{ github.workflow }}
   cancel-in-progress: true
 
 jobs:
   release:
     name: Release package on NPM
     runs-on: ubuntu-latest
-    if: github.event.workflow_run.conclusion == 'success' && startsWith(github.ref_name, 'v')
+    if: github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'refs/tags/v')
     permissions:
       contents: write
       id-token: write
     steps:
       - name: Checkout
         uses: actions/checkout@v4
+        with:
+          ref: ${{ github.event.workflow_run.head_branch }}
 
       - name: Read package.json version
         uses: sergeysova/jq-action@v2
@@ -31,11 +33,32 @@ jobs:
         with:
           cmd: jq --raw-output .version package.json
 
+      - name: Read Git tag version
+        id: tag
+        env:
+          TYPE_GRAPHQL_REF: ${{ github.event.workflow_run.head_branch }}
+        run: |
+          _ref="$TYPE_GRAPHQL_REF"
+          printf 'value=%s\n' "${_ref#refs/tags/}" >> "$GITHUB_OUTPUT"
+
+      - name: Check package.json == Git tag
+        env:
+          TYPE_GRAPHQL_VERSION_PACKAGE: ${{ steps.version.outputs.value }}
+          TYPE_GRAPHQL_VERSION_TAG: ${{ steps.tag.outputs.value }}
+        run: |
+          _version="v$TYPE_GRAPHQL_VERSION_PACKAGE"
+          if [ ! "$_version" = "$TYPE_GRAPHQL_VERSION_TAG" ]; then
+            printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "$_version" "$TYPE_GRAPHQL_VERSION_TAG"
+            exit 1
+          fi
+
       - name: Determine if version is prerelease
         id: prerelease
+        env:
+          TYPE_GRAPHQL_VERSION: ${{ steps.version.outputs.value }}
         run: |
           _prerelease=
-          if printf "%s\n" "${{ steps.version.outputs.value }}" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then
+          if printf "%s\n" "$TYPE_GRAPHQL_VERSION" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then
             _prerelease=false
           else
             _prerelease=true
@@ -61,7 +84,7 @@ jobs:
         run: |
           npm run prepublishOnly
         env:
-          TYPE_GRAPHQL_REF: ${{ github.ref_name }}
+          TYPE_GRAPHQL_REF: ${{ steps.tag.outputs.value }}
 
       - name: Build Changelog
         id: changelog
@@ -79,14 +102,15 @@ jobs:
           prerelease: ${{ steps.prerelease.outputs.value == 'true' }}
 
       - name: Publish
+        env:
+          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+          TYPE_GRAPHQL_PRERELEASE: ${{ steps.prerelease.outputs.value }}
         run: |
           _tag=
-          if [ "${{ steps.prerelease.outputs.value }}" = "true" ]; then
+          if [ "$TYPE_GRAPHQL_PRERELEASE" = "true" ]; then
             _tag="next"
           else
             _tag="latest"
           fi
 
           npm publish --ignore-scripts --tag "$_tag"
-        env:
-          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml
index 90cb6b13..9988bad9 100644
--- a/.github/workflows/website.yml
+++ b/.github/workflows/website.yml
@@ -10,7 +10,7 @@ on:
       - master
 
 concurrency:
-  group: ${{ github.workflow }}-${{ github.ref }}
+  group: ${{ github.workflow }}
   cancel-in-progress: true
 
 jobs:
@@ -22,6 +22,7 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v4
         with:
+          ref: ${{ github.event.workflow_run.head_branch }}
           fetch-depth: 0
 
       - name: Setup Node.js
@@ -46,4 +47,4 @@ jobs:
           user_name: "github-actions[bot]"
           user_email: "github-actions[bot]@users.noreply.github.com"
           full_commit_message: |
-            Deploy website based on ${{ github.sha }}
+            Deploy website based on ${{ github.event.workflow_run.head_sha }}
diff --git a/src/metadata/metadata-storage.ts b/src/metadata/metadata-storage.ts
index 8715e714..da8afa4a 100644
--- a/src/metadata/metadata-storage.ts
+++ b/src/metadata/metadata-storage.ts
@@ -291,7 +291,9 @@ export class MetadataStorage {
           );
         }
 
-        const typeField = typeMetadata.fields!.find(fieldDef => fieldDef.name === def.methodName)!;
+        const typeField = typeMetadata.fields!.find(
+          fieldDef => fieldDef.schemaName === def.schemaName,
+        )!;
         if (!typeField) {
           const shouldCollectFieldMetadata =
             !options.resolvers ||


Test patch:
diff --git a/tests/functional/resolvers.ts b/tests/functional/resolvers.ts
index c1ab50ea..b8cebc22 100644
--- a/tests/functional/resolvers.ts
+++ b/tests/functional/resolvers.ts
@@ -2479,5 +2479,70 @@ describe("Resolvers", () => {
 
       expect(self).toBeInstanceOf(childResolver);
     });
+
+    it("should allow duplicate fieldResolver methods with different schema names for inherited resolvers", async () => {
+      getMetadataStorage().clear();
+      const INHERITED_DYNAMIC_FIELD_NAME_1 = "dynamicallyNamedMethod1";
+      const INHERITED_DYNAMIC_FIELD_NAME_2 = "dynamicallyNamedMethod2";
+
+      const withDynamicallyNamedFieldResolver = (
+        classType: ClassType,
+        BaseResolverClass: ClassType,
+        name: string,
+      ) => {
+        @Resolver(() => classType)
+        class DynamicallyNamedFieldResolver extends BaseResolverClass {
+          @FieldResolver({ name })
+          dynamicallyNamedField(): boolean {
+            return true;
+          }
+        }
+        return DynamicallyNamedFieldResolver;
+      };
+
+      @ObjectType()
+      class SampleObject {
+        @Field()
+        sampleField!: string;
+      }
+
+      @Resolver()
+      class SampleResolver {
+        @Query(() => SampleObject)
+        sampleObject(): SampleObject {
+          return { sampleField: "sampleText" };
+        }
+      }
+
+      const DynamicallyNamedFieldResolver1 = withDynamicallyNamedFieldResolver(
+        SampleObject,
+        SampleResolver,
+        INHERITED_DYNAMIC_FIELD_NAME_1,
+      );
+      const DynamicallyNamedFieldResolver2 = withDynamicallyNamedFieldResolver(
+        SampleObject,
+        DynamicallyNamedFieldResolver1,
+        INHERITED_DYNAMIC_FIELD_NAME_2,
+      );
+
+      const schemaInfo = await getSchemaInfo({
+        resolvers: [DynamicallyNamedFieldResolver2],
+      });
+      schemaIntrospection = schemaInfo.schemaIntrospection;
+      const sampleObjectType = schemaIntrospection.types.find(
+        type => type.name === "SampleObject",
+      ) as IntrospectionObjectType;
+
+      const dynamicField1 = sampleObjectType.fields.find(
+        field => field.name === INHERITED_DYNAMIC_FIELD_NAME_1,
+      )!;
+
+      const dynamicField2 = sampleObjectType.fields.find(
+        field => field.name === INHERITED_DYNAMIC_FIELD_NAME_2,
+      )!;
+
+      expect(dynamicField1).toBeDefined();
+      expect(dynamicField2).toBeDefined();
+    });
   });
 });