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 for ListType payload #4653

Merged
merged 3 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -430,7 +430,7 @@ private ITypeNode CreateTypeNode(IType type)
=> type switch
{
NonNullType nnt => new NonNullTypeNode((INullableTypeNode)CreateTypeNode(nnt.Type)),
ListType lt => new ListTypeNode((INullableTypeNode)CreateTypeNode(lt.ElementType)),
ListType lt => new ListTypeNode(CreateTypeNode(lt.ElementType)),
INamedType nt => new NamedTypeNode(nt.Name),
_ => throw new NotSupportedException("Type is not supported.")
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@ public async Task SimpleMutation_Inferred()
.MatchSnapshotAsync();
}

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

await new ServiceCollection()
.AddGraphQL()
.AddMutationType<SimpleMutationReturnList>()
.AddMutationConventions(
new MutationConventionOptions
{
ApplyToAllMutations = true
})
.ModifyOptions(o => o.StrictValidation = false)
.BuildSchemaAsync()
.MatchSnapshotAsync();
}

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

await new ServiceCollection()
.AddGraphQL()
.AddMutationType<SimpleMutationReturnList>()
.AddMutationConventions(
new MutationConventionOptions
{
ApplyToAllMutations = true
})
.ModifyOptions(o => o.StrictValidation = false)
.ExecuteRequestAsync(
@"mutation {
doSomething(input: { something: ""abc"" }) {
string
}
}")
.MatchSnapshotAsync();
}

[Fact]
public async Task SimpleMutation_Inferred_With_QueryField()
{
Expand Down Expand Up @@ -397,6 +438,11 @@ public string DoSomething(string something)
=> something;
}

public class SimpleMutationReturnList
{
public System.Collections.Generic.List<string> DoSomething(string something) => new() { something };
}

[ExtendObjectType("Mutation")]
public class SimpleMutationExtension
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
schema {
mutation: SimpleMutationReturnList
}

type DoSomethingPayload {
string: [String!]
}

type SimpleMutationReturnList {
doSomething(input: DoSomethingInput!): DoSomethingPayload!
}

input DoSomethingInput {
something: String!
}

"The `@defer` directive may be provided for fragment spreads and inline fragments to inform the executor to delay the execution of the current fragment to indicate deprioritization of the current fragment. A query with `@defer` directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred is delivered in a subsequent response. `@include` and `@skip` take precedence over `@defer`."
directive @defer("If this argument label has a value other than null, it will be passed on to the result of this defer directive. This label is intended to give client applications a way to identify to which fragment a deferred result belongs to." label: String "Deferred when true." if: Boolean) on FRAGMENT_SPREAD | INLINE_FRAGMENT

"The `@stream` directive may be provided for a field of `List` type so that the backend can leverage technology such as asynchronous iterators to provide a partial list in the initial response, and additional list items in subsequent responses. `@include` and `@skip` take precedence over `@stream`."
directive @stream("If this argument label has a value other than null, it will be passed on to the result of this stream directive. This label is intended to give client applications a way to identify to which fragment a streamed result belongs to." label: String "The initial elements that shall be send down to the consumer." initialCount: Int! = 0 "Streamed when true." if: Boolean) on FIELD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"data": {
"doSomething": {
"string": [
"abc"
]
}
}
}