Skip to content

Commit

Permalink
Add dependency injector to ProcessRequest. (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
braudabaugh authored and tlil committed Feb 16, 2019
1 parent d2bf3cb commit 751f8ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/GraphQL.Conventions/Web/IRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GraphQL.Conventions.Web
{
public interface IRequestHandler
{
Task<Response> ProcessRequest(Request request, IUserContext userContext);
Task<Response> ProcessRequest(Request request, IUserContext userContext, IDependencyInjector dependencyInjector = null);

Response Validate(Request request);

Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.Conventions/Web/RequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ internal RequestHandlerImpl(
}
}

public async Task<Response> ProcessRequest(Request request, IUserContext userContext)
public async Task<Response> ProcessRequest(Request request, IUserContext userContext, IDependencyInjector dependencyInjector = null)
{
var result = await _engine
.NewExecutor()
.WithQueryString(request.QueryString)
.WithInputs(request.Variables)
.WithOperationName(request.OperationName)
.WithDependencyInjector(_dependencyInjector)
.WithDependencyInjector(dependencyInjector ?? _dependencyInjector)
.WithUserContext(userContext)
.WithComplexityConfiguration(_complexityConfiguration)
.EnableValidation(_useValidation)
Expand Down
12 changes: 6 additions & 6 deletions test/Tests/Web/RequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task Can_Run_Query()
.New()
.WithQuery<TestQuery>()
.Generate()
.ProcessRequest(request, null);
.ProcessRequest(request, null, null);

response.ExecutionResult.Data.ShouldHaveFieldWithValue("hello", "World");
response.Body.ShouldEqual("{\"data\":{\"hello\":\"World\"}}");
Expand All @@ -34,7 +34,7 @@ public async Task Can_Run_Simple_Query_Using_ComplexityConfiguration()
.WithQuery<TestQuery>()
.WithComplexityConfiguration(new ComplexityConfiguration { MaxDepth = 2 })
.Generate()
.ProcessRequest(request, null);
.ProcessRequest(request, null, null);

response.ExecutionResult.Data.ShouldHaveFieldWithValue("hello", "World");
response.Body.ShouldEqual("{\"data\":{\"hello\":\"World\"}}");
Expand All @@ -51,7 +51,7 @@ public async Task Cannot_Run_Too_Complex_Query_Using_ComplexityConfiguration()
.WithQuery<TestQuery>()
.WithComplexityConfiguration(new ComplexityConfiguration { MaxDepth = 1 })
.Generate()
.ProcessRequest(request, null);
.ProcessRequest(request, null, null);

response.Errors.Count.ShouldEqual(1);
response.Errors[0].Message.ShouldEqual("Query is too nested to execute. Depth is 2 levels, maximum allowed on this endpoint is 1.");
Expand All @@ -66,7 +66,7 @@ public async Task Can_Enrich_With_Profiling_Information()
.WithQuery<ProfiledQuery>()
.WithProfiling()
.Generate()
.ProcessRequest(request, null);
.ProcessRequest(request, null, null);
response.EnrichWithProfilingInformation();
response.Body.ShouldContain("\"extensions\":{\"profile\":");
}
Expand All @@ -80,7 +80,7 @@ public async Task Can_Ignore_Types_From_Unwanted_Namespaces()
.New()
.WithQuery<CompositeQuery>()
.Generate()
.ProcessRequest(request, null);
.ProcessRequest(request, null, null);
response.Body.ShouldEqual("{\"data\":{\"earth\":{\"hello\":\"World\"},\"mars\":{\"hello\":\"World From Mars\"}}}");

// Exclude types from 'Unwanted' namespace, i.e. TypeQuery2 from CompositeQuery schema
Expand All @@ -90,7 +90,7 @@ public async Task Can_Ignore_Types_From_Unwanted_Namespaces()
.IgnoreTypesFromNamespacesStartingWith("GraphQL.Conventions.Tests.Web.Unwanted")
.WithQuery<CompositeQuery>()
.Generate()
.ProcessRequest(request, null);
.ProcessRequest(request, null, null);
response.Errors.Count.ShouldEqual(1);
response.Errors[0].Message.ShouldContain("Cannot query field \"hello\" on type \"TestQuery2\".");
response.Body.ShouldContain("VALIDATION_ERROR");
Expand Down

0 comments on commit 751f8ae

Please sign in to comment.