Skip to content

Commit

Permalink
8.0.0-rc.3
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccallum committed Oct 18, 2021
1 parent abed5a6 commit ad0e4e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageIconUrl>https://github.com/benmccallum/fairybread/raw/master/logo-400x400.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/benmccallum/fairybread/blob/master/LICENSE</PackageLicenseUrl>

<Version>8.0.0-rc.2</Version>
<Version>8.0.0-rc.3</Version>

<HotChocolateVersion>12.0.1</HotChocolateVersion>

Expand Down
23 changes: 19 additions & 4 deletions src/FairyBread/ValidationMiddlewareInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void OnBeforeCompleteType(
// 3. the arg actually has a validator for it's runtime type
if (options.OptimizeMiddlewarePlacement)
{
var (allowUnknown, argRuntimeType) = TryGetArgRuntimeType(argDef);
var (allowUnknown, argRuntimeType) = TryGetArgRuntimeType(objTypeDef, fieldDef, argDef);
if (argRuntimeType is null)
{
if (!allowUnknown &&
Expand Down Expand Up @@ -86,21 +86,36 @@ public override void OnBeforeCompleteType(
}
}

private static (bool AllowUnknown, Type? Type) TryGetArgRuntimeType(ArgumentDefinition argDef)
private static (bool AllowUnknown, Type? Type) TryGetArgRuntimeType(
ObjectTypeDefinition objTypeDef,
ObjectFieldDefinition fieldDef,
ArgumentDefinition argDef)
{
if (argDef.Parameter?.ParameterType is { } argRuntimeType)
{
return (false, argRuntimeType);
}

if (argDef.Type is SyntaxTypeReference synTypeRef)
if (argDef.Type is SyntaxTypeReference)
{
return (true, null);
}

if (argDef.Type is ExtendedTypeReference extTypeRef)
{
return (false, TryGetRuntimeType(extTypeRef.Type));
try
{
return (false, TryGetRuntimeType(extTypeRef.Type));
}
catch (Exception ex)
{
throw new Exception(
$"Problem getting runtime type for argument '{argDef.Name}' " +
$"in field '{fieldDef.Name}' on object type '{objTypeDef.Name}'. " +
$"Disable {nameof(IFairyBreadOptions.OptimizeMiddlewarePlacement)} in " +
$"options and report the issue on GitHub.",
ex);
}
}

return (false, null);
Expand Down

0 comments on commit ad0e4e3

Please sign in to comment.