I am working on a project where I need to use GraphQL in my asp.net core 3.1 project and this is the first time I am working with GraphQL. I added all the required dependencies and when I try to build, it gives compilation error as follows:
PKIUYTSWS123:example-orders andy$ dotnet build
Microsoft (R) Build Engine version 16.7.1+52cd83677 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
Schema/OrdersSchema.cs(11,48): error CS0246: The type or namespace name 'IDependencyResolver' could not be found (are you missing a using directive or an assembly reference?) [/Users/andy/Documents/work/git/example-orders/Orders/Orders.csproj]
Schema/OrdersSubscription.cs(34,41): error CS0246: The type or namespace name 'ResolveFieldContext' could not be found (are you missing a using directive or an assembly reference?) [/Users/andy/Documents/work/git/example-orders/Orders/Orders.csproj]
Build FAILED.
Schema/OrdersSchema.cs(11,48): error CS0246: The type or namespace name 'IDependencyResolver' could not be found (are you missing a using directive or an assembly reference?) [/Users/andy/Documents/work/git/example-orders/Orders/Orders.csproj]
Schema/OrdersSubscription.cs(34,41): error CS0246: The type or namespace name 'ResolveFieldContext' could not be found (are you missing a using directive or an assembly reference?) [/Users/andy/Documents/work/git/example-orders/Orders/Orders.csproj]
0 Warning(s)
2 Error(s)
It looks like IDependencyResolver was removed in GraphQL.NET 3.0 and I am not sure on how can I fix this issue in my project. This is all the dependencies I have here -
Orders.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Types\**" />
<EmbeddedResource Remove="Types\**" />
<None Remove="Types\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GraphQL" Version="3.3.1" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Reactive.Compatibility" Version="5.0.0" />
</ItemGroup>
</Project>
Server.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Transports.WebSockets" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Ui.Playground" Version="4.2.0" />
<PackageReference Include="GraphQL.Server.Ui.Voyager" Version="4.2.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Orders\Orders.csproj" />
</ItemGroup>
</Project>
Here is my OrdersSubscription.cs class and OrdersSchema.cs class.
I have put together an example here in this git repo which outlines this problem. Any thoughts why I am getting this error and how can I fix it? Any help will be appreciate in fixing this issue in my git repo.
I am gonna run this code in production so trying to figure out the right and efficient way to integrate GraphQL in asp.net core 3.1 project.