Skip to content

Commit

Permalink
Factor out argument node creation for Key directive
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonC9018 committed Dec 13, 2023
1 parent b808873 commit 4a4ab6e
Showing 1 changed file with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,9 @@ public static IEntityResolverDescriptor Key(
nameof(fieldSet));
}

var arguments = new List<ArgumentNode>
{
new ArgumentNode(
WellKnownArgumentNames.Fields,
new StringValueNode(fieldSet)),
};
if (false == resolvable)
{
arguments.Add(
new ArgumentNode(
WellKnownArgumentNames.Resolvable,
new BooleanValueNode(false))
);
}
var arguments = CreateKeyArgumentNodes(fieldSet, resolvable);

descriptor.Directive(
WellKnownTypeNames.Key,
arguments.ToArray());
descriptor.Directive(WellKnownTypeNames.Key, arguments);

return new EntityResolverDescriptor<object>(descriptor);
}
Expand All @@ -331,24 +316,34 @@ public static IInterfaceTypeDescriptor Key(
nameof(fieldSet));
}

var arguments = new List<ArgumentNode>
var arguments = CreateKeyArgumentNodes(fieldSet, resolvable);

return descriptor.Directive(WellKnownTypeNames.Key, arguments);
}

private static ArgumentNode[] CreateKeyArgumentNodes(string fieldSet, bool? resolvable)
{
bool notResolvable = resolvable is false;

int argumentCount = 1;
if (notResolvable)
{
new ArgumentNode(
WellKnownArgumentNames.Fields,
new StringValueNode(fieldSet)),
};
if (false == resolvable)
argumentCount++;
}

var arguments = new ArgumentNode[argumentCount];
arguments[0] = new ArgumentNode(
WellKnownArgumentNames.Fields,
new StringValueNode(fieldSet));
if (notResolvable)
{
arguments.Add(
arguments[1] =
new ArgumentNode(
WellKnownArgumentNames.Resolvable,
new BooleanValueNode(false))
);
new BooleanValueNode(false));
}

return descriptor.Directive(
WellKnownTypeNames.Key,
arguments.ToArray());
return arguments;
}

/// <summary>
Expand Down

0 comments on commit 4a4ab6e

Please sign in to comment.