From a5e197290ed21d799b0227a19fb22cd56ed9b463 Mon Sep 17 00:00:00 2001 From: Stephen Lautier Date: Fri, 28 Oct 2022 11:49:10 +0200 Subject: [PATCH] fix(gql): remove deprecations + fixed (#65) --- Heroes.Server/Gql/AppGqlExtensions.cs | 4 +- Heroes.Server/Gql/AppGraphQuery.cs | 76 +++++++----------------- Heroes.Server/Gql/Types/HeroGraphType.cs | 6 +- 3 files changed, 28 insertions(+), 58 deletions(-) diff --git a/Heroes.Server/Gql/AppGqlExtensions.cs b/Heroes.Server/Gql/AppGqlExtensions.cs index 58d2a19..861c9d7 100644 --- a/Heroes.Server/Gql/AppGqlExtensions.cs +++ b/Heroes.Server/Gql/AppGqlExtensions.cs @@ -11,8 +11,10 @@ public static void AddAppGraphQL(this IServiceCollection services) { services.AddGraphQL(builder => builder .AddNewtonsoftJson() + //.AddSystemTextJson() .AddDataLoader() - .AddAutoSchema() + //.AddAutoSchema() + .AddSchema() .AddExecutionStrategySelector() .AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User }) ); diff --git a/Heroes.Server/Gql/AppGraphQuery.cs b/Heroes.Server/Gql/AppGraphQuery.cs index 64d9b8b..9b8d0eb 100644 --- a/Heroes.Server/Gql/AppGraphQuery.cs +++ b/Heroes.Server/Gql/AppGraphQuery.cs @@ -1,9 +1,7 @@ using GraphQL; using Heroes.Contracts.HeroCategories; using Heroes.Contracts.Heroes; -using Heroes.Contracts.Stats; using Heroes.Server.Gql.Types; -using Heroes.Server.Sample; namespace Heroes.Server.Gql; @@ -11,72 +9,40 @@ public class AppGraphQuery : ObjectGraphType { public AppGraphQuery( IHeroGrainClient heroGrainClient, - IHeroCategoryGrainClient heroCategoryGrainClient, - IHeroStatsGrainClient heroStatsClient, - IHeroService mockHeroService + IHeroCategoryGrainClient heroCategoryGrainClient ) { Name = "AppQueries"; - Field( - name: "hero", - description: "hero full object", - arguments: new QueryArguments( - new QueryArgument> { Name = "key", Description = "Unique key for specific hero" } - ), - resolve: context => + Field("hero") + .Description("Hero entry.") + .Argument("key", "Unique key.") + .ResolveAsync(ctx => { - var result = heroGrainClient.Get(context.GetArgument("key")); + var result = heroGrainClient.Get(ctx.GetArgument("key")); return result; - } - ); + }) + ; - Field>( - name: "heroCategories", - description: "hero categories", - resolve: context => + Field, List>("heroes") + .Description("All available Heroes.") + .Argument("role", "Filter by role.") + .ResolveAsync(ctx => { - var result = heroCategoryGrainClient.GetAll(); - return result; - } - ); - - Field>( - name: "heroes", - description: "heroes list", - arguments: new QueryArguments( - new QueryArgument { Name = "role", Description = "filtering heroes by role." } - ), - resolve: context => - { - var role = context.GetArgument("role"); + var role = ctx.GetArgument("role"); var result = heroGrainClient.GetAll((HeroRoleType?)role); return result; - } - ); + }) + ; - Field( - name: "herostats", - description: "view all hero stats", - arguments: new QueryArguments( - new QueryArgument> { Name = "key", Description = "Unique key for specific hero" } - ), - resolve: context => + Field, List>("heroCategories") + .Description("All hero categories.") + .ResolveAsync(ctx => { - var result = heroStatsClient.Get(context.GetArgument("key")); + var result = heroCategoryGrainClient.GetAll(); return result; - } - ); - + }) + ; - Field>( - name: "heroesMock", - description: "heroes list", - resolve: context => - { - var result = mockHeroService.Heroes(); - return result; - } - ); } } \ No newline at end of file diff --git a/Heroes.Server/Gql/Types/HeroGraphType.cs b/Heroes.Server/Gql/Types/HeroGraphType.cs index f0d4a0a..8845e14 100644 --- a/Heroes.Server/Gql/Types/HeroGraphType.cs +++ b/Heroes.Server/Gql/Types/HeroGraphType.cs @@ -13,8 +13,10 @@ public HeroGraphType() Field(x => x.Name).Description("Hero name."); Field(x => x.Popularity).Description("Hero popularity."); - // todo: update - Field("role", "Hero role type e.g. assassin"); + Field("role") + .Description("Hero role type e.g. assassin") + ; + Field, HashSet>("abilities") .Resolve(ctx => ctx.Source.Abilities) .Description("Hero abilities.")