Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mutation convention with ID attribute #4639

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async ValueTask InvokeAsync(IMiddlewareContext context)
new ArgumentValue(
argument,
kind,
inputArgument.IsFullyCoerced,
true,
inputArgument.IsDefaultValue,
value,
valueLiteral));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ private static InputObjectType CreateInputType(
{
var inputFieldDef = new InputFieldDefinition();
argumentDef.CopyTo(inputFieldDef);

inputFieldDef.RuntimeType =
argumentDef.RuntimeType ?? argumentDef.Parameter.ParameterType;

inputObjectDef.Fields.Add(inputFieldDef);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal void CopyTo(ArgumentDefinition target)
target.DefaultValue = DefaultValue;
target.RuntimeDefaultValue = RuntimeDefaultValue;
target.Parameter = Parameter;
target.RuntimeType = target.RuntimeType;
target.RuntimeType = RuntimeType;
}

internal void MergeInto(ArgumentDefinition target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Tests;
using HotChocolate.Types.Relay;
using Microsoft.Extensions.DependencyInjection;
using Snapshooter.Xunit;
using Xunit;
Expand Down Expand Up @@ -346,6 +347,50 @@ public async Task Allow_Payload_Result_Field_To_Be_Null()
.MatchSnapshotAsync();
}

[Fact]
public async Task Allow_Id_Middleware()
{
Snapshot.FullName();

await new ServiceCollection()
.AddGraphQL()
.AddMutationType<MutationWithIds>()
.AddMutationConventions(true)
.ModifyOptions(o => o.StrictValidation = false)
.ExecuteRequestAsync(
@"mutation {
doSomething(input: {
id: ""Rm9vCmdhYWY1ZjAzNjk0OGU0NDRkYWRhNTM2ZTY1MTNkNTJjZA==""
}) {
user { name id }
}
}")
.MatchSnapshotAsync();
}

[Fact]
public async Task Allow_InputObject_Middleware()
{
Snapshot.FullName();

await new ServiceCollection()
.AddGraphQL()
.AddMutationType<MutationWithInputObject>()
.AddMutationConventions(true)
.ModifyOptions(o => o.StrictValidation = false)
.ExecuteRequestAsync(
@"mutation {
doSomething(input: {
test: {
name: ""foo""
}
}) {
user { name }
}
}")
.MatchSnapshotAsync();
}

public class SimpleMutation
{
public string DoSomething(string something)
Expand Down Expand Up @@ -411,6 +456,28 @@ public class DoSomethingInput
public string MyInput2 { get; set; } = default!;
}

public class MutationWithIds
{
public User? DoSomething([ID("Foo")]Guid id)
{
return new User() {Name = "Foo", Id = id,};
}
}

public class MutationWithInputObject
{
public User? DoSomething(Test test)
{
return new User() {Name = test.Name};
}
}

public class Test
{
public string Name { get; set; }

}

public class MultipleArgumentMutation
{
public string DoSomething(string something1, string something2)
Expand Down Expand Up @@ -460,6 +527,8 @@ public class MutationWithInputPayload

public class User
{
public Guid Id { get; set; }

public string? Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"data": {
"doSomething": {
"user": {
"name": "Foo",
"id": "aaf5f036-948e-444d-ada5-36e6513d52cd"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"data": {
"doSomething": {
"user": {
"name": "foo"
}
}
}
}