graphql-dotnet / graphql-dotnet/examples
Update NuGet packages and remove deprecated syntax in examples
- Dominant language
- C#
- Stars
- 268
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
Dear graphql-dotnet team, thank you all for this great software! I am updating the NuGet packages in my GraphQL server project and got some deprecated warnings. So of course I checked the examples in this repo and noticed that they are also still using old NuGets and a deprecated Field syntax.
# Expected Behaviour
Examples should use more up-to-date NuGet Package (e.g. the latest 8.5.x) and avoid deprecated methods.
# Actual Behaviour
The StarWars example uses an older NuGet package (5.1.x) and deprecated Field syntax. I haven't verified the other examples.
```C#
// Deprecated syntax
FieldAsync("hero", resolve: async context => await data.GetDroidByIdAsync("3"));
```
# Steps to reproduce
1. `git clone https://github.com/graphql-dotnet/examples.git`
2. Open \src\AspNetCore\AspNetCore.sln in Visual Studio
3. In the NuGet Package Manager, update the GraphQL package
After these steps, the project fails to compile, and there are several deprecated warnings.
# Proposed fix
Can somebody please confirm that this is the recommended syntax for the foreseeable future? Adapted from [src/StarWars/StarWarsQuery.cs](https://github.com/graphql-dotnet/examples/blob/master/src/StarWars/StarWarsQuery.cs):
```C#
public class StarWarsQuery : ObjectGraphType
{
public StarWarsQuery(StarWarsData data)
{
Name = "Query";
Field("hero")
.ResolveAsync(async context => await data.GetDroidByIdAsync("3"));
Field("human")
.Description("id of the human")
.Argument>("id")
.ResolveAsync(async context => await data.GetHumanByIdAsync(context.GetArgument("id")));
Func> func = (context, id) => data.GetDroidByIdAsync(id);
Field("droid")
.Description("id of the droid")
.Argument>("id")
.ResolveDelegate(func);
}
}
```
If somebody approves, I am ready to invest some time and create a pull request with updated GraphQL NuGets and Field Syntax.
In case I have just missed any up-to-date examples or documentation, could you please point me to them or consider updating the README?
# My environment:
* Windows 11
* Visual Studio 2022
* Target Framework: I tried with .NET 8.0 (latest LTS) and .NET 9.0 (latest)
* GraphQL Nuget Package [8.5.0](https://www.nuget.org/packages/GraphQL/8.5.0)
Thank you for your time :)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.