Skip to content

Commit f4198b2

Browse files
[Fusion] Fix findings (#8870)
1 parent 4c40617 commit f4198b2

File tree

62 files changed

+1861
-774
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1861
-774
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Frozen;
2+
3+
namespace HotChocolate.Types;
4+
5+
public static class HotChocolateTypesAbstractionsScalarDefinitionExtensions
6+
{
7+
private static readonly FrozenDictionary<string, ScalarSerializationType> s_serializationTypeLookup =
8+
new Dictionary<string, ScalarSerializationType>
9+
{
10+
["https://scalars.graphql.org/andimarek/date-time.html"] = ScalarSerializationType.String,
11+
["https://scalars.graphql.org/andimarek/local-date.html"] = ScalarSerializationType.String
12+
}
13+
.ToFrozenDictionary();
14+
15+
public static ScalarSerializationType GetScalarSerializationType(
16+
this IScalarTypeDefinition scalarTypeDefinition)
17+
{
18+
if (scalarTypeDefinition.SpecifiedBy is not null
19+
&& s_serializationTypeLookup.TryGetValue(scalarTypeDefinition.SpecifiedBy.AbsoluteUri, out var scalarSerializationType))
20+
{
21+
return scalarSerializationType;
22+
}
23+
24+
return scalarTypeDefinition.Name switch
25+
{
26+
SpecScalarNames.String.Name => ScalarSerializationType.String,
27+
SpecScalarNames.Int.Name => ScalarSerializationType.Int,
28+
SpecScalarNames.Float.Name => ScalarSerializationType.Float,
29+
SpecScalarNames.Boolean.Name => ScalarSerializationType.Boolean,
30+
SpecScalarNames.ID.Name => ScalarSerializationType.String | ScalarSerializationType.Int,
31+
_ => scalarTypeDefinition.SerializationType
32+
};
33+
}
34+
}

src/HotChocolate/Core/src/Types.Abstractions/Types/IScalarTypeDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IScalarTypeDefinition
2222

2323
/// <summary>
2424
/// Gets the ECMA-262 regex pattern that the serialized scalar value conforms
25-
/// to if its of the serialization type <see cref="ScalarSerializationType.String"/>.
25+
/// to, if it's of the serialization type <see cref="ScalarSerializationType.String"/>.
2626
/// </summary>
2727
string? Pattern { get; }
2828

src/HotChocolate/Core/src/Types.Abstractions/Types/SpecDirectiveNames.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/HotChocolate/Core/src/Types.Abstractions/Types/SpecScalarNames.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/HotChocolate/Fusion-vnext/src/Fusion.Aspire/HotChocolate.Fusion.Aspire.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
<PropertyGroup>
44
<AssemblyName>HotChocolate.Fusion.Aspire</AssemblyName>
55
<RootNamespace>HotChocolate.Fusion.Aspire</RootNamespace>
6-
<TargetFrameworks>net9.0</TargetFrameworks>
7-
<TargetFramework>net9.0</TargetFramework>
6+
<TargetFrameworks>net10.0; net9.0</TargetFrameworks>
87
<IsAotCompliant>false</IsAotCompliant>
98
</PropertyGroup>
109

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryCodes.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static class LogEntryCodes
2727
public const string InputFieldDefaultMismatch = "INPUT_FIELD_DEFAULT_MISMATCH";
2828
public const string InputFieldTypesNotMergeable = "INPUT_FIELD_TYPES_NOT_MERGEABLE";
2929
public const string InputWithMissingRequiredFields = "INPUT_WITH_MISSING_REQUIRED_FIELDS";
30+
public const string InputWithMissingOneOf = "INPUT_WITH_MISSING_ONEOF";
3031
public const string InterfaceFieldNoImplementation = "INTERFACE_FIELD_NO_IMPLEMENTATION";
3132
public const string InvalidFieldSharing = "INVALID_FIELD_SHARING";
3233
public const string InvalidGraphQL = "INVALID_GRAPHQL";

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Logging/LogEntryHelper.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,24 @@ public static LogEntry InputWithMissingRequiredFields(
483483
.Build();
484484
}
485485

486+
public static LogEntry InputWithMissingOneOf(
487+
MutableInputObjectTypeDefinition inputType,
488+
MutableSchemaDefinition schema,
489+
MutableSchemaDefinition schemaWhereOneOfIsDefined)
490+
{
491+
return LogEntryBuilder.New()
492+
.SetMessage(
493+
LogEntryHelper_InputWithMissingOneOf,
494+
inputType.Name,
495+
schema.Name,
496+
schemaWhereOneOfIsDefined.Name)
497+
.SetCode(LogEntryCodes.InputWithMissingOneOf)
498+
.SetSeverity(LogSeverity.Error)
499+
.SetTypeSystemMember(inputType)
500+
.SetSchema(schema)
501+
.Build();
502+
}
503+
486504
public static LogEntry InterfaceFieldNoImplementation(
487505
MutableObjectTypeDefinition objectType,
488506
string fieldName,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using HotChocolate.Fusion.Events;
2+
using HotChocolate.Fusion.Events.Contracts;
3+
using HotChocolate.Fusion.Extensions;
4+
using HotChocolate.Fusion.Logging;
5+
using HotChocolate.Types.Mutable;
6+
7+
namespace HotChocolate.Fusion.PreMergeValidationRules;
8+
9+
/// <summary>
10+
/// If one input type is annotated with the @oneOf directive, all input types
11+
/// of the same name must be annotated with it as well.
12+
/// </summary>
13+
internal sealed class InputWithMissingOneOfRule : IEventHandler<InputTypeGroupEvent>
14+
{
15+
public void Handle(InputTypeGroupEvent @event, CompositionContext context)
16+
{
17+
var (_, inputTypeGroup) = @event;
18+
19+
var firstInputWithOneOf = inputTypeGroup.FirstOrDefault(i => i.InputType.IsOneOf);
20+
21+
if (firstInputWithOneOf is null || inputTypeGroup.Length == 1)
22+
{
23+
return;
24+
}
25+
26+
foreach (var (inputType, schema) in inputTypeGroup)
27+
{
28+
if (inputType.HasInaccessibleDirective())
29+
{
30+
continue;
31+
}
32+
33+
if (!inputType.IsOneOf)
34+
{
35+
context.Log.Write(
36+
LogEntryHelper.InputWithMissingOneOf(
37+
inputType,
38+
schema,
39+
firstInputWithOneOf.Schema));
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)