private static ArgumentValue CreateArgumentValue(
            FieldSelection fieldSelection,
            InputField argument,
            Dictionary <string, IValueNode> argumentValues,
            IVariableCollection variables,
            Path path)
        {
            object argumentValue = null;

            try
            {
                argumentValue = CoerceArgumentValue(
                    argument, variables, argumentValues);
            }
            catch (ScalarSerializationException ex)
            {
                throw new QueryException(QueryError.CreateArgumentError(
                                             ex.Message,
                                             path,
                                             fieldSelection.Nodes.First(),
                                             argument.Name));
            }

            if (argument.Type is NonNullType && argumentValue == null)
            {
                throw new QueryException(QueryError.CreateArgumentError(
                                             $"The argument type of '{argument.Name}' is a " +
                                             "non-null type.",
                                             path,
                                             fieldSelection.Nodes.First(),
                                             argument.Name));
            }

            return(new ArgumentValue(argument.Type, argumentValue));
        }
        public static Dictionary <string, ArgumentValue> CoerceArgumentValues(
            this FieldSelection fieldSelection,
            IVariableCollection variables,
            Path path)
        {
            Dictionary <string, ArgumentValue> coercedArgumentValues =
                new Dictionary <string, ArgumentValue>();

            Dictionary <string, IValueNode> argumentValues =
                fieldSelection.Selection.Arguments
                .Where(t => t.Value != null)
                .ToDictionary(t => t.Name.Value, t => t.Value);

            foreach (InputField argument in fieldSelection.Field.Arguments)
            {
                coercedArgumentValues[argument.Name] = CreateArgumentValue(
                    argument, argumentValues, variables,
                    message => QueryError.CreateArgumentError(
                        message,
                        path,
                        fieldSelection.Nodes.First(),
                        argument.Name));
            }

            return(coercedArgumentValues);
        }