Skip to content

Commit

Permalink
QuerySerializer: skip serializing null properties
Browse files Browse the repository at this point in the history
ProjectV2FieldValue must provide exactly one property at a time
per documentation:

> The values that can be used to update a field of an item inside a
> Project. Only 1 value can be updated at a time.
>
> https://docs.github.com/en/graphql/reference/input-objects#projectv2fieldvalue

Fix this by skipping the serialization of null-valued properties.

Fixes octokit#292
  • Loading branch information
abock committed Apr 13, 2023
1 parent 579006e commit 73a6040
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions Octokit.GraphQL.Core/Core/Serializers/QuerySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,26 @@ private void SerializeValue(StringBuilder builder, object value)
//Cache Hit
}

for (var index = 0; index < properties.Length; index++)
{
var property = properties[index];

if (index == 0)
{
OpenBrace(builder);
}
else
{
builder.Append(",");
}
var serializedPropertyCount = 0;

builder.Append(property.Item1.LowerFirstCharacter()).Append(colon);
SerializeValue(builder, property.Item2.Invoke(value, null));
OpenBrace(builder);

if (index + 1 == properties.Length)
foreach (var property in properties)
{
var propertyValue = property.Item2.Invoke(value, null);
if (propertyValue != null)
{
CloseBrace(builder);
if (serializedPropertyCount++ > 0)
{
builder.Append(",");
}

builder.Append(property.Item1.LowerFirstCharacter()).Append(colon);
SerializeValue(builder, propertyValue);
}
}

CloseBrace(builder);
}
}

Expand Down

0 comments on commit 73a6040

Please sign in to comment.