Skip to content

Commit

Permalink
add Engineer type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Aguilera authored and Ignacio Aguilera committed Jul 21, 2020
1 parent e27b626 commit 2e1d971
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using GraphQL.Types;
using GraphQLNetCore.GraphQLTypes.Enums;
using GraphQLNetCore.Models;
using GraphQLNetCore.Models.Input;
using GraphQLNetCore.Repositories;

namespace GraphQLNetCore.GraphQLTypes.Output
{
public class EngineerType : ObjectGraphType<Engineer>
{
public EngineerType(IPersonRepository personRepo, ISkillRepository skillRepo)
{
Interface<PersonInterface>();
Interface<EmployeeInterface>();
IsTypeOf = obj => obj is Engineer;

Name = nameof(Engineer);
Field(_ => _.Age);
Field(_ => _.Email);
Field(_ => _.Id, type: typeof(IdGraphType));
Field(_ => _.Name);
Field(_ => _.Surname);
Field(_ => _.EmployeeId);
Field(_ => _.Grade, type: typeof(GradeType));
Field(_ => _.Role, type: typeof(RoleType));
Field(_ => _.EyeColor, nullable: true, type: typeof(EyeColorType));
Field<StringGraphType>("fullName", resolve: context => $"{context.Source.Name} {context.Source.Surname}");
Field<ListGraphType<NonNullGraphType<SkillType>>>(
nameof(Person.Skills),
arguments: new QueryArguments
{
new QueryArgument<InputSkillType> { Name = "input" }
},
resolve: context =>
{
var input = context.GetArgument<InputSkill>("input");
return personRepo.GetSkills(context.Source.Id, input);
});
Field<ListGraphType<NonNullGraphType<PersonInterface>>>(
nameof(Person.Friends),
arguments: new QueryArguments
{
new QueryArgument<InputPersonType> { Name = "input" }
},
resolve: context =>
{
var input = context.GetArgument<InputPerson>("input");
return personRepo.GetFriends(context.Source.Id, input);
});
Field<SkillType>(
nameof(Person.FavSkill),
resolve: context => skillRepo.Get(InputSkill.FromId(context.Source.FavSkillId))
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public RootSchema(IDependencyResolver resolver, RootQuery query, RootMutation mu

RegisterType<ContactType>();
RegisterType<CandidateType>();
RegisterType<EngineerType>();
}
}
}
12 changes: 12 additions & 0 deletions lessons/day_06/netcore/src/GraphQLSample/Models/Engineer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using GraphQLNetCore.Models.Abstractions;
using GraphQLNetCore.Models.Enums;

namespace GraphQLNetCore.Models
{
public class Engineer: Person, IEmployee
{
public int EmployeeId { get; set; }
public Role Role { get; set; }
public Grade Grade { get; set; }
}
}
1 change: 1 addition & 0 deletions lessons/day_06/netcore/src/GraphQLSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<EmployeeInterface>();
services.AddSingleton<ContactType>();
services.AddSingleton<CandidateType>();
services.AddSingleton<EngineerType>();
services.AddSingleton<InputPersonType>();
services.AddSingleton<InputPersonCreateType>();
services.AddSingleton<EyeColorType>();
Expand Down

0 comments on commit 2e1d971

Please sign in to comment.