Skip to content

Commit

Permalink
Fixed mutation convention for ListType payload (#4653)
Browse files Browse the repository at this point in the history
  • Loading branch information
horse315 committed Jan 15, 2022
1 parent 9bc3803 commit 9d253df
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
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
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
@@ -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
@@ -0,0 +1,9 @@
{
"data": {
"doSomething": {
"string": [
"abc"
]
}
}
}

0 comments on commit 9d253df

Please sign in to comment.