ardatan / graphql-mesh

🕸️ GraphQL Federation Framework for any API services such as REST, OpenAPI, Swagger, SOAP, gRPC and more...
https://the-guild.dev/graphql/mesh
MIT License
3.3k stars 347 forks source link

[V1] Can't use "resolveTo" with type, query or field renaming #7742

Open enan69500 opened 1 month ago

enan69500 commented 1 month ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.


Describe the bug

When use @resolveTo with renaming source OpenApi (And other i think), that's not working.

TypeDef without renaming =>
  additionalTypeDefs: `
    extend type PointOfSale {
        test: [MS_Agency_CicsAgencyResponse]
          @resolveTo(
            sourceName: "ms-agency"
            sourceTypeName: "Query"
            sourceFieldName: "getCicsByIdUsingGET"
            requiredSelectionSet: "{ agencyId }"
            sourceArgs: { agency_id: "{root.agencyId}" }
          )
    }
  ` 

==> Work

But my renaming =>

        createRenameTransform({
             typeRenamer: ({ typeName }) => {
                 switch (typeName) {
                     case "MS_Agency_AgencyResponse":
                         return "PointOfSale";
                     default:
                         return typeName;
                 }
             },
             fieldRenamer: ({ typeName, fieldName }) => {
                if(typeName === "MS_Agency_Query" && fieldName === "MS_Agency_getCicsByIdUsingGET") {
                    return "getCicsById";
                }
                return fieldName;
             },
         }),

So new typedef :

TypeDef without renaming =>
  additionalTypeDefs: `
    extend type PointOfSale {
        test: [MS_Agency_CicsAgencyResponse]
          @resolveTo(
            sourceName: "ms-agency"
            sourceTypeName: "Query"
            sourceFieldName: "getCicsById"
            requiredSelectionSet: "{ agencyId }"
            sourceArgs: { agency_id: "{root.agencyId}" }
          )
    }
  ` 

That's not working

Note : As you can see, even Query should be called MS_Agency_Query

To Reproduce Steps to reproduce the behavior:

See above

Expected behavior

Error: No field named "getCicsById" exists in the type Query from the source ms-agency at resolve (file:///C:/Sources/test-gm/graphql-mesh-debug/nodemodules/.pnpm/@graphql-mesh+utils@0.102.5@graphql-mesh+cross-helpers@0.4.6_@graphql-tools+utils@10.5.4_gra_7udymn4ftqclyxdht2baqulwli/node_modules/@graphql-mesh/utils/esm/resolve-additional-resolvers.js:201:35) at executeField (file:///C:/Sources/test-gm/graphql-mesh-debug/node_modules/.pnpm/@graphql-tools+executor@1.3.1_graphql@16.9.0/node_modules/@graphql-tools/executor/esm/execution/execute.js:317:24) at executeFields (file:///C:/Sources/test-gm/graphql-mesh-debug/node_modules/.pnpm/@graphql-tools+executor@1.3.1_graphql@16.9.0/node_modules/@graphql-tools/executor/esm/execution/execute.js:265:28) at collectAndExecuteSubfields (file:///C:/Sources/test-gm/graphql-mesh-debug/node_modules/.pnpm/@graphql-tools+executor@1.3.1_graphql@16.9.0/node_modules/@graphql-tools/executor/esm/execution/execute.js:694:23) at completeObjectValue (file:///C:/Sources/test-gm/graphql-mesh-debug/node_modules/.pnpm/@graphql-tools+executor@1.3.1_graphql@16.9.0/node_modules/@graphql-tools/executor/esm/execution/execute.js:684:12) at completeValue (file:///C:/Sources/test-gm/graphql-mesh-debug/node_modules/.pnpm/@graphql-tools+executor@1.3.1_graphql@16.9.0/node_modules/@graphql-tools/executor/esm/execution/execute.js:452:16) at file:///C:/Sources/test-gm/graphql-mesh-debug/node_modules/.pnpm/@graphql-tools+executor@1.3.1_graphql@16.9.0/node_modules/@graphql-tools/executor/esm/execution/execute.js:320:49 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async file:///C:/Sources/test-gm/graphql-mesh-debug/node_modules/.pnpm/@graphql-tools+executor@1.3.1_graphql@16.9.0/node_modules/@graphql-tools/executor/esm/execution/promiseForObject.js:15:35 at async Promise.all (index 0)

Environment:

Additional context

ardatan commented 3 weeks ago

Thanks for creating the issue. Could you share a reproduction on CodeSandbox?

enan69500 commented 1 week ago

Yes, here's the codesandbox => https://codesandbox.io/p/sandbox/error-mesh-renamming-v74hdz

Step :

In this sample, i used a typescript resolver but the same error

LRNZ09 commented 6 days ago

I'm having the same issue with the latest package version (1.2.0) when applying either the createNamingConventionTransform transform or the createRenameTransform transform.