-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from graphql-dotnet/null-literals
Null literals
- Loading branch information
Showing
12 changed files
with
210 additions
and
20 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
deps/graphql-dotnet/src/GraphQL.Tests/Bugs/NullArgumentTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
using GraphQL.Types; | ||
using Shouldly; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace GraphQL.Tests.Bugs | ||
{ | ||
public class NullArguments : QueryTestBase<NullMutationSchema> | ||
{ | ||
[Fact] | ||
public void Supports_partially_nullable_fields_on_arguments() | ||
{ | ||
var query = @" | ||
mutation { | ||
run(input: {id:null, foo:null,bar:null}) | ||
} | ||
"; | ||
var expected = @"{ | ||
""run"": ""idfoobar"" | ||
}"; | ||
AssertQuerySuccess(query, expected, null); | ||
} | ||
|
||
[Fact] | ||
public void Supports_non_null_int() | ||
{ | ||
var query = @" | ||
mutation { | ||
run(input: {id:105, foo:null,bar:{id: null, foo:""a"", bar:{id:101}}}) | ||
} | ||
"; | ||
|
||
var result = AssertQueryWithErrors(query, null, null, expectedErrorCount: 1); | ||
|
||
var caughtError = result.Errors.Single(); | ||
caughtError.ShouldNotBeNull(); | ||
caughtError?.InnerException.ShouldBeNull(); | ||
caughtError?.Message.Contains("In field \"bar\": In field \"id\": Expected \"Int!\", found null."); | ||
} | ||
|
||
[Fact] | ||
public void Supports_non_null_string() | ||
{ | ||
var query = @" | ||
mutation { | ||
run(input: {id:105, foo:null,bar:{id: 1, foo:null, bar:{id:101}}}) | ||
} | ||
"; | ||
|
||
var result = AssertQueryWithErrors(query, null, null, expectedErrorCount: 1); | ||
|
||
var caughtError = result.Errors.Single(); | ||
caughtError.ShouldNotBeNull(); | ||
caughtError?.InnerException.ShouldBeNull(); | ||
caughtError?.Message.Contains("In field \"foo\": Expected \"String!\", found null."); | ||
} | ||
|
||
[Fact] | ||
public void Supports_non_null_object() | ||
{ | ||
var query = @" | ||
mutation { | ||
run(input: {id:105, foo:null,bar:{id: 1, foo:""abc"", bar:null}}) | ||
} | ||
"; | ||
|
||
var result = AssertQueryWithErrors(query, null, null, expectedErrorCount: 1); | ||
|
||
var caughtError = result.Errors.Single(); | ||
caughtError.ShouldNotBeNull(); | ||
caughtError?.InnerException.ShouldBeNull(); | ||
caughtError?.Message.Contains("In field \"bar\": Expected \"NonNullSubChild!\", found null."); | ||
} | ||
} | ||
|
||
public class NullMutationSchema : Schema | ||
{ | ||
public NullMutationSchema() | ||
{ | ||
Mutation = new NullMutation(); | ||
} | ||
} | ||
|
||
public class NullMutation : ObjectGraphType | ||
{ | ||
public NullMutation() | ||
{ | ||
Name = "MyMutation"; | ||
Field<StringGraphType>( | ||
"run", | ||
arguments: new QueryArguments(new QueryArgument<NullInputRoot> { Name = "input" }), | ||
resolve: ctx => | ||
{ | ||
var arg = ctx.GetArgument<NullInputClass>("input"); | ||
var r= (arg.Id == null ? "id" : string.Empty) + | ||
(arg.Foo == null ? "foo" : string.Empty) + | ||
(arg.Bar == null ? "bar" : string.Empty); | ||
return r; | ||
}); | ||
} | ||
} | ||
|
||
public class NullInputClass | ||
{ | ||
public int? Id { get; set; } | ||
public string Foo { get; set; } | ||
public NullInputChildClass Bar { get; set; } | ||
} | ||
|
||
public class NullInputChildClass | ||
{ | ||
public int? Id { get; set; } | ||
public string Foo { get; set; } | ||
public NullInputSubChildClass Bar { get; set; } | ||
} | ||
|
||
public class NullInputSubChildClass | ||
{ | ||
public int? Id { get; set; } | ||
} | ||
|
||
public class NullInputRoot : InputObjectGraphType | ||
{ | ||
public NullInputRoot() | ||
{ | ||
Name = "NullInputRoot"; | ||
Field<IntGraphType>("id"); | ||
Field<StringGraphType>("foo"); | ||
Field<NonNullChild>("bar"); | ||
} | ||
} | ||
|
||
public class NonNullChild : InputObjectGraphType | ||
{ | ||
public NonNullChild() | ||
{ | ||
Name = "NonNullChild"; | ||
Field<NonNullGraphType<IntGraphType>>("id"); | ||
Field<NonNullGraphType<StringGraphType>>("foo"); | ||
Field<NonNullGraphType<NonNullSubChild>>("bar"); | ||
} | ||
} | ||
|
||
public class NonNullSubChild : InputObjectGraphType | ||
{ | ||
public NonNullSubChild() | ||
{ | ||
Name = "NonNullSubChild"; | ||
Field<NonNullGraphType<IntGraphType>>("id"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
deps/graphql-dotnet/src/GraphQL.Tests/Introspection/IntrospectionResult.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace GraphQL.Language.AST | ||
{ | ||
public class NullValue : AbstractNode, IValue | ||
{ | ||
public override string ToString() | ||
{ | ||
return "null"; | ||
} | ||
|
||
public override bool IsEqualTo(INode obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return true; | ||
if (ReferenceEquals(this, obj)) return true; | ||
return obj.GetType() == this.GetType(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters