Skip to content
Open
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 @@ -584,10 +584,7 @@ private static void AddFileMapMethods(
{
if (argument.Type.NamedType() is InputObjectTypeDescriptor { HasUpload: true } type)
{
if (processed.Add(argument.Type.NamedType().Name))
{
AddMapFilesOfInputTypeMethod(classBuilder, type);
}
AddMapFilesOfInputTypeMethod(classBuilder, type, processed);
}
else if (argument.Type.NamedType() is not ScalarTypeDescriptor { Name: "Upload" })
{
Expand All @@ -605,9 +602,10 @@ private static void AddFileMapMethods(

private static void AddMapFilesOfInputTypeMethod(
ClassBuilder builder,
InputObjectTypeDescriptor type)
InputObjectTypeDescriptor type,
HashSet<string> processed)
{
if (!type.HasUpload)
if (!type.HasUpload || !processed.Add(type.Name))
{
return;
}
Expand Down Expand Up @@ -642,7 +640,7 @@ private static void AddMapFilesOfInputTypeMethod(

if (field.Type.NamedType() is InputObjectTypeDescriptor nextType)
{
AddMapFilesOfInputTypeMethod(builder, nextType);
AddMapFilesOfInputTypeMethod(builder, nextType, processed);
}
}
}
Expand Down Expand Up @@ -700,7 +698,9 @@ private static ICode BuildUploadFileMapper(
.New()
.SetMethodName(Files, "Add")
.AddArgument(pathVariable)
.AddArgument($"{variable} is {TypeNames.Upload} u ? u : null"));
.AddArgument(
$"{variable} is {TypeNames.Upload} {checkedVariable} "
+ $"? {checkedVariable} : null"));

default:
throw ThrowHelper.OperationServiceGenerator_HasNoUploadScalar(typeReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ private TestUploadQuery(global::StrawberryShake.IOperationExecutor<ITestUploadRe

private void MapFilesFromArgumentSingle(global::System.String path, global::StrawberryShake.Upload? value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
{
files.Add(path, value is global::StrawberryShake.Upload u ? u : null);
files.Add(path, value is global::StrawberryShake.Upload value_i ? value_i : null);
}

private void MapFilesFromArgumentList(global::System.String path, global::System.Collections.Generic.IReadOnlyList<global::StrawberryShake.Upload?>? value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand All @@ -692,7 +692,7 @@ private void MapFilesFromArgumentList(global::System.String path, global::System
foreach (var value_lt in value_i)
{
var path_lt = path + "." + (path_counter++);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload value_lt_i ? value_lt_i : null);
}
}
}
Expand All @@ -711,7 +711,7 @@ private void MapFilesFromArgumentNested(global::System.String path, global::Syst
foreach (var value_lt_lt in value_lt_i)
{
var path_lt_lt = path_lt + "." + (path_lt_counter++);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload value_lt_lt_i ? value_lt_lt_i : null);
}
}
}
Expand Down Expand Up @@ -742,7 +742,7 @@ private void MapFilesFromTypeBazInput(global::System.String path, global::Strawb
{
var pathFile = path + ".file";
var valueFile = value.File;
files.Add(pathFile, valueFile is global::StrawberryShake.Upload u ? u : null);
files.Add(pathFile, valueFile is global::StrawberryShake.Upload valueFile_i ? valueFile_i : null);
}

private void MapFilesFromArgumentObject(global::System.String path, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar.TestInput? value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ private TestUploadQuery(global::StrawberryShake.IOperationExecutor<ITestUploadRe

private void MapFilesFromArgumentSingle(global::System.String path, global::StrawberryShake.Upload? value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
{
files.Add(path, value is global::StrawberryShake.Upload u ? u : null);
files.Add(path, value is global::StrawberryShake.Upload value_i ? value_i : null);
}

private void MapFilesFromArgumentList(global::System.String path, global::System.Collections.Generic.IReadOnlyList<global::StrawberryShake.Upload?>? value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand All @@ -692,7 +692,7 @@ private void MapFilesFromArgumentList(global::System.String path, global::System
foreach (var value_lt in value_i)
{
var path_lt = path + "." + (path_counter++);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload value_lt_i ? value_lt_i : null);
}
}
}
Expand All @@ -711,7 +711,7 @@ private void MapFilesFromArgumentNested(global::System.String path, global::Syst
foreach (var value_lt_lt in value_lt_i)
{
var path_lt_lt = path_lt + "." + (path_lt_counter++);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload value_lt_lt_i ? value_lt_lt_i : null);
}
}
}
Expand Down Expand Up @@ -742,7 +742,7 @@ private void MapFilesFromTypeBazInput(global::System.String path, global::Strawb
{
var pathFile = path + ".file";
var valueFile = value.File;
files.Add(pathFile, valueFile is global::StrawberryShake.Upload u ? u : null);
files.Add(pathFile, valueFile is global::StrawberryShake.Upload valueFile_i ? valueFile_i : null);
}

private void MapFilesFromArgumentObject(global::System.String path, global::StrawberryShake.CodeGeneration.CSharp.Integration.UploadScalar_InMemory.TestInput? value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper;

namespace StrawberryShake.CodeGeneration.CSharp;

public class UploadMultipleFilesGeneratorTests
{
[Fact]
public void Generate_Should_CompileUniqueLocals_When_InputTypeHasMultipleUploadFields()
{
// arrange
// an input type with more than one Upload field forces the file mapper
// to emit several upload statements inside the same method scope.

// act + assert
AssertResult(
@"query test($input: FileUpload!) {
upload(input: $input)
}",
@"type Query {
upload(input: FileUpload): String
}

input FileUpload {
metadata: String!
file: Upload
file2: Upload
}

scalar Upload
",
"extend schema @key(fields: \"id\")");
}

[Fact]
public void Generate_Should_EmitSingleMapper_When_InputTypeHasMultipleFieldsOfSameUploadInputType()
{
// arrange
// an input type has two fields that point to the same nested upload input
// type, so the file mapper for that nested type must only be generated once.

// act + assert
AssertResult(
@"query test($input: CreateTaskInput!) {
upload(input: $input)
}",
@"type Query {
upload(input: CreateTaskInput): String
}

input CreateTaskInput {
title: String
uploadOne: FileUpload
uploadTwo: FileUpload
}

input FileUpload {
metadata: String!
file: Upload
file2: Upload
}

scalar Upload
",
"extend schema @key(fields: \"id\")");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ namespace Foo.Bar
{
var pathProfilePicture = path + ".profilePicture";
var valueProfilePicture = value.ProfilePicture;
files.Add(pathProfilePicture, valueProfilePicture is global::StrawberryShake.Upload u ? u : null);
files.Add(pathProfilePicture, valueProfilePicture is global::StrawberryShake.Upload valueProfilePicture_i ? valueProfilePicture_i : null);
var pathPhotos = path + ".photos";
var valuePhotos = value.Photos;
if (valuePhotos is { } valuePhotos_i)
Expand All @@ -808,7 +808,7 @@ namespace Foo.Bar
{
var pathData = path + ".data";
var valueData = value.Data;
files.Add(pathData, valueData is global::StrawberryShake.Upload u ? u : null);
files.Add(pathData, valueData is global::StrawberryShake.Upload valueData_i ? valueData_i : null);
var pathMetadata = path + ".metadata";
var valueMetadata = value.Metadata;
if (valueMetadata is { } valueMetadata_i)
Expand All @@ -821,7 +821,7 @@ namespace Foo.Bar
{
var pathThumbnail = path + ".thumbnail";
var valueThumbnail = value.Thumbnail;
files.Add(pathThumbnail, valueThumbnail is global::StrawberryShake.Upload u ? u : null);
files.Add(pathThumbnail, valueThumbnail is global::StrawberryShake.Upload valueThumbnail_i ? valueThumbnail_i : null);
}

private void MapFilesFromArgumentInput(global::System.String path, global::Foo.Bar.User value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace Foo.Bar

private void MapFilesFromArgumentUpload(global::System.String path, global::StrawberryShake.Upload value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
{
files.Add(path, value is global::StrawberryShake.Upload u ? u : null);
files.Add(path, value is global::StrawberryShake.Upload value_i ? value_i : null);
}

public global::System.IObservable<global::StrawberryShake.IOperationResult<ITestResult>> Watch(global::System.String @string, global::StrawberryShake.Upload upload, global::StrawberryShake.ExecutionStrategy? strategy = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace Foo.Bar

private void MapFilesFromArgumentUpload(global::System.String path, global::StrawberryShake.Upload value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
{
files.Add(path, value is global::StrawberryShake.Upload u ? u : null);
files.Add(path, value is global::StrawberryShake.Upload value_i ? value_i : null);
}

public global::System.IObservable<global::StrawberryShake.IOperationResult<ITestResult>> Watch(global::StrawberryShake.Upload upload, global::System.String @string, global::StrawberryShake.ExecutionStrategy? strategy = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ namespace Foo.Bar

private void MapFilesFromArgumentUpload(global::System.String path, global::StrawberryShake.Upload value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
{
files.Add(path, value is global::StrawberryShake.Upload u ? u : null);
files.Add(path, value is global::StrawberryShake.Upload value_i ? value_i : null);
}

private void MapFilesFromArgumentUploadNullable(global::System.String path, global::StrawberryShake.Upload? value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
{
files.Add(path, value is global::StrawberryShake.Upload u ? u : null);
files.Add(path, value is global::StrawberryShake.Upload value_i ? value_i : null);
}

private void MapFilesFromArgumentList(global::System.String path, global::System.Collections.Generic.IReadOnlyList<global::StrawberryShake.Upload> value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand All @@ -225,7 +225,7 @@ namespace Foo.Bar
foreach (var value_lt in value_i)
{
var path_lt = path + "." + (path_counter++);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload value_lt_i ? value_lt_i : null);
}
}
}
Expand All @@ -238,7 +238,7 @@ namespace Foo.Bar
foreach (var value_lt in value_i)
{
var path_lt = path + "." + (path_counter++);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt, value_lt is global::StrawberryShake.Upload value_lt_i ? value_lt_i : null);
}
}
}
Expand All @@ -257,7 +257,7 @@ namespace Foo.Bar
foreach (var value_lt_lt in value_lt_i)
{
var path_lt_lt = path_lt + "." + (path_lt_counter++);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload value_lt_lt_i ? value_lt_lt_i : null);
}
}
}
Expand All @@ -278,7 +278,7 @@ namespace Foo.Bar
foreach (var value_lt_lt in value_lt_i)
{
var path_lt_lt = path_lt + "." + (path_lt_counter++);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload u ? u : null);
files.Add(path_lt_lt, value_lt_lt is global::StrawberryShake.Upload value_lt_lt_i ? value_lt_lt_i : null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ namespace Foo.Bar
{
var pathFoo = path + ".foo";
var valueFoo = value.Foo;
files.Add(pathFoo, valueFoo is global::StrawberryShake.Upload u ? u : null);
files.Add(pathFoo, valueFoo is global::StrawberryShake.Upload valueFoo_i ? valueFoo_i : null);
}

private void MapFilesFromArgumentInput(global::System.String path, global::Foo.Bar.Test value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ namespace Foo.Bar
{
var pathFoo = path + ".foo";
var valueFoo = value.Foo;
files.Add(pathFoo, valueFoo is global::StrawberryShake.Upload u ? u : null);
files.Add(pathFoo, valueFoo is global::StrawberryShake.Upload valueFoo_i ? valueFoo_i : null);
}

private void MapFilesFromArgumentInput(global::System.String path, global::Foo.Bar.Test value, global::System.Collections.Generic.Dictionary<global::System.String, global::StrawberryShake.Upload?> files)
Expand Down
Loading
Loading