Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue were schema-first input runtime types were not correctly inferred. #4727

Merged
merged 3 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal sealed class ResolverTypeInterceptor : TypeInterceptor
private readonly List<FieldResolverConfig> _fieldResolvers;
private readonly List<(NameString, Type)> _resolverTypeList;
private readonly Dictionary<NameString, Type> _runtimeTypes;
private readonly Dictionary<string, ParameterInfo> _parameters = new();
private IDescriptorContext _context = default!;
private INamingConventions _naming = default!;
private ITypeInspector _typeInspector = default!;
Expand Down Expand Up @@ -187,6 +188,42 @@ private void ApplyResolverTypes(
objectTypeDef.RuntimeType,
resolverType: member.ReflectedType);

if (member is MethodInfo method)
{
foreach (ParameterInfo parameter in
_resolverCompiler.GetArgumentParameters(method.GetParameters()))
{
_parameters[parameter.Name!] = parameter;
}

foreach (var argument in field.Arguments)
{
if (_parameters.TryGetValue(argument.Name.Value, out var parameter))
{
argument.Parameter = parameter;
argument.RuntimeType = parameter.ParameterType;

if (_typeReferenceResolver.TryGetType(argument.Type!, out var type))
{
Type? unwrapped = Unwrap(parameter.ParameterType, type);
if (unwrapped is not null)
{
#if NET5_0_OR_GREATER
_runtimeTypes.TryAdd(type.NamedType().Name, unwrapped);
#else
if (!_runtimeTypes.ContainsKey(type.NamedType().Name))
{
_runtimeTypes.Add(type.NamedType().Name, unwrapped);
}
#endif
}
}
}
}

_parameters.Clear();
}

TrySetRuntimeTypeFromMember(context, field.Type, member);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ public async Task EnumAsInputType()

enum FooEnum {
BAR
BAZ
BAZ_BAR
}")
.AddResolver<EnumQuery>("Query")
.Create();

// act
IExecutionResult result =
await schema.MakeExecutable().ExecuteAsync(
"{ setEnumValue(value:BAZ) }");
"{ setEnumValue(value:BAZ_BAR) }");

// assert
Assert.Null(result.Errors);
Expand Down Expand Up @@ -196,7 +196,8 @@ public class Payload
public enum FooEnum
{
Bar,
Baz
Baz,
BazBar
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Label": null,
"Path": null,
"Data": {
"setEnumValue": "Baz"
"setEnumValue": "BazBar"
},
"Errors": null,
"Extensions": null,
Expand Down