Skip to content

Commit

Permalink
Merge pull request #42 from graphql-dotnet/custom-validation-rules
Browse files Browse the repository at this point in the history
Allow custom validation rules to be passed in
  • Loading branch information
tlil authored May 4, 2017
2 parents 540b954 + ff85785 commit e256efc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ internal async Task<ExecutionResult> Execute(
OperationName = operationName,
Inputs = inputs,
UserContext = userContext,
ValidationRules = rules,
ValidationRules = rules != null && rules.Any() ? rules : null,
CancellationToken = cancellationToken,
};

Expand Down
10 changes: 9 additions & 1 deletion src/GraphQL.Conventions/Adapters/Engine/GraphQLExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class GraphQLExecutor : IGraphQLExecutor<ExecutionResult>

private bool _enableProfiling = false;

private IEnumerable<IValidationRule> _validationRules = null;

internal GraphQLExecutor(GraphQLEngine engine, IRequestDeserializer requestDeserializer)
{
_engine = engine;
Expand Down Expand Up @@ -83,6 +85,12 @@ public IGraphQLExecutor<ExecutionResult> WithDependencyInjector(IDependencyInjec
return this;
}

public IGraphQLExecutor<ExecutionResult> WithValidationRules(IEnumerable<IValidationRule> rules)
{
_validationRules = rules;
return this;
}

public IGraphQLExecutor<ExecutionResult> EnableValidation(bool enableValidation = true)
{
_enableValidation = enableValidation;
Expand Down Expand Up @@ -111,7 +119,7 @@ await _engine
_rootObject, _queryString, _operationName, _inputs, _userContext,
enableValidation: _enableValidation,
enableProfiling: _enableProfiling,
rules: null,
rules: _validationRules,
cancellationToken: _cancellationToken)
.ConfigureAwait(false);

Expand Down
3 changes: 3 additions & 0 deletions src/GraphQL.Conventions/Adapters/Engine/IGraphQLExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using GraphQL.Validation;

namespace GraphQL.Conventions
{
Expand All @@ -22,6 +23,8 @@ public interface IGraphQLExecutor<TResult>

IGraphQLExecutor<TResult> WithDependencyInjector(IDependencyInjector injector);

IGraphQLExecutor<TResult> WithValidationRules(IEnumerable<IValidationRule> rules);

IGraphQLExecutor<TResult> EnableValidation(bool enableValidation = true);

IGraphQLExecutor<TResult> DisableValidation();
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.Conventions/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[assembly: AssemblyCopyright("Copyright 2016-2017 Tommy Lillehagen. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.2.4")]
[assembly: AssemblyInformationalVersion("1.2.4")]
[assembly: AssemblyFileVersion("1.2.5")]
[assembly: AssemblyInformationalVersion("1.2.5")]
[assembly: CLSCompliant(false)]

[assembly: InternalsVisibleTo("GraphQL.Conventions.Tests")]
2 changes: 1 addition & 1 deletion src/GraphQL.Conventions/GraphQL.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>GraphQL Conventions for .NET</Description>
<VersionPrefix>1.2.4</VersionPrefix>
<VersionPrefix>1.2.5</VersionPrefix>
<Authors>Tommy Lillehagen</Authors>
<TargetFrameworks>netstandard1.5;net45</TargetFrameworks>
<DebugType>portable</DebugType>
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL.Conventions/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.2.4-*",
"version": "1.2.5-*",
"description": "GraphQL Conventions for .NET",
"authors": [
"Tommy Lillehagen"
Expand Down

0 comments on commit e256efc

Please sign in to comment.