Skip to content

Commit 4eb11c3

Browse files
committed
Reworked the invalid GraphQL name error message. (#7939)
1 parent a329840 commit 4eb11c3

File tree

8 files changed

+92
-22
lines changed

8 files changed

+92
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
For more details look at the `Errors` property.
22

3-
1. The specified name is not a valid GraphQL name. (Parameter 'definition.Name') (HotChocolate.Data.Sorting.SortConventionTests.FooSortType)
3+
1. `` is not a valid GraphQL name.
4+
https://spec.graphql.org/October2021/#sec-Names
5+
(Parameter 'definition.Name') (HotChocolate.Data.Sorting.SortConventionTests.FooSortType)

src/HotChocolate/Primitives/HotChocolate.Primitives.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{42689032-400
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Primitives", "src\Primitives\HotChocolate.Primitives.csproj", "{F5CEC44C-8AB9-4639-9B38-4F523E3ABF2A}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B598E71D-74BD-4055-A2F7-10B7DB892ECB}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Primitives.Tests", "test\Primitives.Tests\HotChocolate.Primitives.Tests.csproj", "{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}"
13+
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1216
Debug|Any CPU = Debug|Any CPU
@@ -20,8 +24,13 @@ Global
2024
{F5CEC44C-8AB9-4639-9B38-4F523E3ABF2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
2125
{F5CEC44C-8AB9-4639-9B38-4F523E3ABF2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
2226
{F5CEC44C-8AB9-4639-9B38-4F523E3ABF2A}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F}.Release|Any CPU.Build.0 = Release|Any CPU
2331
EndGlobalSection
2432
GlobalSection(NestedProjects) = preSolution
2533
{F5CEC44C-8AB9-4639-9B38-4F523E3ABF2A} = {42689032-4007-47A4-B045-12D2681BF2CF}
34+
{F7643027-2CEF-4F06-8DFA-46FFA8C17C4F} = {B598E71D-74BD-4055-A2F7-10B7DB892ECB}
2635
EndGlobalSection
2736
EndGlobal

src/HotChocolate/Primitives/src/Primitives/NameUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static string EnsureGraphQLName(
3434
return name!;
3535
}
3636

37-
throw new ArgumentException(NameUtils_InvalidGraphQLName, argumentName);
37+
throw new ArgumentException(string.Format(NameUtils_EnsureGraphQLName_InvalidName, name), argumentName);
3838
}
3939

4040
/// <summary>

src/HotChocolate/Primitives/src/Primitives/Properties/PrimitivesResources.Designer.cs

Lines changed: 21 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Primitives/src/Primitives/Properties/PrimitivesResources.resx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
<resheader name="writer">
1919
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
2020
</resheader>
21-
<data name="NameUtils_InvalidGraphQLName" xml:space="preserve">
22-
<value>The specified name is not a valid GraphQL name.</value>
23-
</data>
2421
<data name="ThrowHelper_SchemaCoordinate_ArgumentNameCannotBeSetWithoutMemberName" xml:space="preserve">
2522
<value>A argument name without a member name is only allowed on directive coordinates.</value>
2623
</data>
2724
<data name="ThrowHelper_SchemaCoordinate_MemberNameCannotBeSetOnADirectiveCoordinate" xml:space="preserve">
2825
<value>A directive cannot contain a member name.</value>
2926
</data>
27+
<data name="DirectiveTypeFactory_LocationNotSupported" xml:space="preserve">
28+
<value>The specified location `{0}` is not supported.</value>
29+
</data>
30+
<data name="NameUtils_EnsureGraphQLName_InvalidName" xml:space="preserve">
31+
<value>`{0}` is not a valid GraphQL name.
32+
https://spec.graphql.org/October2021/#sec-Names
33+
</value>
34+
</data>
3035
</root>

src/HotChocolate/Primitives/test/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />
33

44
<PropertyGroup>
5-
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
65
<IsPackable>false</IsPackable>
76
<GenerateDocumentationFile>false</GenerateDocumentationFile>
87
</PropertyGroup>
@@ -12,7 +11,8 @@
1211
</ItemGroup>
1312

1413
<ItemGroup>
15-
<ProjectReference Include="..\..\..\..\CookieCrumble\src\CookieCrumble\CookieCrumble.csproj" />
14+
<ProjectReference Include="..\..\..\..\CookieCrumble\src\CookieCrumble.Xunit\CookieCrumble.Xunit.csproj" />
15+
<ProjectReference Include="..\..\..\..\CookieCrumble\src\CookieCrumble.Analyzers\CookieCrumble.Analyzers.csproj" OutputItemType="Analyzer" />
1616
</ItemGroup>
1717

1818
<ItemGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
2+
3+
<PropertyGroup>
4+
<AssemblyName>HotChocolate.Primitives.Tests</AssemblyName>
5+
<RootNamespace>HotChocolate.Primitives</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Primitives\HotChocolate.Primitives.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using HotChocolate.Utilities;
2+
3+
namespace HotChocolate.Primitives;
4+
5+
public class NameUtilsTests
6+
{
7+
[Theory]
8+
[InlineData("1Bar")]
9+
[InlineData("$Bar")]
10+
[InlineData("1_Bar")]
11+
[InlineData("B/ar")]
12+
[InlineData("B+ar")]
13+
public void InvalidName(string name)
14+
{
15+
var message = Assert.Throws<ArgumentException>(() => name.EnsureGraphQLName()).Message;
16+
Assert.Equal(
17+
$"`{name}` is not a valid GraphQL name.{Environment.NewLine}"
18+
+ $"https://spec.graphql.org/October2021/#sec-Names{Environment.NewLine}"
19+
+ $" (Parameter 'name')",
20+
message);
21+
}
22+
23+
[Theory]
24+
[InlineData("_1Bar")]
25+
[InlineData("Bar")]
26+
[InlineData("_Bar")]
27+
[InlineData("Bar123")]
28+
[InlineData("Bar_123")]
29+
[InlineData("ABCDEFGHIJKLMNOPQRSTUVWXYZ")]
30+
[InlineData("abcdefghijklmnopqrstuvwxyz")]
31+
[InlineData("_1234567890")]
32+
public void ValidName(string name)
33+
{
34+
name.EnsureGraphQLName();
35+
}
36+
}

0 commit comments

Comments
 (0)