Skip to content

Commit e2d2300

Browse files
authored
Skimmed Schema Improvements for Fusion (#7167)
1 parent 41dee1d commit e2d2300

File tree

190 files changed

+5302
-2342
lines changed

Some content is hidden

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

190 files changed

+5302
-2342
lines changed

.build/Helpers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static class Helpers
2525
Path.Combine("HotChocolate", "Marten"),
2626
Path.Combine("HotChocolate", "MongoDb"),
2727
Path.Combine("HotChocolate", "OpenApi"),
28+
Path.Combine("HotChocolate", "Primitives"),
2829
Path.Combine("HotChocolate", "Raven"),
2930
Path.Combine("HotChocolate", "Skimmed"),
3031
Path.Combine("HotChocolate", "Fusion"),

src/CookieCrumble/src/CookieCrumble/CookieCrumble.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\Transport.Abstractions\HotChocolate.Transport.Abstractions.csproj" />
3535
</ItemGroup>
3636

37-
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net8.0'">
37+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
3838
<ProjectReference Include="..\..\..\HotChocolate\Fusion\src\Core\HotChocolate.Fusion.csproj" />
39-
<ProjectReference Include="..\..\..\HotChocolate\Skimmed\src\Skimmed\Skimmed.csproj" />
4039
</ItemGroup>
4140

4241
</Project>

src/CookieCrumble/src/CookieCrumble/Formatters/QueryPlanSnapshotValueFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NET7_0_OR_GREATER
1+
#if NET8_0_OR_GREATER
22
using System.Buffers;
33
using HotChocolate.Fusion.Execution.Nodes;
44

src/CookieCrumble/src/CookieCrumble/Formatters/SkimmedSchemaSnapshotValueFormatter.cs

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

src/CookieCrumble/src/CookieCrumble/LocalFactDiscoverer.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,29 @@ namespace CookieCrumble;
77
[XunitTestCaseDiscoverer("LocalFactDiscoverer", "YourTestAssemblyName")]
88
public class LocalFactAttribute : FactAttribute;
99

10-
public class LocalFactDiscoverer : FactDiscoverer
10+
public class LocalFactDiscoverer(IMessageSink diagnosticMessageSink) : FactDiscoverer(diagnosticMessageSink)
1111
{
12-
private readonly IMessageSink _diagnosticMessageSink;
12+
private readonly IMessageSink _diagnosticMessageSink = diagnosticMessageSink;
1313

14-
public LocalFactDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink)
15-
{
16-
_diagnosticMessageSink = diagnosticMessageSink;
17-
}
18-
19-
20-
protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
14+
protected override IXunitTestCase CreateTestCase(
15+
ITestFrameworkDiscoveryOptions discoveryOptions,
16+
ITestMethod testMethod,
17+
IAttributeInfo factAttribute)
2118
{
2219
if (TestEnvironment.IsLocalEnvironment())
2320
{
24-
return new XunitTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod);
25-
}
26-
else
27-
{
28-
return new ExecutionErrorTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "LocalFact tests cannot run in CI environment");
21+
return new XunitTestCase(
22+
_diagnosticMessageSink,
23+
discoveryOptions.MethodDisplayOrDefault(),
24+
discoveryOptions.MethodDisplayOptionsOrDefault(),
25+
testMethod);
2926
}
27+
28+
return new ExecutionErrorTestCase(
29+
_diagnosticMessageSink,
30+
discoveryOptions.MethodDisplayOrDefault(),
31+
discoveryOptions.MethodDisplayOptionsOrDefault(),
32+
testMethod,
33+
"LocalFact tests cannot run in CI environment");
3034
}
3135
}

src/CookieCrumble/src/CookieCrumble/Snapshot.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ public class Snapshot
3131
new HttpResponseSnapshotValueFormatter(),
3232
new OperationResultSnapshotValueFormatter(),
3333
new JsonElementSnapshotValueFormatter(),
34-
#if NET7_0_OR_GREATER
34+
#if NET8_0_OR_GREATER
3535
new QueryPlanSnapshotValueFormatter(),
36-
new SkimmedSchemaSnapshotValueFormatter(),
3736
#endif
3837
});
3938
private static readonly JsonSnapshotValueFormatter _defaultFormatter = new();

src/HotChocolate/Core/src/Abstractions/HotChocolate.Abstractions.csproj

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

2323

2424
<ItemGroup>
25-
<ProjectReference Include="..\..\..\Language\src\Language\HotChocolate.Language.csproj" />
25+
<ProjectReference Include="..\..\..\Primitives\src\Primitives\HotChocolate.Primitives.csproj" />
2626
</ItemGroup>
2727

2828
<ItemGroup>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Collections;
2+
using System.Diagnostics.CodeAnalysis;
3+
4+
namespace HotChocolate.Features;
5+
6+
public sealed class EmptyFeatureCollection : IFeatureCollection
7+
{
8+
private EmptyFeatureCollection()
9+
{
10+
}
11+
12+
public bool IsReadOnly => true;
13+
14+
public int Revision => 0;
15+
16+
public object? this[Type key]
17+
{
18+
get => default;
19+
set => ThrowReadOnly();
20+
}
21+
22+
/// <inheritdoc />
23+
public TFeature? Get<TFeature>()
24+
=> default;
25+
26+
/// <inheritdoc />
27+
public void Set<TFeature>(TFeature? instance)
28+
=> ThrowReadOnly();
29+
30+
[DoesNotReturn]
31+
private static void ThrowReadOnly()
32+
=> throw new NotSupportedException("The feature collection is read-only.");
33+
34+
/// <inheritdoc />
35+
public IEnumerator<KeyValuePair<Type, object>> GetEnumerator()
36+
{
37+
yield break;
38+
}
39+
40+
/// <inheritdoc />
41+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
42+
43+
public static EmptyFeatureCollection Default { get; } = new();
44+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This code was originally forked of https://github.com/dotnet/aspnetcore/tree/c7aae8ff34dce81132d0fb3a976349dcc01ff903/src/Extensions/Features/src
2+
3+
namespace HotChocolate.Features;
4+
5+
/// <summary>
6+
/// An object that has features.
7+
/// </summary>
8+
public interface IFeatureProvider
9+
{
10+
/// <summary>
11+
/// Gets the feature collection.
12+
/// </summary>
13+
IFeatureCollection Features { get; }
14+
}

src/HotChocolate/Core/src/Features/ReadOnlyFeatureCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public object? this[Type key]
6666
}
6767

6868
/// <inheritdoc />
69-
public void Set<TFeature>(TFeature? instance) =>
70-
throw new NotSupportedException("The feature collection is read-only.");
69+
public void Set<TFeature>(TFeature? instance)
70+
=> throw new NotSupportedException("The feature collection is read-only.");
7171

7272
/// <inheritdoc />
7373
public IEnumerator<KeyValuePair<Type, object>> GetEnumerator() => _features.GetEnumerator();

src/HotChocolate/Core/src/Types/Types/DirectiveCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private static IEnumerable<Directive> FindDirectives(Directive[] directives, str
8181

8282
return null;
8383
}
84-
84+
8585
/// <inheritdoc />
8686
public Directive? FirstOrDefault<TRuntimeType>()
8787
{
@@ -230,7 +230,7 @@ internal static DirectiveCollection CreateAndComplete(
230230

231231
// If we had any errors while building the directives list we will
232232
// clean the null entries out so that the list is consistent.
233-
// We only do that so we can collect other schema errors as well and do
233+
// We only do that, so we can collect other schema errors as well and do
234234
// not have to fully fail here but have one SchemaException at the end of
235235
// the schema creation that contains a list of errors.
236236
if (hasErrors)

src/HotChocolate/Fusion/Directory.Build.props

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

44
<PropertyGroup>
5-
<TargetFrameworks>$(Library3TargetFrameworks)</TargetFrameworks>
5+
<TargetFrameworks>net8.0</TargetFrameworks>
66
</PropertyGroup>
77

88
</Project>

src/HotChocolate/Fusion/src/Composition/CompositionContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public CompositionContext(
5959
/// <summary>
6060
/// Gets the subgraph schemas.
6161
/// </summary>
62-
public List<Schema> Subgraphs { get; } = [];
62+
public List<SchemaDefinition> Subgraphs { get; } = [];
6363

6464
/// <summary>
6565
/// Get the grouped subgraph entities.
@@ -69,7 +69,7 @@ public CompositionContext(
6969
/// <summary>
7070
/// Gets the fusion graph schema.
7171
/// </summary>
72-
public Schema FusionGraph { get; }
72+
public SchemaDefinition FusionGraph { get; }
7373

7474
/// <summary>
7575
/// Gets the fusion types.
@@ -105,7 +105,7 @@ public CompositionContext(
105105
/// <returns>
106106
/// Returns the subgraph schema.
107107
/// </returns>
108-
public Schema GetSubgraphSchema(string subgraphName)
108+
public SchemaDefinition GetSubgraphSchema(string subgraphName)
109109
=> Subgraphs.First(t => t.Name.EqualsOrdinal(subgraphName));
110110

111111
/// <summary>
@@ -130,11 +130,11 @@ public bool TryGetSubgraphMember<T>(
130130
string subgraphName,
131131
SchemaCoordinate coordinate,
132132
[NotNullWhen(true)] out T? member)
133-
where T : ITypeSystemMember
133+
where T : ITypeSystemMemberDefinition
134134
=> GetSubgraphSchema(subgraphName).TryGetMember(coordinate, out member);
135135

136136
public IEnumerable<T> GetSubgraphMembers<T>(SchemaCoordinate coordinate)
137-
where T : ITypeSystemMember
137+
where T : ITypeSystemMemberDefinition
138138
{
139139
foreach (var subgraph in Subgraphs)
140140
{

src/HotChocolate/Fusion/src/Composition/Directives/DirectivesHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using HotChocolate.Language;
22
using HotChocolate.Utilities;
33
using static HotChocolate.Fusion.Composition.Properties.CompositionResources;
4-
using IHasDirectives = HotChocolate.Skimmed.IHasDirectives;
4+
using IDirectivesProvider = HotChocolate.Skimmed.IDirectivesProvider;
55

66
namespace HotChocolate.Fusion.Composition;
77

@@ -15,10 +15,10 @@ internal static class DirectivesHelper
1515
public const string NewNameArg = "newName";
1616
public const string FieldArg = "field";
1717

18-
public static bool ContainsIsDirective(this IHasDirectives member)
18+
public static bool ContainsIsDirective(this IDirectivesProvider member)
1919
=> member.Directives.ContainsName(IsDirectiveName);
2020

21-
public static IsDirective GetIsDirective(this IHasDirectives member)
21+
public static IsDirective GetIsDirective(this IDirectivesProvider member)
2222
{
2323
var directive = member.Directives[IsDirectiveName].First();
2424

@@ -40,10 +40,10 @@ public static IsDirective GetIsDirective(this IHasDirectives member)
4040
DirectivesHelper_GetIsDirective_NoFieldAndNoCoordinate);
4141
}
4242

43-
public static bool ContainsRequireDirective(this IHasDirectives member)
43+
public static bool ContainsRequireDirective(this IDirectivesProvider member)
4444
=> member.Directives.ContainsName(RequireDirectiveName);
4545

46-
public static RequireDirective GetRequireDirective(this IHasDirectives member)
46+
public static RequireDirective GetRequireDirective(this IDirectivesProvider member)
4747
{
4848
var directive = member.Directives[RequireDirectiveName].First();
4949
var arg = directive.Arguments.FirstOrDefault(t => t.Name.EqualsOrdinal(FieldArg));

src/HotChocolate/Fusion/src/Composition/Entities/EntityPart.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace HotChocolate.Fusion.Composition;
44

55
/// <summary>
6-
/// Represents an entity part that maps to an <see cref="ObjectType"/> in a <see cref="Schema"/>.
6+
/// Represents an entity part that maps to an <see cref="ObjectTypeDefinition"/> in a <see cref="Schema"/>.
77
/// </summary>
88
/// <param name="Type">
9-
/// The <see cref="ObjectType"/> that defines the structure of the entity.
9+
/// The <see cref="ObjectTypeDefinition"/> that defines the structure of the entity.
1010
/// </param>
1111
/// <param name="Schema">
12-
/// The schema to which the <see cref="ObjectType"/> belongs.
12+
/// The schema to which the <see cref="ObjectTypeDefinition"/> belongs.
1313
/// </param>
14-
internal sealed record EntityPart(ObjectType Type, Schema Schema);
14+
internal sealed record EntityPart(ObjectTypeDefinition Type, SchemaDefinition Schema);

src/HotChocolate/Fusion/src/Composition/Entities/MemberReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
namespace HotChocolate.Fusion.Composition;
55

6-
internal sealed record MemberReference(InputField Argument, FieldNode Requirement);
6+
internal sealed record MemberReference(InputFieldDefinition Argument, FieldNode Requirement);

src/HotChocolate/Fusion/src/Composition/Extensions/ComplexTypeMergeExtensions.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ internal static class ComplexTypeMergeExtensions
77
{
88
// This extension method creates a new OutputField by replacing the type name of each field
99
// in the source with the corresponding type name in the target schema.
10-
public static OutputField CreateField(
10+
public static OutputFieldDefinition CreateField(
1111
this CompositionContext context,
12-
OutputField source,
13-
Schema targetSchema)
12+
OutputFieldDefinition source,
13+
SchemaDefinition targetSchema)
1414
{
15-
var target = new OutputField(source.Name);
15+
var target = new OutputFieldDefinition(source.Name);
1616
target.MergeDescriptionWith(source);
1717
target.MergeDeprecationWith(source);
1818

@@ -24,14 +24,14 @@ public static OutputField CreateField(
2424
// in the source with the corresponding type name in the target schema.
2525
foreach (var sourceArgument in source.Arguments)
2626
{
27-
var targetArgument = new InputField(sourceArgument.Name);
27+
var targetArgument = new InputFieldDefinition(sourceArgument.Name);
2828
targetArgument.MergeDescriptionWith(sourceArgument);
2929
targetArgument.DefaultValue = sourceArgument.DefaultValue;
3030

3131
// Replace the type name of the argument in the source with the corresponding type name
3232
// in the target schema.
3333
targetArgument.Type = sourceArgument.Type.ReplaceNameType(n => targetSchema.Types[n]);
34-
34+
3535
targetArgument.MergeDeprecationWith(sourceArgument);
3636

3737
target.Arguments.Add(targetArgument);
@@ -45,8 +45,8 @@ public static OutputField CreateField(
4545
// names or if the number of arguments does not match.
4646
public static void MergeField(
4747
this CompositionContext context,
48-
OutputField source,
49-
OutputField target,
48+
OutputFieldDefinition source,
49+
OutputFieldDefinition target,
5050
string typeName)
5151
{
5252
var mergedType = MergeOutputType(source.Type, target.Type);
@@ -85,7 +85,7 @@ public static void MergeField(
8585
if (source.Arguments.TryGetField(targetArgument.Name, out var sourceArgument))
8686
{
8787
argMatchCount++;
88-
88+
8989
var mergedInputType = MergeInputType(sourceArgument.Type, targetArgument.Type);
9090

9191
if (mergedInputType is null)
@@ -98,7 +98,7 @@ public static void MergeField(
9898
targetArgument.Type));
9999
return;
100100
}
101-
101+
102102
if(!targetArgument.Type.Equals(mergedInputType, TypeComparison.Structural))
103103
{
104104
targetArgument.Type = mergedInputType;
@@ -145,4 +145,4 @@ public static void MergeField(
145145
}
146146
}
147147
}
148-
}
148+
}

0 commit comments

Comments
 (0)