-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement LessonSave mutation #31
Merged
pirvudoru
merged 7 commits into
code4romania:develop
from
alex-damian-negru:feature/implement-lessonSave-mutation
Jul 21, 2021
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e77397
Add initial mutation with `LessonSave`
e8e94e1
Extract mock LessonSave resolver
ff30034
Take input into account
72d91dd
Extract LessonSaveResolver#Resolve
190b64d
Auto-register GraphQL `Inputs` & `Types` namespaces
1824620
Reorganize input and output types
pirvudoru 006376a
Merge pull request #1 from pirvudoru/feature/implement-lessonSave-mut…
alex-damian-negru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,13 @@ | ||
using GraphQL.Types; | ||
|
||
namespace TeacherWorkout.Api.GraphQL.Inputs | ||
{ | ||
public class LessonSaveInput : InputObjectGraphType | ||
{ | ||
public LessonSaveInput() | ||
{ | ||
Name = "LessonSaveInput"; | ||
Field<IdGraphType>("lessonId"); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
TeacherWorkout.Api/GraphQL/Resolvers/LessonSaveResolver.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,42 @@ | ||
using TeacherWorkout.Api.Models; | ||
|
||
namespace TeacherWorkout.Api.GraphQL.Resolvers | ||
|
||
{ | ||
public static class LessonSaveResolver | ||
{ | ||
public static LessonSavePayload Resolve(LessonSave lessonSave) | ||
{ | ||
return new() {Lesson = MockData(lessonSave)}; | ||
} | ||
|
||
private static Lesson MockData(LessonSave lessonSave) | ||
{ | ||
return new() | ||
{ | ||
Id = lessonSave.LessonId, | ||
Title = "Lorem Ipsum", | ||
Thumbnail = new Image | ||
{ | ||
Description = "For Challenged People", | ||
Url = "https://example.com" | ||
}, | ||
Theme = new Theme | ||
{ | ||
Id = "1", | ||
Title = "Lorem Ipsum", | ||
Thumbnail = new Image | ||
{ | ||
Description = "For Challenged People", | ||
Url = "https://example.com" | ||
} | ||
}, | ||
Duration = new Duration | ||
{ | ||
Value = 45, | ||
Unit = DurationUnit.Minutes | ||
} | ||
}; | ||
} | ||
} | ||
} |
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,28 @@ | ||
using GraphQL; | ||
using GraphQL.Types; | ||
using TeacherWorkout.Api.GraphQL.Resolvers; | ||
using TeacherWorkout.Api.GraphQL.Types; | ||
using TeacherWorkout.Api.Models; | ||
using LessonSaveInput = TeacherWorkout.Api.GraphQL.Inputs.LessonSaveInput; | ||
|
||
namespace TeacherWorkout.Api.GraphQL | ||
{ | ||
public class TeacherWorkoutMutation : ObjectGraphType<object> | ||
{ | ||
public TeacherWorkoutMutation(LessonSaveInput input) | ||
{ | ||
Name = "Mutation"; | ||
|
||
Field<LessonSavePayloadType>( | ||
"lessonSave", | ||
arguments: new QueryArguments( | ||
new QueryArgument<NonNullGraphType<LessonSaveInput>> {Name = "input"} | ||
), | ||
resolve: context => | ||
{ | ||
var lessonSave = context.GetArgument<LessonSave>("input"); | ||
return LessonSaveResolver.Resolve(lessonSave); | ||
}); | ||
} | ||
} | ||
} |
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
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,15 @@ | ||
using GraphQL.Types; | ||
using TeacherWorkout.Api.Models; | ||
|
||
namespace TeacherWorkout.Api.GraphQL.Types | ||
{ | ||
public class LessonSavePayloadType : ObjectGraphType<LessonSavePayload> | ||
{ | ||
public LessonSavePayloadType() | ||
{ | ||
Name = "LessonSavePayload"; | ||
|
||
Field(x => x.Lesson).Description("The newly created lesson."); | ||
} | ||
} | ||
} |
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,14 @@ | ||
using TeacherWorkout.Api.GraphQL.Types; | ||
|
||
namespace TeacherWorkout.Api.Models | ||
{ | ||
public class LessonSave | ||
{ | ||
private string _lessonId; | ||
public dynamic LessonId | ||
{ | ||
get => _lessonId; | ||
set => _lessonId = value.ToString(); | ||
} | ||
} | ||
} |
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,9 @@ | ||
using TeacherWorkout.Api.GraphQL.Types; | ||
|
||
namespace TeacherWorkout.Api.Models | ||
{ | ||
public class LessonSavePayload | ||
{ | ||
public Lesson Lesson { 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
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
<ItemGroup> | ||
<Folder Include="Controllers" /> | ||
<Folder Include="GraphQL\Mutations" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal:
Rename this to a LessonSaveInputType
Define a LessonSaveInput
Inherit LessonSaveInputType from InputObjectGraphType
Define the fields using the strongly typed methods to avoid typos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand this correctly. Which
strongly typed methods
are you referring to?Also, wouldn't it be confusing if a file was named
..InputType
? Would it be both anInput
& aType
? 🤷♂️There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made alex-damian-negru#1 to show what i was talknig about.