Make args
optional in readField
(i.e. infer them)
#441
Labels
📕 cache
Feature requests related to the cache
args
optional in readField
(i.e. infer them)
#441
We use client-resolved fields to compute new fields that rely on other fields that are returned by a graphql server e.g. in the following case, resolving
isCompleted
uses thecompletionState
field:We need to pass the
args
toreadField
otherwise it doesn't find the data we want. This makes sense, since thecompletion
value will be different depending on the value offilters
.The trouble arises when another argument is added to the
completionState
field, but is not added to theargs
passed toreadField
. In that case,isCompleted
stops working as expected and instead fails silently, leading to incorrect data getting returned. There's no way to indicate thatisCompleted
is dependent uponcompletionState
besides:isCompleted
and throwing or logging an errorAdding the explicit check might seem sufficient, but unfortunately it only runs at run-time so it's easy for this to slip through unnoticed.
This issue proposes updating the implementation of
readField
such that the default behaviour is to apply theargs
that the field was called with if there's only field/args pair for that field. That is, if my query only includes one instance ofcompletionState
, havereadField
return that value regardless of what args it was called with. If there are more than one, then fallback to the current behaviour whereundefined
is returned (or throw an error, print a warning etc) -- in this case the consumer would need to passargs
so they're explicit about what they want. I'm guessing thatargs
are required because there might be multiple instances of the same field with different args -- though I'm not sure about this, nor if graphql allows doing that without adding aliases for the different instances.So for the query above, the type policy would be:
And it would keep doing the right thing regardless what args are passed to
completionState
.The text was updated successfully, but these errors were encountered: