Skip to content

Commit 52cc8db

Browse files
authored
Docs: Mention required valueType for struct scalars in Strawberry Shake (#8575)
1 parent d429710 commit 52cc8db

File tree

5 files changed

+1740
-9
lines changed

5 files changed

+1740
-9
lines changed

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ScalarGeneratorTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ChilliCream.Testing;
2+
using Xunit.Sdk;
23
using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper;
34

45
namespace StrawberryShake.CodeGeneration.CSharp;
@@ -95,6 +96,34 @@ public void Custom_Scalar_With_SerializationType_And_RuntimeType() =>
9596
@serializationType(name: ""global::System.Int32"")",
9697
"extend schema @key(fields: \"id\")");
9798

99+
[Fact]
100+
public void Custom_Scalar_With_ValueType_RuntimeType() =>
101+
AssertResult(
102+
"query GetId($modelId: ModelIdScalar!) { personId(id: $modelId) }",
103+
"type Query { personId(id: ModelIdScalar!): ModelIdScalar }",
104+
"scalar ModelIdScalar",
105+
@"extend scalar ModelIdScalar
106+
@runtimeType(name: ""global::StrawberryShake.CodeGeneration.CSharp.ModelId"" valueType: true)");
107+
108+
[Fact]
109+
public void Custom_Scalar_With_ValueType_RuntimeType_Used_As_Nullable_Input() =>
110+
AssertResult(
111+
"query GetId($modelId: ModelIdScalar) { personId(id: $modelId) }",
112+
"type Query { personId(id: ModelIdScalar): ModelIdScalar }",
113+
"scalar ModelIdScalar",
114+
@"extend scalar ModelIdScalar
115+
@runtimeType(name: ""global::StrawberryShake.CodeGeneration.CSharp.ModelId"" valueType: true)");
116+
117+
[Fact]
118+
public void Custom_Scalar_With_ValueType_RuntimeType_Fails_If_ValueType_Not_Specified() =>
119+
Assert.Throws<FailException>(() =>
120+
AssertResult(
121+
"query GetId($modelId: ModelIdScalar!) { personId(id: $modelId) }",
122+
"type Query { personId(id: ModelIdScalar!): ModelIdScalar }",
123+
"scalar ModelIdScalar",
124+
@"extend scalar ModelIdScalar
125+
@runtimeType(name: ""global::StrawberryShake.CodeGeneration.CSharp.ModelId"")"));
126+
98127
[Fact]
99128
public void Any_Scalar() =>
100129
AssertResult(
@@ -187,3 +216,5 @@ public void Uri_Type() =>
187216
}
188217

189218
public class Custom;
219+
220+
public record struct ModelId(long Id);

0 commit comments

Comments
 (0)