Skip to content

Commit

Permalink
fix(gql): remove deprecations + fixed (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlautier authored Oct 28, 2022
1 parent da8f211 commit a5e1972
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 58 deletions.
4 changes: 3 additions & 1 deletion Heroes.Server/Gql/AppGqlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ public static void AddAppGraphQL(this IServiceCollection services)
{
services.AddGraphQL(builder => builder
.AddNewtonsoftJson()
//.AddSystemTextJson()
.AddDataLoader()
.AddAutoSchema<AppSchema>()
//.AddAutoSchema<AppGraphQuery>()
.AddSchema<AppSchema>()
.AddExecutionStrategySelector<GraceDefaultExecutionStrategySelector>()
.AddUserContextBuilder(httpContext => new GraphQLUserContext { User = httpContext.User })
);
Expand Down
76 changes: 21 additions & 55 deletions Heroes.Server/Gql/AppGraphQuery.cs
Original file line number Diff line number Diff line change
@@ -1,82 +1,48 @@
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;

public class AppGraphQuery : ObjectGraphType
{
public AppGraphQuery(
IHeroGrainClient heroGrainClient,
IHeroCategoryGrainClient heroCategoryGrainClient,
IHeroStatsGrainClient heroStatsClient,
IHeroService mockHeroService
IHeroCategoryGrainClient heroCategoryGrainClient
)
{
Name = "AppQueries";

Field<HeroGraphType>(
name: "hero",
description: "hero full object",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "key", Description = "Unique key for specific hero" }
),
resolve: context =>
Field<HeroGraphType, Hero>("hero")
.Description("Hero entry.")
.Argument<StringGraphType>("key", "Unique key.")
.ResolveAsync(ctx =>
{
var result = heroGrainClient.Get(context.GetArgument<string>("key"));
var result = heroGrainClient.Get(ctx.GetArgument<string>("key"));
return result;
}
);
})
;

Field<ListGraphType<HeroCategoryGraphType>>(
name: "heroCategories",
description: "hero categories",
resolve: context =>
Field<ListGraphType<HeroGraphType>, List<Hero>>("heroes")
.Description("All available Heroes.")
.Argument<HeroRoleGraphType>("role", "Filter by role.")
.ResolveAsync(ctx =>
{
var result = heroCategoryGrainClient.GetAll();
return result;
}
);

Field<ListGraphType<HeroGraphType>>(
name: "heroes",
description: "heroes list",
arguments: new QueryArguments(
new QueryArgument<HeroRoleGraphType> { Name = "role", Description = "filtering heroes by role." }
),
resolve: context =>
{
var role = context.GetArgument<int?>("role");
var role = ctx.GetArgument<int?>("role");
var result = heroGrainClient.GetAll((HeroRoleType?)role);
return result;
}
);
})
;

Field<HeroStatsGraphType>(
name: "herostats",
description: "view all hero stats",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "key", Description = "Unique key for specific hero" }
),
resolve: context =>
Field<ListGraphType<HeroCategoryGraphType>, List<HeroCategory>>("heroCategories")
.Description("All hero categories.")
.ResolveAsync(ctx =>
{
var result = heroStatsClient.Get(context.GetArgument<string>("key"));
var result = heroCategoryGrainClient.GetAll();
return result;
}
);

})
;

Field<ListGraphType<HeroGraphType>>(
name: "heroesMock",
description: "heroes list",
resolve: context =>
{
var result = mockHeroService.Heroes();
return result;
}
);
}
}
6 changes: 4 additions & 2 deletions Heroes.Server/Gql/Types/HeroGraphType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public HeroGraphType()
Field(x => x.Name).Description("Hero name.");
Field(x => x.Popularity).Description("Hero popularity.");

// todo: update
Field<HeroRoleGraphType>("role", "Hero role type e.g. assassin");
Field<HeroRoleGraphType>("role")
.Description("Hero role type e.g. assassin")
;

Field<ListGraphType<StringGraphType>, HashSet<string>>("abilities")
.Resolve(ctx => ctx.Source.Abilities)
.Description("Hero abilities.")
Expand Down

0 comments on commit a5e1972

Please sign in to comment.