Skip to content
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

Fix/mock data answers #80

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions TeacherWorkout.Api/GraphQL/TeacherWorkoutMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,33 @@ public TeacherWorkoutMutation(CompleteStep completeStep,
{
Name = "Mutation";

Field<NonNullGraphType<LessonSavePayloadType>>(
"lessonSave",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<LessonSaveInputType>> { Name = "input" }
),
resolve: context =>
Field<NonNullGraphType<LessonSavePayloadType>>("lessonSave")
.Argument<NonNullGraphType<LessonSaveInputType>>(Name = "input")
.Resolve(context =>
{
var lessonSave = context.GetArgument<LessonSaveInput>("input");
return LessonSaveResolver.Resolve(lessonSave);
});

Field<StepCompletePayloadType>(
"stepComplete",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<StepCompleteInputType>> { Name = "input" }
),
resolve: context =>
Field<StepCompletePayloadType>("stepComplete")
.Argument<NonNullGraphType<StepCompleteInputType>>(Name = "input")
.Resolve(context =>
{
var input = context.GetArgument<StepCompleteInput>("input");
return completeStep.Execute(input);
});

Field<ThemeCreatePayloadType>(
"themeCreate",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ThemeCreateInputType>> { Name = "input" }
),
resolve: context =>
Field<ThemeCreatePayloadType>("themeCreate")
.Argument<NonNullGraphType<ThemeCreateInputType>>(Name = "input")
.Resolve(context =>
{
var input = context.GetArgument<ThemeCreateInput>("input");
return createTheme.Execute(input);
});

Field<ThemeUpdatePayloadType>(
"themeUpdate",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ThemeUpdateInputType>> { Name = "input" }
),
resolve: context =>
Field<ThemeUpdatePayloadType>("themeUpdate")
.Argument<NonNullGraphType<ThemeUpdateInputType>>(Name = "input")
.Resolve(context =>
{
var input = context.GetArgument<ThemeUpdateInput>("input");
return updateTheme.Execute(input);
Expand Down
20 changes: 7 additions & 13 deletions TeacherWorkout.Api/GraphQL/TeacherWorkoutQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ public TeacherWorkoutQuery(GetThemes getThemes,
.ReturnAll()
.Resolve(context => getLessons.Execute(context.ToInput<LessonFilter>()).ToConnection());

Field<NonNullGraphType<StepUnionType>>(
"step",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<IdGraphType>> {Name = "id", Description = "id of the step"}
),
resolve: context => getStep.Execute(context.ToInput<StepFindInput>()));

Field<ListGraphType<NonNullGraphType<LessonStatusType>>>(
"lessonStatuses",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ListGraphType<NonNullGraphType<IdGraphType>>>> { Name = "lessonIds", Description = "Ids of " }
),
resolve: context => getLessonStatuses.Execute(context.ToInput<LessonStatusFilter>()));
Field<NonNullGraphType<StepUnionType>>("step")
.Argument<NonNullGraphType<IdGraphType>>(Name = "id", Description = "id of the step")
.Resolve(context => getStep.Execute(context.ToInput<StepFindInput>()));

Field<ListGraphType<NonNullGraphType<LessonStatusType>>>("lessonStatuses")
.Argument<NonNullGraphType<ListGraphType<NonNullGraphType<IdGraphType>>>>(Name = "lessonIds", Description = "Id's of leassons")
.Resolve(context => getLessonStatuses.Execute(context.ToInput<LessonStatusFilter>()));
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions TeacherWorkout.Api/GraphQL/Types/AnswerStatusEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,5 @@ namespace TeacherWorkout.Api.GraphQL.Types
{
public class AnswerStatusEnum : EnumerationGraphType<AnswerStatus>
{
public AnswerStatusEnum()
{
Name = "AnswerStatus";

AddValue("Correct", "Correct.", 1);
AddValue("Incorrect", "Incorrect.", 2);
AddValue("None", "None.", 3);
}
}
}
7 changes: 0 additions & 7 deletions TeacherWorkout.Api/GraphQL/Types/DurationUnitEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,5 @@ namespace TeacherWorkout.Api.GraphQL.Types
{
public class DurationUnitEnum : EnumerationGraphType<DurationUnit>
{
public DurationUnitEnum()
{
Name = "DurationUnit";

AddValue("Minutes", "Minutes.", 1);
AddValue("Hours", "Hours.", 2);
}
}
}
2 changes: 2 additions & 0 deletions TeacherWorkout.Api/GraphQL/Types/ExerciseStepType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public ExerciseStepType()
Field(x => x.Id, type: typeof(IdGraphType));
Field(x => x.Question).Description("The question");
Field(x => x.Answers).Description("The possible possible answers");

IsTypeOf = obj => obj is ExerciseStep;
}
}
}
18 changes: 9 additions & 9 deletions TeacherWorkout.Api/GraphQL/Types/LessonStepInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@ namespace TeacherWorkout.Api.GraphQL.Types
{
public class LessonStepInterface : InterfaceGraphType<ILessonStep>
{
public LessonStepInterface(
SlideStepType slideStep,
ExerciseStepType exerciseStep,
ExerciseSummaryStepType exerciseSummaryStep,
LessonSummaryStepType lessonSummaryStep)
public LessonStepInterface()
{
Name = "LessonStep";

Field(d => d.Id, type: typeof(IdGraphType)).Description("The id of the step.");

// Note: be sure not to pull in these references from DI when the graph types
// are registered as transients (the default lifetime for graph types)
// https://github.com/graphql-dotnet/graphql-dotnet/blob/master/docs2/site/docs/getting-started/interfaces.md#resolvetype
ResolveType = obj =>
{
if (obj is SlideStep)
{
return slideStep;
return new GraphQLTypeReference("SlideStep");
}

if (obj is ExerciseStep)
{
return exerciseStep;
return new GraphQLTypeReference("ExerciseStep");
}

if (obj is ExerciseSummaryStep)
{
return exerciseSummaryStep;
return new GraphQLTypeReference("ExerciseSummaryStep");
}

if (obj is LessonSummaryStep)
{
return lessonSummaryStep;
return new GraphQLTypeReference("LessonSummaryStep");
}

throw new ArgumentOutOfRangeException($"Could not resolve graph type for {obj.GetType().Name}");
Expand Down
13 changes: 5 additions & 8 deletions TeacherWorkout.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using GraphQL.Server;
using GraphQL;
using GraphQL.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand Down Expand Up @@ -42,13 +42,10 @@ public void ConfigureServices(IServiceCollection services)
AddRepositories(services, "TeacherWorkout.Data");

services.AddHttpContextAccessor();
services.AddGraphQL(options =>
{
options.EnableMetrics = false;
})
.AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true)
.AddSystemTextJson()
.AddGraphTypes();
services.AddGraphQL(b => b
.AddErrorInfoProvider(opt => opt.ExposeExceptionDetails = true)
.AddGraphTypes()
.AddSystemTextJson());

services.AddDbContext<TeacherWorkoutContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("TeacherWorkoutContext")));
Expand Down
2 changes: 1 addition & 1 deletion TeacherWorkout.Api/TeacherWorkout.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.SystemTextJson" Version="5.2.2" />
<PackageReference Include="GraphQL.Server.All" Version="7.6.0" />
<PackageReference Include="GraphQL.Server.Ui.Graphiql" Version="7.6.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
16 changes: 14 additions & 2 deletions TeacherWorkout.Data/Repositories/LessonStatusRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@ public IEnumerable<LessonStatus> List(LessonStatusFilter filter)
return lessons.Select(l => new LessonStatus
{
Lesson = l,
CurrentLessonStep = new ExerciseStep {
Question = "Some very important question?"
CurrentLessonStep = new ExerciseStep
{
Id = "42",
Question = "Some very important question?",
Answers = new List<Answer> {
new() {
Id = "42",
Title = "Yes"
},
new() {
Id = "43",
Title = "Awesome"
}
}
},
PercentCompleted = 1
});
Expand Down
Loading