Skip to content

Commit

Permalink
New validation (#48)
Browse files Browse the repository at this point in the history
+semver: minor
  • Loading branch information
pekkah authored Feb 28, 2019
1 parent 9310f4b commit 40da2cd
Show file tree
Hide file tree
Showing 68 changed files with 4,048 additions and 2,224 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tanka GraphQL library
## Features

* Execute queries, mutations and subscriptions
* Validation (Dirty port from graphql-dotnet). Validation is the slowest part of the execution and needs to be redone.
* Validation (new implementation in v0.3.0)
* SignalR hub for streaming queries, mutations and subscriptions
* ApolloLink for the provided SignalR hub

Expand Down
16 changes: 12 additions & 4 deletions docs/1-execution/01-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@

### Execution

[{tanka.graphql.tests.validation.ValidatorFacts.ValidateAsync}]
[{tanka.graphql.tests.validation.ValidatorFacts.Validate}]


### Rules

5.1.1 Executable Definitions
Execution

[{tanka.graphql.validation.ExecutionRules.All}]

Rules not implemented
[{tanka.graphql.tests.validation.ValidatorFacts.Rule_532_Field_Selection_Merging}]
[{tanka.graphql.tests.validation.ValidatorFacts.Rule_572_DirectivesAreInValidLocations_valid1}]
[{tanka.graphql.tests.validation.ValidatorFacts.Rule_583_AllVariableUsesDefined}]
[{tanka.graphql.tests.validation.ValidatorFacts.Rule_584_AllVariablesUsed_valid1}]
[{tanka.graphql.tests.validation.ValidatorFacts.Rule_585_AllVariableUsagesAreAllowed_valid1}]


[{tanka.graphql.tests.validation.ValidatorFacts.Rule_511_Executable_Definitions}]

>TODO: Rest of the rules. Issue [#16](https://github.com/pekkah/tanka-graphql/issues/16)

2 changes: 1 addition & 1 deletion docs/_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">Tanka GraphQL</a>
<ul class="navbar-nav px-3">
<li class="nav-item text-nowrap">
<a class="nav-link" href="https://github.com/pekkah/tanka-docs-gen">GitHub</a>
<a class="nav-link" href="https://github.com/pekkah/tanka-graphql">GitHub</a>
</li>
</ul>
</nav>
Expand Down
11 changes: 7 additions & 4 deletions src/graphql.benchmarks/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Benchmarks
private ISchema _schema;
private GraphQLDocument _mutation;
private GraphQLDocument _subscription;
private IEnumerable<CombineRule> _defaultRulesMap;

[GlobalSetup]
public async Task Setup()
Expand All @@ -28,8 +29,9 @@ public async Task Setup()
_query = Utils.InitializeQuery();
_mutation = Utils.InitializeMutation();
_subscription = Utils.InitializeSubscription();
_defaultRulesMap = ExecutionRules.All;
}

[Benchmark]
public async Task Query_with_defaults()
{
Expand Down Expand Up @@ -135,11 +137,12 @@ public async Task Subscribe_without_validation_and_get_value()
var value = result.Source.Receive();
AssertResult(value.Errors);
}

[Benchmark]
public async Task Validate_query_with_defaults()
public void Validate_query_with_defaults()
{
var result = await Validator.ValidateAsync(
var result = Validator.Validate(
_defaultRulesMap,
_schema,
_query);

Expand Down
2 changes: 1 addition & 1 deletion src/graphql/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Error(string message)
public string Message { get; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<GraphQLLocation> Locations { get; set; }
public List<GraphQLLocation> Locations { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<object> Path { get; set; }
Expand Down
7 changes: 4 additions & 3 deletions src/graphql/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static async Task<ExecutionResult> ExecuteAsync(
if (!validationResult.IsValid)
return new ExecutionResult
{
Errors = validationResult.Errors.Select(e => new Error(e.Message))
Errors = validationResult.Errors.Select(e =>e.ToError())
};

ExecutionResult executionResult;
Expand Down Expand Up @@ -141,10 +141,11 @@ public static async Task<SubscriptionResult> SubscribeAsync(
if (options.Validate)
{
await extensions.BeginValidationAsync();
validationResult = await Validator.ValidateAsync(
validationResult = Validator.Validate(
ExecutionRules.All,
options.Schema,
document,
coercedVariableValues).ConfigureAwait(false);
coercedVariableValues);

logger.ValidationResult(validationResult);

Expand Down
3 changes: 1 addition & 2 deletions src/graphql/graphql.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -20,5 +20,4 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
</ItemGroup>

</Project>
Loading

0 comments on commit 40da2cd

Please sign in to comment.