Skip to content

Commit

Permalink
Skimmed Schema Improvements for Fusion (#7167)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jun 17, 2024
1 parent 41dee1d commit e2d2300
Show file tree
Hide file tree
Showing 190 changed files with 5,302 additions and 2,342 deletions.
1 change: 1 addition & 0 deletions .build/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static class Helpers
Path.Combine("HotChocolate", "Marten"),
Path.Combine("HotChocolate", "MongoDb"),
Path.Combine("HotChocolate", "OpenApi"),
Path.Combine("HotChocolate", "Primitives"),
Path.Combine("HotChocolate", "Raven"),
Path.Combine("HotChocolate", "Skimmed"),
Path.Combine("HotChocolate", "Fusion"),
Expand Down
3 changes: 1 addition & 2 deletions src/CookieCrumble/src/CookieCrumble/CookieCrumble.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\Transport.Abstractions\HotChocolate.Transport.Abstractions.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net8.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<ProjectReference Include="..\..\..\HotChocolate\Fusion\src\Core\HotChocolate.Fusion.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Skimmed\src\Skimmed\Skimmed.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
using System.Buffers;
using HotChocolate.Fusion.Execution.Nodes;

Expand Down

This file was deleted.

32 changes: 18 additions & 14 deletions src/CookieCrumble/src/CookieCrumble/LocalFactDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ namespace CookieCrumble;
[XunitTestCaseDiscoverer("LocalFactDiscoverer", "YourTestAssemblyName")]
public class LocalFactAttribute : FactAttribute;

public class LocalFactDiscoverer : FactDiscoverer
public class LocalFactDiscoverer(IMessageSink diagnosticMessageSink) : FactDiscoverer(diagnosticMessageSink)
{
private readonly IMessageSink _diagnosticMessageSink;
private readonly IMessageSink _diagnosticMessageSink = diagnosticMessageSink;

public LocalFactDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink)
{
_diagnosticMessageSink = diagnosticMessageSink;
}


protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
protected override IXunitTestCase CreateTestCase(
ITestFrameworkDiscoveryOptions discoveryOptions,
ITestMethod testMethod,
IAttributeInfo factAttribute)
{
if (TestEnvironment.IsLocalEnvironment())
{
return new XunitTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod);
}
else
{
return new ExecutionErrorTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, "LocalFact tests cannot run in CI environment");
return new XunitTestCase(
_diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod);
}

return new ExecutionErrorTestCase(
_diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod,
"LocalFact tests cannot run in CI environment");
}
}
3 changes: 1 addition & 2 deletions src/CookieCrumble/src/CookieCrumble/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public class Snapshot
new HttpResponseSnapshotValueFormatter(),
new OperationResultSnapshotValueFormatter(),
new JsonElementSnapshotValueFormatter(),
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
new QueryPlanSnapshotValueFormatter(),
new SkimmedSchemaSnapshotValueFormatter(),
#endif
});
private static readonly JsonSnapshotValueFormatter _defaultFormatter = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


<ItemGroup>
<ProjectReference Include="..\..\..\Language\src\Language\HotChocolate.Language.csproj" />
<ProjectReference Include="..\..\..\Primitives\src\Primitives\HotChocolate.Primitives.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
44 changes: 44 additions & 0 deletions src/HotChocolate/Core/src/Features/EmptyFeatureCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;

namespace HotChocolate.Features;

public sealed class EmptyFeatureCollection : IFeatureCollection
{
private EmptyFeatureCollection()
{
}

public bool IsReadOnly => true;

public int Revision => 0;

public object? this[Type key]
{
get => default;
set => ThrowReadOnly();
}

/// <inheritdoc />
public TFeature? Get<TFeature>()
=> default;

/// <inheritdoc />
public void Set<TFeature>(TFeature? instance)
=> ThrowReadOnly();

[DoesNotReturn]
private static void ThrowReadOnly()
=> throw new NotSupportedException("The feature collection is read-only.");

/// <inheritdoc />
public IEnumerator<KeyValuePair<Type, object>> GetEnumerator()
{
yield break;
}

/// <inheritdoc />
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public static EmptyFeatureCollection Default { get; } = new();
}
14 changes: 14 additions & 0 deletions src/HotChocolate/Core/src/Features/IFeatureProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This code was originally forked of https://github.com/dotnet/aspnetcore/tree/c7aae8ff34dce81132d0fb3a976349dcc01ff903/src/Extensions/Features/src

namespace HotChocolate.Features;

/// <summary>
/// An object that has features.
/// </summary>
public interface IFeatureProvider
{
/// <summary>
/// Gets the feature collection.
/// </summary>
IFeatureCollection Features { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public object? this[Type key]
}

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

/// <inheritdoc />
public IEnumerator<KeyValuePair<Type, object>> GetEnumerator() => _features.GetEnumerator();
Expand Down
4 changes: 2 additions & 2 deletions src/HotChocolate/Core/src/Types/Types/DirectiveCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static IEnumerable<Directive> FindDirectives(Directive[] directives, str

return null;
}

/// <inheritdoc />
public Directive? FirstOrDefault<TRuntimeType>()
{
Expand Down Expand Up @@ -230,7 +230,7 @@ internal static DirectiveCollection CreateAndComplete(

// If we had any errors while building the directives list we will
// clean the null entries out so that the list is consistent.
// We only do that so we can collect other schema errors as well and do
// We only do that, so we can collect other schema errors as well and do
// not have to fully fail here but have one SchemaException at the end of
// the schema creation that contains a list of errors.
if (hasErrors)
Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/Fusion/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<TargetFrameworks>$(Library3TargetFrameworks)</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

</Project>
10 changes: 5 additions & 5 deletions src/HotChocolate/Fusion/src/Composition/CompositionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public CompositionContext(
/// <summary>
/// Gets the subgraph schemas.
/// </summary>
public List<Schema> Subgraphs { get; } = [];
public List<SchemaDefinition> Subgraphs { get; } = [];

/// <summary>
/// Get the grouped subgraph entities.
Expand All @@ -69,7 +69,7 @@ public CompositionContext(
/// <summary>
/// Gets the fusion graph schema.
/// </summary>
public Schema FusionGraph { get; }
public SchemaDefinition FusionGraph { get; }

/// <summary>
/// Gets the fusion types.
Expand Down Expand Up @@ -105,7 +105,7 @@ public CompositionContext(
/// <returns>
/// Returns the subgraph schema.
/// </returns>
public Schema GetSubgraphSchema(string subgraphName)
public SchemaDefinition GetSubgraphSchema(string subgraphName)
=> Subgraphs.First(t => t.Name.EqualsOrdinal(subgraphName));

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

public IEnumerable<T> GetSubgraphMembers<T>(SchemaCoordinate coordinate)
where T : ITypeSystemMember
where T : ITypeSystemMemberDefinition
{
foreach (var subgraph in Subgraphs)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using HotChocolate.Language;
using HotChocolate.Utilities;
using static HotChocolate.Fusion.Composition.Properties.CompositionResources;
using IHasDirectives = HotChocolate.Skimmed.IHasDirectives;
using IDirectivesProvider = HotChocolate.Skimmed.IDirectivesProvider;

namespace HotChocolate.Fusion.Composition;

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

public static bool ContainsIsDirective(this IHasDirectives member)
public static bool ContainsIsDirective(this IDirectivesProvider member)
=> member.Directives.ContainsName(IsDirectiveName);

public static IsDirective GetIsDirective(this IHasDirectives member)
public static IsDirective GetIsDirective(this IDirectivesProvider member)
{
var directive = member.Directives[IsDirectiveName].First();

Expand All @@ -40,10 +40,10 @@ public static IsDirective GetIsDirective(this IHasDirectives member)
DirectivesHelper_GetIsDirective_NoFieldAndNoCoordinate);
}

public static bool ContainsRequireDirective(this IHasDirectives member)
public static bool ContainsRequireDirective(this IDirectivesProvider member)
=> member.Directives.ContainsName(RequireDirectiveName);

public static RequireDirective GetRequireDirective(this IHasDirectives member)
public static RequireDirective GetRequireDirective(this IDirectivesProvider member)
{
var directive = member.Directives[RequireDirectiveName].First();
var arg = directive.Arguments.FirstOrDefault(t => t.Name.EqualsOrdinal(FieldArg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace HotChocolate.Fusion.Composition;

/// <summary>
/// Represents an entity part that maps to an <see cref="ObjectType"/> in a <see cref="Schema"/>.
/// Represents an entity part that maps to an <see cref="ObjectTypeDefinition"/> in a <see cref="Schema"/>.
/// </summary>
/// <param name="Type">
/// The <see cref="ObjectType"/> that defines the structure of the entity.
/// The <see cref="ObjectTypeDefinition"/> that defines the structure of the entity.
/// </param>
/// <param name="Schema">
/// The schema to which the <see cref="ObjectType"/> belongs.
/// The schema to which the <see cref="ObjectTypeDefinition"/> belongs.
/// </param>
internal sealed record EntityPart(ObjectType Type, Schema Schema);
internal sealed record EntityPart(ObjectTypeDefinition Type, SchemaDefinition Schema);
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

namespace HotChocolate.Fusion.Composition;

internal sealed record MemberReference(InputField Argument, FieldNode Requirement);
internal sealed record MemberReference(InputFieldDefinition Argument, FieldNode Requirement);
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ internal static class ComplexTypeMergeExtensions
{
// This extension method creates a new OutputField by replacing the type name of each field
// in the source with the corresponding type name in the target schema.
public static OutputField CreateField(
public static OutputFieldDefinition CreateField(
this CompositionContext context,
OutputField source,
Schema targetSchema)
OutputFieldDefinition source,
SchemaDefinition targetSchema)
{
var target = new OutputField(source.Name);
var target = new OutputFieldDefinition(source.Name);
target.MergeDescriptionWith(source);
target.MergeDeprecationWith(source);

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

// Replace the type name of the argument in the source with the corresponding type name
// in the target schema.
targetArgument.Type = sourceArgument.Type.ReplaceNameType(n => targetSchema.Types[n]);

targetArgument.MergeDeprecationWith(sourceArgument);

target.Arguments.Add(targetArgument);
Expand All @@ -45,8 +45,8 @@ public static OutputField CreateField(
// names or if the number of arguments does not match.
public static void MergeField(
this CompositionContext context,
OutputField source,
OutputField target,
OutputFieldDefinition source,
OutputFieldDefinition target,
string typeName)
{
var mergedType = MergeOutputType(source.Type, target.Type);
Expand Down Expand Up @@ -85,7 +85,7 @@ public static void MergeField(
if (source.Arguments.TryGetField(targetArgument.Name, out var sourceArgument))
{
argMatchCount++;

var mergedInputType = MergeInputType(sourceArgument.Type, targetArgument.Type);

if (mergedInputType is null)
Expand All @@ -98,7 +98,7 @@ public static void MergeField(
targetArgument.Type));
return;
}

if(!targetArgument.Type.Equals(mergedInputType, TypeComparison.Structural))
{
targetArgument.Type = mergedInputType;
Expand Down Expand Up @@ -145,4 +145,4 @@ public static void MergeField(
}
}
}
}
}
Loading

0 comments on commit e2d2300

Please sign in to comment.