简体   繁体   中英

Getting ambiquity issues with auto generated code from StrawberryShake (GraphQL)

I'm getting abiquity issues when using the auto generated code from the StrawberryShake.CodeGeneration.CSharp.Analyzers. First time using this package so I might have done something silly.

Image of error in visual studio CS0121

I've tried reinstalling the nuget package and reinstalling the tool.

For reference my project properties are as follows:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
    <PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
    <PackageReference Include="Refit" Version="6.3.2" />
    <PackageReference Include="StrawberryShake.CodeGeneration.CSharp.Analyzers" Version="12.15.2" />
    <PackageReference Include="StrawberryShake.Transport.Http" Version="12.15.2" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\GrafanaUtilities.Shared.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Generated\" />
  </ItemGroup>

  <ItemGroup>
    <GraphQLConfig Include="Queries\Queries.graphql" />
  </ItemGroup>
</Project>

Update: I managed to get arround the error currently by flagging the generated code not to do anything during compile (It appears as though the code is being placed in some temp directory as well as in the "Generated" folder in the project.)

If there is a way to prevent the temp file that would be great to know. For anyone else facing the same issue hope this helps.

I faced the same issue, and it's annoying because when this happens VSCode can not give you IntelliSense, and the generated code is not the most readable.

In fact I don't think it generate any more files than what's in "Generated" folder, but that code is only for us to see. The actual code is generated on the fly.

This is from their getting started guide here: https://chillicream.com/docs/strawberryshake/get-started

With the project compiled you now should see a directory Generated. The generated code is just there for the IDE, the actual code was injected directly into roslyn through source generators

Therefore it should be safe to get rid of the code inside the "Generated" folder, everything works still.

You can do this by setting "emitGeneratedCode": false, in .graphqlrc.json file.

Boom, then VSCode does not complain about duplicate definitions, and IntelliSense works like a Charm.

This appears to have been fixed in StrawberryShake v13, where they use a different approach, a preview release is available now.

I was having the same issue in VS Code and Rider and have been using the comment out solution, but after upgrading I no longer need to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM