forked from thinkb4/a-walk-in-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ignacio Aguilera
authored and
Ignacio Aguilera
committed
Jul 21, 2020
1 parent
e27b626
commit 2e1d971
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
lessons/day_06/netcore/src/GraphQLSample/GraphQLTypes/Output/EngineerType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
lessons/day_06/netcore/src/GraphQLSample/Models/Engineer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters