Skip to content

Commit

Permalink
Add initial mutation with LessonSave
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Damian Negru committed Jun 26, 2021
1 parent 27f576d commit dd80e90
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
13 changes: 13 additions & 0 deletions TeacherWorkout.Api/GraphQL/Inputs/LessonSaveInput.cs
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");
}
}
}
50 changes: 50 additions & 0 deletions TeacherWorkout.Api/GraphQL/TeacherWorkoutMutation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using GraphQL;
using GraphQL.Types;
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 => new LessonSavePayload
{
Lesson = new Lesson
{
Id = "42",
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
}
}
});
}
}
}
1 change: 1 addition & 0 deletions TeacherWorkout.Api/GraphQL/TeacherWorkoutSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public TeacherWorkoutSchema(IServiceProvider provider)
: base(provider)
{
Query = provider.GetRequiredService<TeacherWorkoutQuery>();
Mutation = provider.GetRequiredService<TeacherWorkoutMutation>();
AddTypeMappings();
}

Expand Down
15 changes: 15 additions & 0 deletions TeacherWorkout.Api/GraphQL/Types/LessonSavePayloadType.cs
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.");
}
}
}
9 changes: 9 additions & 0 deletions TeacherWorkout.Api/Models/LessonSavePayload.cs
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; }
}
}
3 changes: 3 additions & 0 deletions TeacherWorkout.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using TeacherWorkout.Api.GraphQL;
using TeacherWorkout.Api.GraphQL.Inputs;

namespace TeacherWorkout.Api
{
Expand All @@ -26,6 +27,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddControllers();

services.AddSingleton<TeacherWorkoutQuery>();
services.AddSingleton<TeacherWorkoutMutation>();
services.AddSingleton<LessonSaveInput>();
services.AddSingleton<ISchema, TeacherWorkoutSchema>();
AddGraphTypes(services);

Expand Down
1 change: 1 addition & 0 deletions TeacherWorkout.Api/TeacherWorkout.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<Folder Include="Controllers" />
<Folder Include="GraphQL\Mutations" />
</ItemGroup>

</Project>

0 comments on commit dd80e90

Please sign in to comment.