Skip to content

Commit

Permalink
generate Array.Empty<GraphQlFieldMetadata>() instead of new GraphQlFi…
Browse files Browse the repository at this point in the history
…eldMetadata[0]
  • Loading branch information
Husqvik committed Nov 19, 2023
1 parent 4610874 commit a55762d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/GraphQlClientGenerator/GraphQlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private void GenerateDataClassBody(GraphQlType type, ICollection<GraphQlField> f
writer.Write(indentation);
writer.Write(" private ");
writer.Write(context.GetDataPropertyType(type, field).NetTypeName);
writer.Write(" ");
writer.Write(' ');
writer.Write(backingFieldName);
writer.WriteLine(";");
}
Expand Down Expand Up @@ -596,13 +596,13 @@ private string GenerateFileMember(GenerationContext context, string typeName, Gr

writer.Write(indentation);
writer.Write(GetMemberAccessibility());
writer.Write(" ");
writer.Write(' ');

if (_configuration.GeneratePartialClasses)
writer.Write("partial ");

writer.Write(graphQlType.Kind is GraphQlTypeKind.Interface ? "interface" : "class");
writer.Write(" ");
writer.Write(' ');
writer.Write(typeName);

if (!String.IsNullOrEmpty(baseTypeName))
Expand Down Expand Up @@ -718,7 +718,7 @@ private void GenerateDataProperty(
writer.Write("public ");

writer.Write(propertyTypeName);
writer.Write(" ");
writer.Write(' ');
writer.Write(propertyContext.PropertyName);

writeBody(propertyTypeDescription with { NetTypeName = propertyTypeName }, GetBackingFieldName(member.Name, propertyContext.RequiresRawName));
Expand Down Expand Up @@ -750,11 +750,12 @@ private void GenerateQueryBuilder(GenerationContext context, GraphQlType graphQl
CSharpTypeName = className
});

var useCompatibleSyntax = _configuration.CSharpVersion == CSharpVersion.Compatible;
var writer = context.Writer;
var indentation = GetIndentation(context.Indentation);
writer.Write(indentation);
writer.Write(GetMemberAccessibility());
writer.Write(" ");
writer.Write(' ');

if (_configuration.GeneratePartialClasses)
writer.Write("partial ");
Expand All @@ -771,7 +772,9 @@ private void GenerateQueryBuilder(GenerationContext context, GraphQlType graphQl

if (fields is null)
{
writer.WriteLine(" new GraphQlFieldMetadata[0];"); // TODO: Array.Empty<GraphQlFieldMetadata>();
writer.Write(' ');
writer.Write(useCompatibleSyntax ? "new GraphQlFieldMetadata[0]" : "Array.Empty<GraphQlFieldMetadata>()");
writer.WriteLine(';');
writer.WriteLine();
}
else
Expand All @@ -780,7 +783,7 @@ private void GenerateQueryBuilder(GenerationContext context, GraphQlType graphQl

var fieldMetadataIndentation = indentation;

if (_configuration.CSharpVersion == CSharpVersion.Compatible)
if (useCompatibleSyntax)
{
writer.Write(indentation);
writer.WriteLine(" new []");
Expand Down Expand Up @@ -848,7 +851,6 @@ private void GenerateQueryBuilder(GenerationContext context, GraphQlType graphQl
writer.WriteLine();
}

var useCompatibleSyntax = _configuration.CSharpVersion == CSharpVersion.Compatible;
var directiveLocation = GetDirectiveLocation(context.Schema, graphQlType.Name);

if (graphQlType.Kind is GraphQlTypeKind.Interface or GraphQlTypeKind.Union)
Expand Down Expand Up @@ -1274,7 +1276,7 @@ private string WriteDirectiveParameterList(

writer.Write(", ");
writer.Write(AddQuestionMarkIfNullableReferencesEnabled(directiveClassName));
writer.Write(" ");
writer.Write(' ');
writer.Write(directiveParameterName);
writer.Write(" = null");
}
Expand Down Expand Up @@ -1312,7 +1314,7 @@ private void WriteOverrideProperty(string accessibility, string propertyType, st
writer.Write(accessibility);
writer.Write(" override ");
writer.Write(propertyType);
writer.Write(" ");
writer.Write(' ');
writer.Write(propertyName);
writer.Write(" { get");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public partial class SimpleObjectTypeQueryBuilder : GraphQlQueryBuilder<SimpleOb

public partial class UnionTypeQueryBuilder : GraphQlQueryBuilder<UnionTypeQueryBuilder>
{
private static readonly GraphQlFieldMetadata[] AllFieldMetadata = new GraphQlFieldMetadata[0];
private static readonly GraphQlFieldMetadata[] AllFieldMetadata = Array.Empty<GraphQlFieldMetadata>();

public UnionTypeQueryBuilder() => WithTypeName();

Expand Down

0 comments on commit a55762d

Please sign in to comment.