Skip to content

Commit

Permalink
Merge branch 'main' into gai/field-selection-map-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Jan 17, 2025
2 parents acf1d65 + 3a21e79 commit f0331d4
Show file tree
Hide file tree
Showing 92 changed files with 2,917 additions and 931 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 22
cache: "yarn"
cache-dependency-path: "website/yarn.lock"

- name: Install cspell
run: npm install -g cspell
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<PackageVersion Include="System.Reactive" Version="6.0.0" />
<PackageVersion Include="Xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit.v3" Version="1.0.0" />
<PackageVersion Include="xunit.v3" Version="1.0.1" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.12.5" />
<PackageVersion Include="TUnit" Version="0.4.71" />
</ItemGroup>
Expand Down
48 changes: 48 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,54 @@ public static ListType ListType(this IType type)
throw new ArgumentException(TypeResources.TypeExtensions_InvalidStructure);
}

/// <summary>
/// Gets the named type (the most inner type) from a type structure.
/// </summary>
/// <param name="type">
/// The type from which the named type shall be extracted.
/// </param>
/// <typeparam name="T">
/// The expected type of the named type.
/// </typeparam>
/// <returns>
/// Returns the named type.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="type"/> is <c>null</c>.
/// </exception>
/// <exception cref="ArgumentException">
/// The type structure is invalid or
/// the named type is not of the expected type.
/// </exception>
public static T NamedType<T>(this IType type) where T : INamedType
{
var namedType = type.NamedType();

if(namedType is T t)
{
return t;
}

throw new ArgumentException(
"The named type is not of the expected type.",
nameof(type));
}

/// <summary>
/// Gets the named type (the most inner type) from a type structure.
/// </summary>
/// <param name="type">
/// The type from which the named type shall be extracted.
/// </param>
/// <returns>
/// Returns the named type.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="type"/> is <c>null</c>.
/// </exception>
/// <exception cref="ArgumentException">
/// The type structure is invalid.
/// </exception>
public static INamedType NamedType(this IType type)
{
if (type is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,35 @@ public static void NamedType()
Assert.NotNull(stringType);
}

[Fact]
public static void NamedType_Of_T()
{
// arrange
var type = new NonNullType(
new ListType(
new NonNullType(
new StringType())));

// act
var stringType = type.NamedType<StringType>();

// assert
Assert.NotNull(stringType);
}

[Fact]
public static void NamedType_Of_T_Is_Not_Of_T()
{
// arrange
var type = new NonNullType(
new ListType(
new NonNullType(
new StringType())));

// act & assert
Assert.Throws<ArgumentException>(() => type.NamedType<ObjectType>());
}

[Fact]
public static void NamedType_Type_Is_Null()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace HotChocolate.Fusion.Errors;

internal static class ErrorHelper
{
public static CompositionError SourceSchemaValidationFailed()
=> new(ErrorHelper_SourceSchemaValidationFailed);

public static CompositionError PreMergeValidationFailed()
=> new(ErrorHelper_PreMergeValidationFailed);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HotChocolate.Skimmed;
using static HotChocolate.Fusion.WellKnownDirectiveNames;

namespace HotChocolate.Fusion.Extensions;

internal static class DirectivesProviderExtensions
{
public static bool HasExternalDirective(this IDirectivesProvider type)
{
return type.Directives.ContainsName(External);
}

public static bool HasInaccessibleDirective(this IDirectivesProvider type)
{
return type.Directives.ContainsName(Inaccessible);
}

public static bool HasInternalDirective(this IDirectivesProvider type)
{
return type.Directives.ContainsName(Internal);
}

public static bool HasLookupDirective(this IDirectivesProvider type)
{
return type.Directives.ContainsName(Lookup);
}

public static bool HasOverrideDirective(this IDirectivesProvider type)
{
return type.Directives.ContainsName(Override);
}

public static bool HasProvidesDirective(this IDirectivesProvider type)
{
return type.Directives.ContainsName(Provides);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ namespace HotChocolate.Fusion.Logging;
public static class LogEntryCodes
{
public const string DisallowedInaccessible = "DISALLOWED_INACCESSIBLE";
public const string EnumValuesMismatch = "ENUM_VALUES_MISMATCH";
public const string ExternalArgumentDefaultMismatch = "EXTERNAL_ARGUMENT_DEFAULT_MISMATCH";
public const string ExternalMissingOnBase = "EXTERNAL_MISSING_ON_BASE";
public const string ExternalOnInterface = "EXTERNAL_ON_INTERFACE";
public const string ExternalUnused = "EXTERNAL_UNUSED";
public const string FieldArgumentTypesNotMergeable = "FIELD_ARGUMENT_TYPES_NOT_MERGEABLE";
public const string InputFieldDefaultMismatch = "INPUT_FIELD_DEFAULT_MISMATCH";
public const string InputFieldTypesNotMergeable = "INPUT_FIELD_TYPES_NOT_MERGEABLE";
public const string InputWithMissingRequiredFields = "INPUT_WITH_MISSING_REQUIRED_FIELDS";
public const string KeyDirectiveInFieldsArg = "KEY_DIRECTIVE_IN_FIELDS_ARG";
public const string KeyFieldsHasArgs = "KEY_FIELDS_HAS_ARGS";
public const string KeyFieldsSelectInvalidType = "KEY_FIELDS_SELECT_INVALID_TYPE";
public const string KeyInvalidFields = "KEY_INVALID_FIELDS";
public const string KeyInvalidFieldsType = "KEY_INVALID_FIELDS_TYPE";
public const string KeyInvalidSyntax = "KEY_INVALID_SYNTAX";
public const string LookupMustNotReturnList = "LOOKUP_MUST_NOT_RETURN_LIST";
public const string LookupShouldHaveNullableReturnType = "LOOKUP_SHOULD_HAVE_NULLABLE_RETURN_TYPE";
public const string LookupReturnsList = "LOOKUP_RETURNS_LIST";
public const string LookupReturnsNonNullableType = "LOOKUP_RETURNS_NON_NULLABLE_TYPE";
public const string OutputFieldTypesNotMergeable = "OUTPUT_FIELD_TYPES_NOT_MERGEABLE";
public const string OverrideFromSelf = "OVERRIDE_FROM_SELF";
public const string OverrideOnInterface = "OVERRIDE_ON_INTERFACE";
public const string ProvidesDirectiveInFieldsArg = "PROVIDES_DIRECTIVE_IN_FIELDS_ARG";
public const string ProvidesFieldsHasArgs = "PROVIDES_FIELDS_HAS_ARGS";
public const string ProvidesFieldsMissingExternal = "PROVIDES_FIELDS_MISSING_EXTERNAL";
public const string ProvidesInvalidFieldsType = "PROVIDES_INVALID_FIELDS_TYPE";
public const string ProvidesInvalidSyntax = "PROVIDES_INVALID_SYNTAX";
public const string ProvidesOnNonCompositeField = "PROVIDES_ON_NON_COMPOSITE_FIELD";
public const string QueryRootTypeInaccessible = "QUERY_ROOT_TYPE_INACCESSIBLE";
public const string RequireDirectiveInFieldsArg = "REQUIRE_DIRECTIVE_IN_FIELDS_ARG";
Expand Down
Loading

0 comments on commit f0331d4

Please sign in to comment.