graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Ambiguous Call to AddTypes()

Open danielmackay opened this issue 3 years ago • 13 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Product

Hot Chocolate

Describe the bug

I am trying to use the AddTypes() method to auto register my types, but there are conflicting method signatures. I have used this function as shown in the v13 blog post.

Steps to reproduce

  1. Install the following packages:
    <PackageReference Include="HotChocolate.AspNetCore" Version="13.0.5" />
    <PackageReference Include="HotChocolate.Data.EntityFramework" Version="13.0.5" />
  1. Add the following server configuration:
builder.Services
    .AddGraphQLServer()
    .AddTypes()
  1. Confirm the following error is shown:

image

Relevant log output

No response

Additional Context?

No response

Version

13.0.5

danielmackay avatar Mar 07 '23 13:03 danielmackay

The name of the method is based on the name of your assembly. You can customize it with [assembly: Module("MyName")], and then use AddMyNameTypes(), or just use the default name of your assembly.

glen-84 avatar Mar 07 '23 16:03 glen-84

@glen-84 is correct. In our default template we defined the ModuleInfo to add a module called types thats why in the default template we have the AddTypes method.

I am closing this issue as its not a bug but a config issue.

[assembly:Module("MyTypes")] ... will create AddMyTypes

michaelstaib avatar Mar 08 '23 20:03 michaelstaib

I did manage to get this working by adding ModuleInfo.cs and a reference to the package to do the source generation.

Would be great to see these extra steps added to the documentation.

I would be happy to help with this also if you could provide some direction. 🙂

danielmackay avatar Mar 08 '23 21:03 danielmackay

@tobias-tengler can you provide some directions on how @danielmackay can add this to the docs?

michaelstaib avatar Mar 10 '23 13:03 michaelstaib

Sure :) @danielmackay you can find the documentation in this repository under website. I would add a new page to src/docs/hotchocolate/v13/defining-a-schema, something like automatic-type-registration.md. There you can add a title and the actual content (you can look at other documents for guidance). How you can add this new page is detailed here: https://github.com/ChilliCream/graphql-platform/tree/main/website#creating-a-new-documentation-page

To preview your changes run yarn in the website directory, followed by yarn start.

If you need any further help, please let new know :)

tobias-tengler avatar Mar 12 '23 11:03 tobias-tengler

How was this solved? I cannot figure it out and can't find the documentation that @danielmackay described.

awebCaseys avatar Feb 25 '25 22:02 awebCaseys

I'm getting the same error on the GraphQL server template on the latest Visual Studio. Strangely it still compiles... @michaelstaib I feel this should be reopened.

HunterAhlquist avatar Mar 24 '25 20:03 HunterAhlquist

@michaelstaib I have to confirm what @HunterAhlquist said. I'm using JetBrains Rider if that matters. Nonetheless, when you will open your own tutorial then you will not be able to even compile the template generated by the HotChocolate. I am using the following HotChocolate versions: <ItemGroup> <PackageReference Include="HotChocolate.AspNetCore" Version="15.1.1" /> <PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.1" /> <PackageReference Include="HotChocolate.Types.Analyzers" Version="15.1.1"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> </ItemGroup>

Compiler is not marking any line of code as an issue, but once I will try to build, I am getting the following error message:

0>Program.cs(3,22): Error CS0121 : The call is ambiguous between the following methods or properties: 'SchemaRequestExecutorBuilderExtensions.AddTypes(IRequestExecutorBuilder, params Type[])' and 'SchemaRequestExecutorBuilderExtensions.AddTypes(IRequestExecutorBuilder, params INamedType[])'

Unfortunatelly, this is not an issue of configuration and lack of ModuleInfo.cs's line [assembly: Module("Types")] because your template is already having this line written in GettingStarted/Properties/ModuleInfo.cs

Actually, when I turned the template's : builder.AddGraphQL().AddTypes(); Into:

builder.AddGraphQL()
    .AddType<Author>()
    .AddType<Book>()
    .AddQueryType();

Template compiled, and when I tried to create a query I could not download the schema at all. I am attaching the error message I have recieved after schedule download attempt. I am adding screenshot how I acquired the error message to omit any misunderstandings.

Image

ErrorMessage.md

Please reopen the issue

mariuszbyahoo avatar Mar 26 '25 16:03 mariuszbyahoo

Yeah also can't get the example running

lucsoft avatar Mar 26 '25 17:03 lucsoft

i found it strange why so many new comments here are so i justed one thing.

Looks like this is a big regression from the latests minor update. so i reverted to 15.0.3 and now it works again

Image

lucsoft avatar Mar 26 '25 17:03 lucsoft

Guys, we can downgrade to 15.0.3 OR upgrade to prerelease to 15.1.2-p.1 which already fixes the source generator. I've tested both (as @michaelstaib suggested) - and the prerelease version works just fine

mariuszbyahoo avatar Mar 26 '25 18:03 mariuszbyahoo

Thanks @mariuszbyahoo. Currently I'm using v13 and upgrading to v15. Can fix the issue with HotChocolate.Types.Analyzers v15.0.3. But I try to upgrade all Hotchocolate all related library to v15.1.10. Still having the same issue. Is it really fixed in v15.1.2?

dave-chow avatar Oct 03 '25 13:10 dave-chow

@dave-chow sorry for a late response but I stepped away even from the donet world recently, I think I will not be able to assist you further

mariuszbyahoo avatar Oct 12 '25 14:10 mariuszbyahoo