Validate variable usage is allowed in objects
This commit is contained in:
parent
c018657e25
commit
1c7554c328
@ -1403,6 +1403,20 @@ variablesInAllowedPositionRule = OperationDefinitionRule $ \case
|
|||||||
. traverse (findArgumentVariables variables argumentTypes)
|
. traverse (findArgumentVariables variables argumentTypes)
|
||||||
mapDirectives variables = fmap fold
|
mapDirectives variables = fmap fold
|
||||||
<$> traverse (findDirectiveVariables variables)
|
<$> traverse (findDirectiveVariables variables)
|
||||||
|
lookupInputObject variables objectFieldValue locationInfo
|
||||||
|
| Full.Node{ node = Full.Object objectFields, ..} <- objectFieldValue
|
||||||
|
, Just (expectedType, _) <- locationInfo
|
||||||
|
, In.InputObjectBaseType inputObjectType <- expectedType
|
||||||
|
, In.InputObjectType _ _ fieldTypes' <- inputObjectType =
|
||||||
|
fold <$> traverse (traverseObjectField variables fieldTypes') objectFields
|
||||||
|
| otherwise = pure mempty
|
||||||
|
maybeUsageAllowed variableName variables locationInfo
|
||||||
|
| Just (locationType, locationValue) <- locationInfo
|
||||||
|
, findVariableDefinition' <- findVariableDefinition variableName
|
||||||
|
, Just variableDefinition <- find findVariableDefinition' variables
|
||||||
|
= maybeToSeq
|
||||||
|
<$> isVariableUsageAllowed locationType locationValue variableDefinition
|
||||||
|
| otherwise = pure mempty
|
||||||
findArgumentVariables :: [Full.VariableDefinition]
|
findArgumentVariables :: [Full.VariableDefinition]
|
||||||
-> HashMap Full.Name In.Argument
|
-> HashMap Full.Name In.Argument
|
||||||
-> Full.Argument
|
-> Full.Argument
|
||||||
@ -1410,23 +1424,27 @@ variablesInAllowedPositionRule = OperationDefinitionRule $ \case
|
|||||||
findArgumentVariables variables argumentTypes argument
|
findArgumentVariables variables argumentTypes argument
|
||||||
| Full.Argument argumentName argumentValue _ <- argument
|
| Full.Argument argumentName argumentValue _ <- argument
|
||||||
, Full.Node{ node = Full.Variable variableName, ..} <- argumentValue
|
, Full.Node{ node = Full.Variable variableName, ..} <- argumentValue
|
||||||
, Just expectedType <- HashMap.lookup argumentName argumentTypes
|
= maybeUsageAllowed variableName variables
|
||||||
, findVariableDefinition' <- findVariableDefinition variableName
|
$ locationPair extractArgument argumentTypes argumentName
|
||||||
, Just variableDefinition <- find findVariableDefinition' variables =
|
|
||||||
maybeToSeq <$> isVariableUsageAllowed expectedType variableDefinition
|
|
||||||
| Full.Argument argumentName argumentValue _ <- argument
|
| Full.Argument argumentName argumentValue _ <- argument
|
||||||
, Full.Node{ node = Full.Object objectFields, ..} <- argumentValue
|
= lookupInputObject variables argumentValue
|
||||||
, Just typeArgument <- HashMap.lookup argumentName argumentTypes
|
$ locationPair extractArgument argumentTypes argumentName
|
||||||
, In.Argument _ expectedType _ <- typeArgument
|
extractField (In.InputField _ locationType locationValue) =
|
||||||
, In.InputObjectBaseType inputObjectType <- expectedType
|
(locationType, locationValue)
|
||||||
, In.InputObjectType _ _ fieldTypes <- inputObjectType =
|
extractArgument (In.Argument _ locationType locationValue) =
|
||||||
fold <$> traverse (traverseObjectField fieldTypes) objectFields
|
(locationType, locationValue)
|
||||||
| otherwise = pure mempty
|
locationPair extract fieldTypes name =
|
||||||
traverseObjectField _fieldTypes = const $ pure mempty
|
extract <$> HashMap.lookup name fieldTypes
|
||||||
|
traverseObjectField variables fieldTypes Full.ObjectField{..}
|
||||||
|
| Full.Node{ node = Full.Variable variableName } <- value
|
||||||
|
= maybeUsageAllowed variableName variables
|
||||||
|
$ locationPair extractField fieldTypes name
|
||||||
|
| otherwise = lookupInputObject variables value
|
||||||
|
$ locationPair extractField fieldTypes name
|
||||||
findVariableDefinition variableName variableDefinition =
|
findVariableDefinition variableName variableDefinition =
|
||||||
let Full.VariableDefinition variableName' _ _ _ = variableDefinition
|
let Full.VariableDefinition variableName' _ _ _ = variableDefinition
|
||||||
in variableName == variableName'
|
in variableName == variableName'
|
||||||
isVariableUsageAllowed (In.Argument _ locationType locationDefaultValue) variableDefinition
|
isVariableUsageAllowed locationType locationDefaultValue variableDefinition
|
||||||
| Full.VariableDefinition _ variableType _ _ <- variableDefinition
|
| Full.VariableDefinition _ variableType _ _ <- variableDefinition
|
||||||
, Full.TypeNonNull _ <- variableType =
|
, Full.TypeNonNull _ <- variableType =
|
||||||
typesCompatibleOrError variableDefinition locationType
|
typesCompatibleOrError variableDefinition locationType
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
resolver: lts-16.27
|
resolver: lts-16.31
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
- .
|
- .
|
||||||
|
Loading…
Reference in New Issue
Block a user