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

@source directive does not reflect correct type after transforms are applied causing Hive to fail #7771

Open uzair-inamdar opened 1 month ago

uzair-inamdar 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 The @source directive does not have the correct type value for openapi source handler after namingConvention and rename transforms are applied. The value against the type field is the name of the type before the transforms are applied.

The issue here seems to be stemming from type merging that is happening due to the rename. Because the old type does not exist anymore, the source directive is referencing a non-existent type that has merged into another existing type.

To Reproduce Steps to reproduce the behavior:

  1. Use openapi schema to consume a OpenAPI spec compliant schema with a field type of enum.
  2. Apply namingConvention transform followed by rename transform on the Mesh generated enum type name.
  3. Generate the schema using compose-cli and then run Hive locally against the generated schema.
  4. Go to the suggested Hive endpoing (localhost:4000 in my case) and observe the error telling you that the type described in the @source directive cannot be found:
    Error: Type mutation_update_masking_job_by_id_job_type for field MaskingJob.jobType is not defined in the schema

Expected behavior

Generated enum type after transforms
"""The type of the Masking job."""
enum MaskingJobType @source(name: "query_get_masking_execution_metrics_report_items_items_masking_job_type", subgraph: "apigw-services") @join__type(graph: APIGW_SERVICES) {
  STANDARD @join__enumValue(graph: APIGW_SERVICES)
  HYPERSCALE @join__enumValue(graph: APIGW_SERVICES)
}
Incorrect mapping field
MaskingJob {
    jobType: MaskingJobType @source(name: "job_type", type: "mutation_update_masking_job_by_id_job_type", subgraph: "apigw-services") @deprecated(reason: "deprecated")
}
Error on Hive page
Error: Type mutation_update_masking_job_by_id_job_type for field MaskingJob.jobType is not defined in the schema

Environment:

Additional context I see in the @graphql-mesh/compose-cli source code that there is a TODO relating to some transform application: https://github.com/ardatan/graphql-mesh/blob/d46d31b62abacf1fd6fed8e8ad900b29426a8a05/packages/compose-cli/src/getComposedSchemaFromConfig.ts#L130

Maybe that is to blame?

ardatan commented 2 weeks ago

Thanks for creating the issue with details and the PR for the fix. But could you provide a reproduction on CodeSandbox or in a PR? So we can debug together and help you to finish the PR.