Skip to content

Commit ca63f21

Browse files
authoredJun 24, 2021
Strawberry GUID robustness 11.x (#3863)
1 parent 0280c7d commit ca63f21

12 files changed

+144
-59
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
1+
override StrawberryShake.Serialization.UuidSerializer.Format(System.Guid runtimeValue) -> string!
2+
override StrawberryShake.Serialization.UuidSerializer.Parse(string! serializedValue) -> System.Guid
3+
StrawberryShake.Serialization.UuidSerializer.UuidSerializer(string! typeName = "Uuid", string! format = "D") -> void

‎src/StrawberryShake/Client/src/Core/Serialization/UuidSerializer.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,31 @@
22

33
namespace StrawberryShake.Serialization
44
{
5-
public class UuidSerializer
6-
: ScalarSerializer<Guid>
5+
/// <summary>
6+
/// This serializer handles UUID scalars.
7+
/// </summary>
8+
public class UuidSerializer : ScalarSerializer<string, Guid>
79
{
8-
public UuidSerializer(string typeName = BuiltInScalarNames.Uuid)
10+
private readonly string _format;
11+
12+
public UuidSerializer(string typeName = BuiltInScalarNames.Uuid, string format = "D")
913
: base(typeName)
1014
{
15+
_format = format;
16+
}
17+
18+
public override Guid Parse(string serializedValue)
19+
{
20+
if (Guid.TryParse(serializedValue, out Guid guid))
21+
{
22+
return guid;
23+
}
24+
throw ThrowHelper.UuidSerializer_CouldNotParse(serializedValue);
25+
}
26+
27+
protected override string Format(Guid runtimeValue)
28+
{
29+
return runtimeValue.ToString(_format);
1130
}
1231
}
1332
}

‎src/StrawberryShake/Client/src/Core/ThrowHelper.cs

+5
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@ internal static GraphQLClientException TimeSpanSerializer_CouldNotFormatValue(
5757
new(new ClientError(
5858
$"The TimeSpan serializer could not serialize value {value}. The provided value " +
5959
$"was not in format {format.ToString()}"));
60+
61+
62+
internal static GraphQLClientException UuidSerializer_CouldNotParse(string guid) =>
63+
new(new ClientError(
64+
$"The Guid serializer could not parse value {guid}. Invalid format."));
6065
}
6166
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using StrawberryShake;
3+
using StrawberryShake.Serialization;
4+
using Xunit;
5+
6+
namespace Core.Tests.Serialization
7+
{
8+
public class UuidSerializerTests
9+
{
10+
[Theory]
11+
[InlineData("D")]
12+
[InlineData("N")]
13+
[InlineData("B")]
14+
[InlineData("P")]
15+
[InlineData("X")]
16+
public void Parse_Different_Formats(string format)
17+
{
18+
// arrange
19+
var serializer = new UUIDSerializer();
20+
var guid = Guid.NewGuid();
21+
22+
// act
23+
Guid result = serializer.Parse(guid.ToString(format));
24+
25+
// assert
26+
Assert.Equal(guid, result);
27+
}
28+
29+
[Fact]
30+
public void Parse_Exception()
31+
{
32+
// arrange
33+
var serializer = new UUIDSerializer();
34+
35+
// assert
36+
Assert.Throws<GraphQLClientException>(() => serializer.Parse(string.Empty));
37+
}
38+
39+
[Theory]
40+
[InlineData("D")]
41+
[InlineData("N")]
42+
[InlineData("B")]
43+
[InlineData("P")]
44+
[InlineData("X")]
45+
public void Format(string format)
46+
{
47+
// arrange
48+
var serializer = new UUIDSerializer(format: format);
49+
var guid = Guid.NewGuid();
50+
51+
// act
52+
var result = serializer.Format(guid);
53+
54+
// assert
55+
Assert.Equal(guid.ToString(format), result);
56+
}
57+
}
58+
}

‎src/StrawberryShake/CodeGeneration/src/CodeGeneration/Utilities/SchemaHelper.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ private static void AddDefaultScalarInfos(
227227
TryAddLeafType(leafTypes, ScalarNames.Float, TypeNames.Double, TypeNames.Double);
228228
TryAddLeafType(leafTypes, ScalarNames.Decimal, TypeNames.Decimal, TypeNames.Decimal);
229229
TryAddLeafType(leafTypes, ScalarNames.Url, TypeNames.Uri);
230-
TryAddLeafType(leafTypes, ScalarNames.Uuid, TypeNames.Guid, TypeNames.Guid);
231-
TryAddLeafType(leafTypes, "Guid", TypeNames.Guid, TypeNames.Guid);
230+
TryAddLeafType(leafTypes, ScalarNames.Uuid, TypeNames.Guid, TypeNames.String);
231+
TryAddLeafType(leafTypes, "Uuid", TypeNames.Guid, TypeNames.String);
232+
TryAddLeafType(leafTypes, "Guid", TypeNames.Guid, TypeNames.String);
232233
TryAddLeafType(leafTypes, ScalarNames.DateTime, TypeNames.DateTimeOffset);
233234
TryAddLeafType(leafTypes, ScalarNames.Date, TypeNames.DateTime);
234235
TryAddLeafType(leafTypes, ScalarNames.TimeSpan, TypeNames.TimeSpan);

‎src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/EntityIdFactoryGeneratorTests.Simple_Uuid_Entity.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ namespace Foo.Bar
122122
return false;
123123
}
124124

125-
return (Id == other.Id) && ((Email is null && other.Email is null) || Email != null && Email.Equals(other.Email));
125+
return (Id.Equals(other.Id)) && ((Email is null && other.Email is null) || Email != null && Email.Equals(other.Email));
126126
}
127127

128128
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -473,14 +473,14 @@ namespace Foo.Bar.State
473473
private readonly global::StrawberryShake.IEntityStore _entityStore;
474474
private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer;
475475
private readonly global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IGetPersonResult> _resultDataFactory;
476-
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Guid, global::System.Guid> _uuidParser;
476+
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.Guid> _uuidParser;
477477
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.String> _stringParser;
478478
public GetPersonBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IGetPersonResult> resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver)
479479
{
480480
_entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore));
481481
_idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer));
482482
_resultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory));
483-
_uuidParser = serializerResolver.GetLeafValueParser<global::System.Guid, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
483+
_uuidParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
484484
_stringParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.String>("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found.");
485485
}
486486

@@ -565,7 +565,7 @@ namespace Foo.Bar.State
565565
throw new global::System.ArgumentNullException();
566566
}
567567

568-
return _uuidParser.Parse(obj.Value.GetGuid()!);
568+
return _uuidParser.Parse(obj.Value.GetString()!);
569569
}
570570

571571
private global::System.String? DeserializeString(global::System.Text.Json.JsonElement? obj)
@@ -606,7 +606,7 @@ namespace Foo.Bar.State
606606

607607
private global::StrawberryShake.EntityId ParsePersonEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
608608
{
609-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
609+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
610610
}
611611

612612
private global::System.String FormatPersonEntityId(global::StrawberryShake.EntityId entityId)
@@ -615,7 +615,7 @@ namespace Foo.Bar.State
615615
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
616616
jsonWriter.WriteStartObject();
617617
jsonWriter.WriteString("__typename", entityId.Name);
618-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
618+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
619619
jsonWriter.WriteEndObject();
620620
jsonWriter.Flush();
621621
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);

‎src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/ResultTypeGeneratorTests.Nested_Entity.snap

+9-9
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ namespace Foo.Bar
217217
return false;
218218
}
219219

220-
return (Id == other.Id) && ((Make is null && other.Make is null) || Make != null && Make.Equals(other.Make)) && ((MakeCode is null && other.MakeCode is null) || MakeCode != null && MakeCode.Equals(other.MakeCode)) && IsDisabled == other.IsDisabled;
220+
return (Id.Equals(other.Id)) && ((Make is null && other.Make is null) || Make != null && Make.Equals(other.Make)) && ((MakeCode is null && other.MakeCode is null) || MakeCode != null && MakeCode.Equals(other.MakeCode)) && IsDisabled == other.IsDisabled;
221221
}
222222

223223
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -323,7 +323,7 @@ namespace Foo.Bar
323323
return false;
324324
}
325325

326-
return (Id == other.Id) && ((Model is null && other.Model is null) || Model != null && Model.Equals(other.Model)) && ((ModelCode is null && other.ModelCode is null) || ModelCode != null && ModelCode.Equals(other.ModelCode)) && VehicleMakeId == other.VehicleMakeId && IsDisabled == other.IsDisabled && ((ModelType is null && other.ModelType is null) || ModelType != null && ModelType.Equals(other.ModelType));
326+
return (Id.Equals(other.Id)) && ((Model is null && other.Model is null) || Model != null && Model.Equals(other.Model)) && ((ModelCode is null && other.ModelCode is null) || ModelCode != null && ModelCode.Equals(other.ModelCode)) && VehicleMakeId.Equals(other.VehicleMakeId) && IsDisabled == other.IsDisabled && ((ModelType is null && other.ModelType is null) || ModelType != null && ModelType.Equals(other.ModelType));
327327
}
328328

329329
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -982,15 +982,15 @@ namespace Foo.Bar.State
982982
private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer;
983983
private readonly global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IDecodeVINResult> _resultDataFactory;
984984
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Boolean, global::System.Boolean> _booleanParser;
985-
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Guid, global::System.Guid> _uuidParser;
985+
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.Guid> _uuidParser;
986986
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.String> _stringParser;
987987
public DecodeVINBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IDecodeVINResult> resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver)
988988
{
989989
_entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore));
990990
_idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer));
991991
_resultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory));
992992
_booleanParser = serializerResolver.GetLeafValueParser<global::System.Boolean, global::System.Boolean>("Boolean") ?? throw new global::System.ArgumentException("No serializer for type `Boolean` found.");
993-
_uuidParser = serializerResolver.GetLeafValueParser<global::System.Guid, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
993+
_uuidParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
994994
_stringParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.String>("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found.");
995995
}
996996

@@ -1101,7 +1101,7 @@ namespace Foo.Bar.State
11011101
throw new global::System.ArgumentNullException();
11021102
}
11031103

1104-
return _uuidParser.Parse(obj.Value.GetGuid()!);
1104+
return _uuidParser.Parse(obj.Value.GetString()!);
11051105
}
11061106

11071107
private global::System.String? DeserializeString(global::System.Text.Json.JsonElement? obj)
@@ -1201,7 +1201,7 @@ namespace Foo.Bar.State
12011201

12021202
private global::StrawberryShake.EntityId ParseVehicleMakeEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
12031203
{
1204-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
1204+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
12051205
}
12061206

12071207
private global::System.String FormatVehicleMakeEntityId(global::StrawberryShake.EntityId entityId)
@@ -1210,15 +1210,15 @@ namespace Foo.Bar.State
12101210
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
12111211
jsonWriter.WriteStartObject();
12121212
jsonWriter.WriteString("__typename", entityId.Name);
1213-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
1213+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
12141214
jsonWriter.WriteEndObject();
12151215
jsonWriter.Flush();
12161216
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);
12171217
}
12181218

12191219
private global::StrawberryShake.EntityId ParseVehicleModelEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
12201220
{
1221-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
1221+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
12221222
}
12231223

12241224
private global::System.String FormatVehicleModelEntityId(global::StrawberryShake.EntityId entityId)
@@ -1227,7 +1227,7 @@ namespace Foo.Bar.State
12271227
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
12281228
jsonWriter.WriteStartObject();
12291229
jsonWriter.WriteString("__typename", entityId.Name);
1230-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
1230+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
12311231
jsonWriter.WriteEndObject();
12321232
jsonWriter.Flush();
12331233
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);

‎src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/ScalarGeneratorTests.Complete_Schema_With_Uuid_And_DateTime.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ namespace Foo.Bar
158158
return false;
159159
}
160160

161-
return (Id == other.Id) && Amount == other.Amount && Date.Equals(other.Date) && ((Description is null && other.Description is null) || Description != null && Description.Equals(other.Description)) && Category.Equals(other.Category) && PaymentMethod.Equals(other.PaymentMethod) && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Tags, other.Tags);
161+
return (Id.Equals(other.Id)) && Amount == other.Amount && Date.Equals(other.Date) && ((Description is null && other.Description is null) || Description != null && Description.Equals(other.Description)) && Category.Equals(other.Category) && PaymentMethod.Equals(other.PaymentMethod) && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Tags, other.Tags);
162162
}
163163

164164
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -823,7 +823,7 @@ namespace Foo.Bar.State
823823
private readonly global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IAllExpensesResult> _resultDataFactory;
824824
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::Foo.Bar.ExpenseCategory> _expenseCategoryParser;
825825
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::Foo.Bar.PaymentMethod> _paymentMethodParser;
826-
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Guid, global::System.Guid> _uuidParser;
826+
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.Guid> _uuidParser;
827827
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Decimal, global::System.Decimal> _decimalParser;
828828
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.DateTimeOffset> _dateTimeParser;
829829
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.String> _stringParser;
@@ -834,7 +834,7 @@ namespace Foo.Bar.State
834834
_resultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory));
835835
_expenseCategoryParser = serializerResolver.GetLeafValueParser<global::System.String, global::Foo.Bar.ExpenseCategory>("ExpenseCategory") ?? throw new global::System.ArgumentException("No serializer for type `ExpenseCategory` found.");
836836
_paymentMethodParser = serializerResolver.GetLeafValueParser<global::System.String, global::Foo.Bar.PaymentMethod>("PaymentMethod") ?? throw new global::System.ArgumentException("No serializer for type `PaymentMethod` found.");
837-
_uuidParser = serializerResolver.GetLeafValueParser<global::System.Guid, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
837+
_uuidParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
838838
_decimalParser = serializerResolver.GetLeafValueParser<global::System.Decimal, global::System.Decimal>("Decimal") ?? throw new global::System.ArgumentException("No serializer for type `Decimal` found.");
839839
_dateTimeParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.DateTimeOffset>("DateTime") ?? throw new global::System.ArgumentException("No serializer for type `DateTime` found.");
840840
_stringParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.String>("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found.");
@@ -937,7 +937,7 @@ namespace Foo.Bar.State
937937
throw new global::System.ArgumentNullException();
938938
}
939939

940-
return _uuidParser.Parse(obj.Value.GetGuid()!);
940+
return _uuidParser.Parse(obj.Value.GetString()!);
941941
}
942942

943943
private global::System.Decimal DeserializeNonNullableDecimal(global::System.Text.Json.JsonElement? obj)
@@ -1071,7 +1071,7 @@ namespace Foo.Bar.State
10711071

10721072
private global::StrawberryShake.EntityId ParseExpenseEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
10731073
{
1074-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
1074+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
10751075
}
10761076

10771077
private global::System.String FormatExpenseEntityId(global::StrawberryShake.EntityId entityId)
@@ -1080,7 +1080,7 @@ namespace Foo.Bar.State
10801080
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
10811081
jsonWriter.WriteStartObject();
10821082
jsonWriter.WriteString("__typename", entityId.Name);
1083-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
1083+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
10841084
jsonWriter.WriteEndObject();
10851085
jsonWriter.Flush();
10861086
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);

‎src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/SchemaGeneratorTests.Create_GetFeatById.snap

+8-8
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ namespace Foo.Bar
209209
return false;
210210
}
211211

212-
return (Id == other.Id) && Name.Equals(other.Name) && Level == other.Level && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Details, other.Details);
212+
return (Id.Equals(other.Id)) && Name.Equals(other.Name) && Level == other.Level && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Details, other.Details);
213213
}
214214

215215
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -851,15 +851,15 @@ namespace Foo.Bar.State
851851
private readonly global::StrawberryShake.IEntityStore _entityStore;
852852
private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer;
853853
private readonly global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IGetFeatByIdResult> _resultDataFactory;
854-
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Guid, global::System.Guid> _uuidParser;
854+
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.Guid> _uuidParser;
855855
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.String> _stringParser;
856856
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Int32, global::System.Int32> _intParser;
857857
public GetFeatByIdBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IGetFeatByIdResult> resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver)
858858
{
859859
_entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore));
860860
_idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer));
861861
_resultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory));
862-
_uuidParser = serializerResolver.GetLeafValueParser<global::System.Guid, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
862+
_uuidParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
863863
_stringParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.String>("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found.");
864864
_intParser = serializerResolver.GetLeafValueParser<global::System.Int32, global::System.Int32>("Int") ?? throw new global::System.ArgumentException("No serializer for type `Int` found.");
865865
}
@@ -977,7 +977,7 @@ namespace Foo.Bar.State
977977
throw new global::System.ArgumentNullException();
978978
}
979979

980-
return _uuidParser.Parse(obj.Value.GetGuid()!);
980+
return _uuidParser.Parse(obj.Value.GetString()!);
981981
}
982982

983983
private global::System.String DeserializeNonNullableString(global::System.Text.Json.JsonElement? obj)
@@ -1091,7 +1091,7 @@ namespace Foo.Bar.State
10911091

10921092
private global::StrawberryShake.EntityId ParseFeatEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
10931093
{
1094-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
1094+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
10951095
}
10961096

10971097
private global::System.String FormatFeatEntityId(global::StrawberryShake.EntityId entityId)
@@ -1100,15 +1100,15 @@ namespace Foo.Bar.State
11001100
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
11011101
jsonWriter.WriteStartObject();
11021102
jsonWriter.WriteString("__typename", entityId.Name);
1103-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
1103+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
11041104
jsonWriter.WriteEndObject();
11051105
jsonWriter.Flush();
11061106
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);
11071107
}
11081108

11091109
private global::StrawberryShake.EntityId ParseFeatDetailsBlockEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
11101110
{
1111-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
1111+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
11121112
}
11131113

11141114
private global::System.String FormatFeatDetailsBlockEntityId(global::StrawberryShake.EntityId entityId)
@@ -1117,7 +1117,7 @@ namespace Foo.Bar.State
11171117
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
11181118
jsonWriter.WriteStartObject();
11191119
jsonWriter.WriteString("__typename", entityId.Name);
1120-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
1120+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
11211121
jsonWriter.WriteEndObject();
11221122
jsonWriter.Flush();
11231123
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);

‎src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/SchemaGeneratorTests.Create_GetFeatsPage.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ namespace Foo.Bar.State
10591059

10601060
private global::StrawberryShake.EntityId ParseFeatEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
10611061
{
1062-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
1062+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
10631063
}
10641064

10651065
private global::System.String FormatFeatEntityId(global::StrawberryShake.EntityId entityId)
@@ -1068,15 +1068,15 @@ namespace Foo.Bar.State
10681068
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
10691069
jsonWriter.WriteStartObject();
10701070
jsonWriter.WriteString("__typename", entityId.Name);
1071-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
1071+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
10721072
jsonWriter.WriteEndObject();
10731073
jsonWriter.Flush();
10741074
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);
10751075
}
10761076

10771077
private global::StrawberryShake.EntityId ParseActionTypeEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
10781078
{
1079-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
1079+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
10801080
}
10811081

10821082
private global::System.String FormatActionTypeEntityId(global::StrawberryShake.EntityId entityId)
@@ -1085,7 +1085,7 @@ namespace Foo.Bar.State
10851085
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
10861086
jsonWriter.WriteStartObject();
10871087
jsonWriter.WriteString("__typename", entityId.Name);
1088-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
1088+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
10891089
jsonWriter.WriteEndObject();
10901090
jsonWriter.Flush();
10911091
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);

‎src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/SchemaGeneratorTests.Create_UpdateMembers_Mutation.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace Foo.Bar
184184
return false;
185185
}
186186

187-
return (CorrelationId == other.CorrelationId);
187+
return (CorrelationId.Equals(other.CorrelationId));
188188
}
189189

190190
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -375,7 +375,7 @@ namespace Foo.Bar
375375
return false;
376376
}
377377

378-
return (Id == other.Id) && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Members, other.Members);
378+
return (Id.Equals(other.Id)) && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Members, other.Members);
379379
}
380380

381381
public override global::System.Int32 GetHashCode()
@@ -531,7 +531,7 @@ namespace Foo.Bar
531531
return false;
532532
}
533533

534-
return (Id == other.Id) && Type.Equals(other.Type) && Remove == other.Remove;
534+
return (Id.Equals(other.Id)) && Type.Equals(other.Type) && Remove == other.Remove;
535535
}
536536

537537
public override global::System.Int32 GetHashCode()
@@ -927,15 +927,15 @@ namespace Foo.Bar.State
927927
private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer;
928928
private readonly global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IUpdateMembersResult> _resultDataFactory;
929929
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::Foo.Bar.ProjectUserRoleType> _projectUserRoleTypeParser;
930-
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Guid, global::System.Guid> _guidParser;
930+
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.Guid> _guidParser;
931931
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Boolean, global::System.Boolean> _booleanParser;
932932
public UpdateMembersBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IUpdateMembersResult> resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver)
933933
{
934934
_entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore));
935935
_idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer));
936936
_resultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory));
937937
_projectUserRoleTypeParser = serializerResolver.GetLeafValueParser<global::System.String, global::Foo.Bar.ProjectUserRoleType>("ProjectUserRoleType") ?? throw new global::System.ArgumentException("No serializer for type `ProjectUserRoleType` found.");
938-
_guidParser = serializerResolver.GetLeafValueParser<global::System.Guid, global::System.Guid>("Guid") ?? throw new global::System.ArgumentException("No serializer for type `Guid` found.");
938+
_guidParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.Guid>("Guid") ?? throw new global::System.ArgumentException("No serializer for type `Guid` found.");
939939
_booleanParser = serializerResolver.GetLeafValueParser<global::System.Boolean, global::System.Boolean>("Boolean") ?? throw new global::System.ArgumentException("No serializer for type `Boolean` found.");
940940
}
941941

@@ -1024,7 +1024,7 @@ namespace Foo.Bar.State
10241024
throw new global::System.ArgumentNullException();
10251025
}
10261026

1027-
return _guidParser.Parse(obj.Value.GetGuid()!);
1027+
return _guidParser.Parse(obj.Value.GetString()!);
10281028
}
10291029
}
10301030

‎src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/__snapshots__/SchemaGeneratorTests.QueryInterference.snap

+14-14
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ namespace Foo.Bar
222222
return false;
223223
}
224224

225-
return (Id == other.Id) && Name.Equals(other.Name) && Level == other.Level && CanBeLearnedMoreThanOnce == other.CanBeLearnedMoreThanOnce && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Details, other.Details);
225+
return (Id.Equals(other.Id)) && Name.Equals(other.Name) && Level == other.Level && CanBeLearnedMoreThanOnce == other.CanBeLearnedMoreThanOnce && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Details, other.Details);
226226
}
227227

228228
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -629,7 +629,7 @@ namespace Foo.Bar
629629
return false;
630630
}
631631

632-
return (Id == other.Id) && Name.Equals(other.Name) && Level == other.Level && ((Special is null && other.Special is null) || Special != null && Special.Equals(other.Special)) && ((Trigger is null && other.Trigger is null) || Trigger != null && Trigger.Equals(other.Trigger)) && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Details, other.Details) && ActionType.Equals(other.ActionType);
632+
return (Id.Equals(other.Id)) && Name.Equals(other.Name) && Level == other.Level && ((Special is null && other.Special is null) || Special != null && Special.Equals(other.Special)) && ((Trigger is null && other.Trigger is null) || Trigger != null && Trigger.Equals(other.Trigger)) && global::StrawberryShake.Helper.ComparisonHelper.SequenceEqual(Details, other.Details) && ActionType.Equals(other.ActionType);
633633
}
634634

635635
public override global::System.Boolean Equals(global::System.Object? obj)
@@ -3526,7 +3526,7 @@ namespace Foo.Bar.State
35263526
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::Foo.Bar.SortEnumType> _sortEnumTypeParser;
35273527
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Int32, global::System.Int32> _intParser;
35283528
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.String> _stringParser;
3529-
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Guid, global::System.Guid> _uuidParser;
3529+
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.Guid> _uuidParser;
35303530
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Boolean, global::System.Boolean> _booleanParser;
35313531
public GetFeatsPageBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IGetFeatsPageResult> resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver)
35323532
{
@@ -3536,7 +3536,7 @@ namespace Foo.Bar.State
35363536
_sortEnumTypeParser = serializerResolver.GetLeafValueParser<global::System.String, global::Foo.Bar.SortEnumType>("SortEnumType") ?? throw new global::System.ArgumentException("No serializer for type `SortEnumType` found.");
35373537
_intParser = serializerResolver.GetLeafValueParser<global::System.Int32, global::System.Int32>("Int") ?? throw new global::System.ArgumentException("No serializer for type `Int` found.");
35383538
_stringParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.String>("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found.");
3539-
_uuidParser = serializerResolver.GetLeafValueParser<global::System.Guid, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
3539+
_uuidParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
35403540
_booleanParser = serializerResolver.GetLeafValueParser<global::System.Boolean, global::System.Boolean>("Boolean") ?? throw new global::System.ArgumentException("No serializer for type `Boolean` found.");
35413541
}
35423542

@@ -3663,7 +3663,7 @@ namespace Foo.Bar.State
36633663
throw new global::System.ArgumentNullException();
36643664
}
36653665

3666-
return _uuidParser.Parse(obj.Value.GetGuid()!);
3666+
return _uuidParser.Parse(obj.Value.GetString()!);
36673667
}
36683668

36693669
private global::System.String DeserializeNonNullableString(global::System.Text.Json.JsonElement? obj)
@@ -3736,15 +3736,15 @@ namespace Foo.Bar.State
37363736
private readonly global::StrawberryShake.IEntityStore _entityStore;
37373737
private readonly global::StrawberryShake.IEntityIdSerializer _idSerializer;
37383738
private readonly global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IGetFeatByIdResult> _resultDataFactory;
3739-
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Guid, global::System.Guid> _uuidParser;
3739+
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.Guid> _uuidParser;
37403740
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.String, global::System.String> _stringParser;
37413741
private readonly global::StrawberryShake.Serialization.ILeafValueParser<global::System.Int32, global::System.Int32> _intParser;
37423742
public GetFeatByIdBuilder(global::StrawberryShake.IEntityStore entityStore, global::StrawberryShake.IEntityIdSerializer idSerializer, global::StrawberryShake.IOperationResultDataFactory<global::Foo.Bar.IGetFeatByIdResult> resultDataFactory, global::StrawberryShake.Serialization.ISerializerResolver serializerResolver)
37433743
{
37443744
_entityStore = entityStore ?? throw new global::System.ArgumentNullException(nameof(entityStore));
37453745
_idSerializer = idSerializer ?? throw new global::System.ArgumentNullException(nameof(idSerializer));
37463746
_resultDataFactory = resultDataFactory ?? throw new global::System.ArgumentNullException(nameof(resultDataFactory));
3747-
_uuidParser = serializerResolver.GetLeafValueParser<global::System.Guid, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
3747+
_uuidParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.Guid>("Uuid") ?? throw new global::System.ArgumentException("No serializer for type `Uuid` found.");
37483748
_stringParser = serializerResolver.GetLeafValueParser<global::System.String, global::System.String>("String") ?? throw new global::System.ArgumentException("No serializer for type `String` found.");
37493749
_intParser = serializerResolver.GetLeafValueParser<global::System.Int32, global::System.Int32>("Int") ?? throw new global::System.ArgumentException("No serializer for type `Int` found.");
37503750
}
@@ -3862,7 +3862,7 @@ namespace Foo.Bar.State
38623862
throw new global::System.ArgumentNullException();
38633863
}
38643864

3865-
return _uuidParser.Parse(obj.Value.GetGuid()!);
3865+
return _uuidParser.Parse(obj.Value.GetString()!);
38663866
}
38673867

38683868
private global::System.String DeserializeNonNullableString(global::System.Text.Json.JsonElement? obj)
@@ -4018,7 +4018,7 @@ namespace Foo.Bar.State
40184018

40194019
private global::StrawberryShake.EntityId ParseFeatEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
40204020
{
4021-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
4021+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
40224022
}
40234023

40244024
private global::System.String FormatFeatEntityId(global::StrawberryShake.EntityId entityId)
@@ -4027,15 +4027,15 @@ namespace Foo.Bar.State
40274027
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
40284028
jsonWriter.WriteStartObject();
40294029
jsonWriter.WriteString("__typename", entityId.Name);
4030-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
4030+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
40314031
jsonWriter.WriteEndObject();
40324032
jsonWriter.Flush();
40334033
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);
40344034
}
40354035

40364036
private global::StrawberryShake.EntityId ParseFeatDetailsBlockEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
40374037
{
4038-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
4038+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
40394039
}
40404040

40414041
private global::System.String FormatFeatDetailsBlockEntityId(global::StrawberryShake.EntityId entityId)
@@ -4044,15 +4044,15 @@ namespace Foo.Bar.State
40444044
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
40454045
jsonWriter.WriteStartObject();
40464046
jsonWriter.WriteString("__typename", entityId.Name);
4047-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
4047+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
40484048
jsonWriter.WriteEndObject();
40494049
jsonWriter.Flush();
40504050
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);
40514051
}
40524052

40534053
private global::StrawberryShake.EntityId ParseActionTypeEntityId(global::System.Text.Json.JsonElement obj, global::System.String type)
40544054
{
4055-
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetGuid()!);
4055+
return new global::StrawberryShake.EntityId(type, obj.GetProperty("id").GetString()!);
40564056
}
40574057

40584058
private global::System.String FormatActionTypeEntityId(global::StrawberryShake.EntityId entityId)
@@ -4061,7 +4061,7 @@ namespace Foo.Bar.State
40614061
using var jsonWriter = new global::System.Text.Json.Utf8JsonWriter(writer, _options);
40624062
jsonWriter.WriteStartObject();
40634063
jsonWriter.WriteString("__typename", entityId.Name);
4064-
jsonWriter.WriteString("id", (global::System.Guid)entityId.Value);
4064+
jsonWriter.WriteString("id", (global::System.String)entityId.Value);
40654065
jsonWriter.WriteEndObject();
40664066
jsonWriter.Flush();
40674067
return global::System.Text.Encoding.UTF8.GetString(writer.GetInternalBuffer(), 0, writer.Length);

0 commit comments

Comments
 (0)
Please sign in to comment.