Skip to content

Update NuGet packages and remove deprecated syntax in examples #138

@pharmafirma

Description

@pharmafirma

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.

// Deprecated syntax
FieldAsync<CharacterInterface>("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:

public class StarWarsQuery : ObjectGraphType<object>
{
    public StarWarsQuery(StarWarsData data)
    {
        Name = "Query";
        Field<CharacterInterface>("hero")
            .ResolveAsync(async context => await data.GetDroidByIdAsync("3"));
        Field<HumanType>("human")
            .Description("id of the human")
            .Argument<NonNullGraphType<StringGraphType>>("id")
            .ResolveAsync(async context => await data.GetHumanByIdAsync(context.GetArgument<string>("id")));

        Func<IResolveFieldContext, string, Task<Droid>> func = (context, id) => data.GetDroidByIdAsync(id);
        Field<DroidType>("droid")
            .Description("id of the droid")
            .Argument<NonNullGraphType<StringGraphType>>("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

Thank you for your time :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions