ChilliCream/graphql-platform

Fusion composition issue: The name `cost` was already registered by another type. (HotChocolate.Types.DirectiveType)

wouth opened this issue · 5 comments

Product

Hot Chocolate

Version

14.0.0

Link to minimal reproduction

https://github.com/wouth/FusionCompositionIssue

Steps to reproduce

  • Run dotnet tool restore
  • Build FusionCompositionIssue.sln
  • Run all 3 projects (Gateway, Subgrapgh1 and Subgraph2) of the solution
  • Run build-gateway.cmd to:
    • for the subgraphs: download the schema's and pack the subgraph
    • for the gateway: compose the gateway
    • download the schema of the just composed gateway
  • The last step fails. See the debug terminal of the gateway where the error (The name cost was already registered by another type. (HotChocolate.Types.DirectiveType)) is shown.

What is expected?

I expect that there is no issue composing a gateway for multiple subgraphs where the @cost directive exists in multiple subgraphs.

What is actually happening?

Error The name cost was already registered by another type. (HotChocolate.Types.DirectiveType) is returned by the gateway when requesting the schema.

Relevant log output

[2024-10-17T07:42:16.564Z] Function 'GraphQL', Invocation id 'e349e599-8e80-45d9-8821-33afb183547f': An exception was thrown by the invocation.
[2024-10-17T07:42:16.601Z] Result: Function 'GraphQL', Invocation id 'e349e599-8e80-45d9-8821-33afb183547f': An exception was thrown by the invocation.
Exception: HotChocolate.SchemaException: For more details look at the Errors property.
[2024-10-17T07:42:16.584Z] Executed 'Functions.GraphQL' (Failed, Id=e349e599-8e80-45d9-8821-33afb183547f, Duration=1861ms)
[2024-10-17T07:42:16.604Z] System.Private.CoreLib: Exception while executing function: Functions.GraphQL. System.Private.CoreLib: Result: Failure
Exception: HotChocolate.SchemaException: For more details look at the Errors property.
[2024-10-17T07:42:16.606Z]
[2024-10-17T07:42:16.607Z] 1. The name cost was already registered by another type. (HotChocolate.Types.DirectiveType)
[2024-10-17T07:42:16.580Z] Executed 'Functions.GraphQL' (Failed, Id=bccb61f4-eaec-41ef-b845-854d3501b295, Duration=1862ms)
[2024-10-17T07:42:16.584Z] Executed 'Functions.GraphQL' (Failed, Id=58e787ae-68ba-475a-ae18-f75f9bf4b8a2, Duration=1861ms)

Additional context

Schema for Subgraph1:

schema {
  query: Query
}

type Test1 {
  testProperty: String
}

type Query {
  test1: [Test1]
}

"The purpose of the `cost` directive is to define a `weight` for GraphQL types, fields, and arguments. Static analysis can use these weights when calculating the overall cost of a query or response."
directive @cost("The `weight` argument defines what value to add to the overall cost for every appearance, or possible appearance, of a type, field, argument, etc." weight: String!) on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM | INPUT_FIELD_DEFINITION

Schema for Subgraph2:

schema {
  query: Query
}

type Test2 {
  testProperty: String
}

type Query {
  test2: [Test2]
}

"The purpose of the `cost` directive is to define a `weight` for GraphQL types, fields, and arguments. Static analysis can use these weights when calculating the overall cost of a query or response."
directive @cost("The `weight` argument defines what value to add to the overall cost for every appearance, or possible appearance, of a type, field, argument, etc." weight: String!) on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM | INPUT_FIELD_DEFINITION

Above issue is not solved in version 14.1.0-p.2.

I'm not able to run the projects without the host.json and local.settings.json files. What should they contain?

I'm not able to run the projects without the host.json and local.settings.json files. What should they contain?

I just removed the host.json files as they were not needed, and added the local.settings.json files.

System.InvalidOperationException: The gRPC channel URI 'http://:7201' could not be parsed.

To run the projects in de solution, I use VS2022 to start the 3 projects at oncee.

Otherwise, I think you need these steps:

cd Subgraph1
func.exe start --port 7201
  • Open command prompt:
cd Subgraph2
func.exe start --port 7202
  • Open command prompt:
cd Gateway
func.exe start --port 7200
  • Continue with above bullet 'Run build-gateway.cmd to'.