Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem generating client when using NodaTime types in the schema. #8004

Open
david-driscoll opened this issue Feb 9, 2025 · 4 comments
Open

Comments

@david-driscoll
Copy link
Contributor

Product

Strawberry Shake

Version

15.0.3

Link to minimal reproduction

https://github.com/david-driscoll/gql-duplicatekey-poc

Steps to reproduce

I've created a reproduction repository, with a simple project and a simplified.

A simple clone and dotnet build will give you an error like this:

What is expected?

Build should succeed.

What is actually happening?

Build fails.

Relevant log output

Restore complete (0.1s)
  gql-duplicatekey-poc failed with 2 error(s) (0.2s)
    EXEC : error GQL: An item with the same key has already been added. Key: LocalDate
    /Users/david/.nuget/packages/strawberryshake.server/15.0.3/build/StrawberryShake.Server.targets(71,5): error MSB3073: The command "dotnet "/Users/david/.nuget/packages/strawberryshake.server/15.0.3/build/../tools/net9/dotnet-graphql.dll" generate "/Users/david/Development/david-driscoll/gql-duplicatekey-poc" -o "/Users/david/Development/david-driscoll/gql-duplicatekey-poc/obj/Debug/net9.0/berry" -n gql_duplicatekey_poc -a md5 -t" exited with code 1.

Build failed with 2 error(s) in 0.6s

Additional context

Now curiously if I comment out all the usages of LocalDate, LocalTime and LocalDateTime the project builds.

You can see the diff here for the successful build: david-driscoll/gql-duplicatekey-poc@a3ef895

The working branch is: https://github.com/david-driscoll/gql-duplicatekey-poc/tree/working
The failing branch is: https://github.com/david-driscoll/gql-duplicatekey-poc/tree/master

I tried debugging to no avail, I don't know whats going on, lol. Input or output it doesn't appear to matter.

I was able to narrow down the issue appears to be TypeRegistrar.GetUnhandled() returning the duplicate types from the dependencies. How or why, I could not tell you.

@glen-84 glen-84 self-assigned this Feb 10, 2025
@glen-84 glen-84 modified the milestones: HC-15.x.x, HC-15.1.0 Feb 10, 2025
@glen-84
Copy link
Collaborator

glen-84 commented Feb 12, 2025

@david-driscoll Can you please try 15.1.0-p.3?

@michaelstaib
Copy link
Member

@david-driscoll any feedback?

@Dontrym3
Copy link

Dontrym3 commented Feb 19, 2025

I think i have the same issue in my api, here's my partial stacktrace:

HotChocolate.SchemaException: For more details look at the `Errors` property.

1. An item with the same key has already been added. Key: LocalDate

   at HotChocolate.Configuration.TypeInitializer.DiscoverTypes()
   at HotChocolate.Configuration.TypeInitializer.Initialize()
   at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
   at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
   at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
   at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
   at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(ConfigurationContext context, RequestExecutorSetup setup, RequestExecutorOptions executorOptions, IServiceProvider schemaServices, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)

i've tried to use version: 15.1.0-p.3 without success.

Like @david-driscoll, if I remove my LocalDate Property it works.

Here's a small example on how i locally reproduce the issue:

public class Query
{
    // this crash, I must comment for the sdl to successfully generate
    public List<Failure> GetFailure()
        => [new Failure() { Name = "yo", Date = LocalDate.MinIsoValue }];

    public List<Success> GetSuccess()
        => [new Success() { Name = "yo" }];
}

public class Failure
{
    public string Name { get; set; }
    public LocalDate Date { get; set; }
}

public class Success
{
    public string Name { get; set; }
}

i'm using the HotChocolate.Types.NodaTime package right now but I believe even before it was causing problem without the package (I was always using NodaTime LocalDate type in my domain)

@josteinkjerstad
Copy link

+1 to this. We do not use NodaTime but still have the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants