Skip to content

Commit

Permalink
Changed scalar binding behavior (#1386)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jan 16, 2020
1 parent bad41c6 commit 6eb64e1
Show file tree
Hide file tree
Showing 58 changed files with 406 additions and 411 deletions.
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using HotChocolate.Execution.Configuration;
using HotChocolate.Language;
using HotChocolate.Types;
using HotChocolate.Utilities;
using Moq;
using Snapshooter;
Expand All @@ -21,18 +22,21 @@ public class MaxComplexityMiddlewareTests
int count, bool valid)
{
// arrange
var schema = Schema.Create(
@"
type Query {
foo(i: Int): String
@cost(complexity: 5 multipliers: [""i""])
}
",
c =>
{
c.BindResolver(() => "Hello")
.To("Query", "foo");
});
var schema = SchemaBuilder.New()
.AddDocumentFromString(
@"
type Query {
foo(i: Int): String
@cost(complexity: 5 multipliers: [""i""])
}
input FooInput {
index : Int
}
")
.AddDirectiveType<CostDirectiveType>()
.AddResolver("Query", "foo", "Hello")
.Create();

var options = new Mock<IValidateQueryOptionsAccessor>();
options.SetupGet(t => t.MaxOperationComplexity).Returns(20);
Expand Down Expand Up @@ -106,18 +110,21 @@ public class MaxComplexityMiddlewareTests
int count, bool valid)
{
// arrange
var schema = Schema.Create(
@"
type Query {
foo(i: Int): String
@cost(complexity: 5 multipliers: [""i""])
}
",
c =>
{
c.BindResolver(() => "Hello")
.To("Query", "foo");
});
var schema = SchemaBuilder.New()
.AddDocumentFromString(
@"
type Query {
foo(i: Int): String
@cost(complexity: 5 multipliers: [""i""])
}
input FooInput {
index : Int
}
")
.AddDirectiveType<CostDirectiveType>()
.AddResolver("Query", "foo", "Hello")
.Create();

var options = new Mock<IValidateQueryOptionsAccessor>();
options.SetupGet(t => t.MaxOperationComplexity).Returns(20);
Expand Down Expand Up @@ -194,22 +201,21 @@ public class MaxComplexityMiddlewareTests
int count, bool valid)
{
// arrange
var schema = Schema.Create(
@"
type Query {
foo(i: FooInput): String
@cost(complexity: 5 multipliers: [""i.index""])
}
input FooInput {
index : Int
}
",
c =>
{
c.BindResolver(() => "Hello")
.To("Query", "foo");
});
var schema = SchemaBuilder.New()
.AddDocumentFromString(
@"
type Query {
foo(i: FooInput): String
@cost(complexity: 5 multipliers: [""i.index""])
}
input FooInput {
index : Int
}
")
.AddDirectiveType<CostDirectiveType>()
.AddResolver("Query", "foo", "Hello")
.Create();

var options = new Mock<IValidateQueryOptionsAccessor>();
options.SetupGet(t => t.MaxOperationComplexity).Returns(20);
Expand Down Expand Up @@ -283,22 +289,21 @@ public class MaxComplexityMiddlewareTests
int count, bool valid)
{
// arrange
var schema = Schema.Create(
@"
type Query {
var schema = SchemaBuilder.New()
.AddDocumentFromString(
@"
type Query {
foo(i: FooInput): String
@cost(complexity: 5 multipliers: [""i.index""])
}
input FooInput {
index : Int
}
",
c =>
{
c.BindResolver(() => "Hello")
.To("Query", "foo");
});
")
.AddDirectiveType<CostDirectiveType>()
.AddResolver("Query", "foo", "Hello")
.Create();

var options = new Mock<IValidateQueryOptionsAccessor>();
options.SetupGet(t => t.MaxOperationComplexity).Returns(20);
Expand Down Expand Up @@ -389,6 +394,7 @@ public async Task Validate_Multiple_Levels_Valid()
baz: String
}
")
.AddDirectiveType<CostDirectiveType>()
.Use(next => context =>
{
context.Result = "baz";
Expand Down Expand Up @@ -432,6 +438,7 @@ public async Task Validate_Multiple_Levels_Invalid()
baz: String
}
")
.AddDirectiveType<CostDirectiveType>()
.Use(next => context =>
{
context.Result = "baz";
Expand Down
Expand Up @@ -618,6 +618,7 @@ private Schema CreateSchema()
c =>
{
c.Use(next => context => Task.CompletedTask);
c.RegisterType<IntType>();
c.RegisterType<BarType>();
c.RegisterType<FooType>();
c.RegisterType<BazType>();
Expand Down
@@ -0,0 +1 @@
{ bar: [ { bar: [ "def" ] } ] }
Expand Up @@ -924,26 +924,6 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "Int",
"description": "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "MultiplierPath",
"description": "The multiplier path scalar represents a valid GraphQL multiplier path string.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "Baz",
Expand Down Expand Up @@ -1013,47 +993,6 @@
"onFragment": true,
"onField": true
},
{
"name": "cost",
"description": "The cost directives is used to express the complexity of a field.",
"args": [
{
"name": "complexity",
"description": "Defines the complexity of the field.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"defaultValue": "1"
},
{
"name": "multipliers",
"description": "Defines field arguments that act as complexity multipliers.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "MultiplierPath",
"ofType": null
}
}
},
"defaultValue": null
}
],
"onOperation": false,
"onFragment": false,
"onField": false
},
{
"name": "deprecated",
"description": "The @deprecated directive is used within the type system definition language to indicate deprecated portions of a GraphQL service’s schema,such as deprecated fields on a type or deprecated enum values.",
Expand Down
Expand Up @@ -1015,26 +1015,6 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "Int",
"description": "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "MultiplierPath",
"description": "The multiplier path scalar represents a valid GraphQL multiplier path string.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Foo",
Expand Down Expand Up @@ -1106,47 +1086,6 @@
"onFragment": true,
"onField": true
},
{
"name": "cost",
"description": "The cost directives is used to express the complexity of a field.",
"args": [
{
"name": "complexity",
"description": "Defines the complexity of the field.",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"defaultValue": "1"
},
{
"name": "multipliers",
"description": "Defines field arguments that act as complexity multipliers.",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "MultiplierPath",
"ofType": null
}
}
},
"defaultValue": null
}
],
"onOperation": false,
"onFragment": false,
"onField": false
},
{
"name": "deprecated",
"description": "The @deprecated directive is used within the type system definition language to indicate deprecated portions of a GraphQL service’s schema,such as deprecated fields on a type or deprecated enum values.",
Expand Down
Expand Up @@ -210,7 +210,7 @@ public class ByteArrayType
: ScalarType
{
public ByteArrayType()
: base("ByteArray")
: base("ByteArray", BindingBehavior.Implicit)
{
}

Expand Down
Expand Up @@ -6,12 +6,9 @@
"Output: HotChocolate.ISchema": "Output: HotChocolate.Types.Introspection.__Schema",
"Output: HotChocolate.Types.IType": "Output: HotChocolate.Types.Introspection.__Type",
"None: HotChocolate.Types.TypeKind": "None: HotChocolate.Types.Introspection.__TypeKind",
"None: HotChocolate.Types.CostDirective": "None: HotChocolate.Types.CostDirectiveType",
"None: System.String": "None: HotChocolate.Types.StringType",
"None: System.Boolean": "None: HotChocolate.Types.BooleanType",
"None: HotChocolate.Types.DeprecatedDirective": "None: HotChocolate.Types.DeprecatedDirectiveType",
"None: System.Int32": "None: HotChocolate.Types.IntType",
"None: HotChocolate.Types.MultiplierPathString": "None: HotChocolate.Types.MultiplierPathType",
"Output: HotChocolate.Configuration.TypeDiscovererTests.Foo": "Output: HotChocolate.Types.ObjectType<HotChocolate.Configuration.TypeDiscovererTests.Foo>",
"Output: HotChocolate.Configuration.TypeDiscovererTests.Bar": "Output: HotChocolate.Types.ObjectType<HotChocolate.Configuration.TypeDiscovererTests.Bar>"
}
Expand Up @@ -9,12 +9,9 @@
"HotChocolate.Types.Introspection.__TypeKind": "HotChocolate.Types.TypeKind",
"HotChocolate.Types.SkipDirectiveType": "System.Object",
"HotChocolate.Types.IncludeDirectiveType": "System.Object",
"HotChocolate.Types.CostDirectiveType": "HotChocolate.Types.CostDirective",
"HotChocolate.Types.StringType": "System.String",
"HotChocolate.Types.BooleanType": "System.Boolean",
"HotChocolate.Types.DeprecatedDirectiveType": "HotChocolate.Types.DeprecatedDirective",
"HotChocolate.Types.IntType": "System.Int32",
"HotChocolate.Types.MultiplierPathType": "HotChocolate.Types.MultiplierPathString",
"HotChocolate.Types.ObjectType<HotChocolate.Configuration.TypeDiscovererTests.Foo>": "HotChocolate.Configuration.TypeDiscovererTests.Foo",
"HotChocolate.Types.ObjectType<HotChocolate.Configuration.TypeDiscovererTests.Bar>": "HotChocolate.Configuration.TypeDiscovererTests.Bar"
}
Expand Up @@ -6,12 +6,9 @@
"Output: HotChocolate.ISchema": "Output: HotChocolate.Types.Introspection.__Schema",
"Output: HotChocolate.Types.IType": "Output: HotChocolate.Types.Introspection.__Type",
"None: HotChocolate.Types.TypeKind": "None: HotChocolate.Types.Introspection.__TypeKind",
"None: HotChocolate.Types.CostDirective": "None: HotChocolate.Types.CostDirectiveType",
"Output: HotChocolate.Configuration.TypeDiscovererTests.Foo": "Output: HotChocolate.Configuration.TypeDiscovererTests+FooType",
"None: System.String": "None: HotChocolate.Types.StringType",
"None: System.Boolean": "None: HotChocolate.Types.BooleanType",
"None: HotChocolate.Types.DeprecatedDirective": "None: HotChocolate.Types.DeprecatedDirectiveType",
"None: System.Int32": "None: HotChocolate.Types.IntType",
"None: HotChocolate.Types.MultiplierPathString": "None: HotChocolate.Types.MultiplierPathType",
"Output: HotChocolate.Configuration.TypeDiscovererTests.Bar": "Output: HotChocolate.Configuration.TypeDiscovererTests+BarType"
}
Expand Up @@ -9,12 +9,9 @@
"HotChocolate.Types.Introspection.__TypeKind": "HotChocolate.Types.TypeKind",
"HotChocolate.Types.SkipDirectiveType": "System.Object",
"HotChocolate.Types.IncludeDirectiveType": "System.Object",
"HotChocolate.Types.CostDirectiveType": "HotChocolate.Types.CostDirective",
"HotChocolate.Configuration.TypeDiscovererTests.FooType": "HotChocolate.Configuration.TypeDiscovererTests.Foo",
"HotChocolate.Types.StringType": "System.String",
"HotChocolate.Types.BooleanType": "System.Boolean",
"HotChocolate.Types.DeprecatedDirectiveType": "HotChocolate.Types.DeprecatedDirective",
"HotChocolate.Types.IntType": "System.Int32",
"HotChocolate.Types.MultiplierPathType": "HotChocolate.Types.MultiplierPathString",
"HotChocolate.Configuration.TypeDiscovererTests.BarType": "HotChocolate.Configuration.TypeDiscovererTests.Bar"
}
Expand Up @@ -6,12 +6,9 @@
"Output: HotChocolate.ISchema": "Output: HotChocolate.Types.Introspection.__Schema",
"Output: HotChocolate.Types.IType": "Output: HotChocolate.Types.Introspection.__Type",
"None: HotChocolate.Types.TypeKind": "None: HotChocolate.Types.Introspection.__TypeKind",
"None: HotChocolate.Types.CostDirective": "None: HotChocolate.Types.CostDirectiveType",
"Output: HotChocolate.Configuration.TypeDiscovererTests.Foo": "Output: HotChocolate.Types.ObjectType<HotChocolate.Configuration.TypeDiscovererTests.Foo>",
"None: System.String": "None: HotChocolate.Types.StringType",
"None: System.Boolean": "None: HotChocolate.Types.BooleanType",
"None: HotChocolate.Types.DeprecatedDirective": "None: HotChocolate.Types.DeprecatedDirectiveType",
"None: System.Int32": "None: HotChocolate.Types.IntType",
"None: HotChocolate.Types.MultiplierPathString": "None: HotChocolate.Types.MultiplierPathType",
"Output: HotChocolate.Configuration.TypeDiscovererTests.Bar": "Output: HotChocolate.Configuration.TypeDiscovererTests+BarType"
}

0 comments on commit 6eb64e1

Please sign in to comment.