Exemplo n.º 1
0
 private void CheckForNullValueViolation(Variable variable)
 {
     if (variable.Type.IsNonNullType() && variable.Value is null)
     {
         throw new QueryException(QueryError.CreateVariableError(
                                      "The variable value cannot be null.",
                                      variable.Name));
     }
 }
Exemplo n.º 2
0
 private void CheckForInvalidValueType(Variable variable)
 {
     if (!variable.Type.IsInstanceOfType(variable.Value))
     {
         throw new QueryException(QueryError.CreateVariableError(
                                      "The variable value is not of the correct type.",
                                      variable.Name));
     }
 }
Exemplo n.º 3
0
        public T GetVariable <T>(string variableName)
        {
            if (string.IsNullOrEmpty(variableName))
            {
                throw new ArgumentNullException(nameof(variableName));
            }

            if (!TryGetVariable(variableName, out T variableValue))
            {
                throw new QueryException(QueryError.CreateVariableError(
                                             "The specified variable was not declared.",
                                             variableName));
            }

            return(variableValue);
        }
Exemplo n.º 4
0
 public object ParseLiteral()
 {
     try
     {
         if (_parsedValue == null)
         {
             _parsedValue = Type.ParseLiteral(Value);
         }
         return(_parsedValue);
     }
     catch (ArgumentException ex)
     {
         throw new QueryException(
                   QueryError.CreateVariableError(
                       ex.Message, Name));
     }
 }
Exemplo n.º 5
0
        private Variable CreateVariable(
            VariableDefinitionNode variableDefinition)
        {
            string variableName = variableDefinition.Variable.Name.Value;
            IType  variableType = GetType(variableDefinition.Type);

            if (variableType is IInputType type)
            {
                return(new Variable(
                           variableName, type,
                           variableDefinition.DefaultValue));
            }

            throw new QueryException(QueryError.CreateVariableError(
                                         $"The variable type ({variableType.ToString()}) " +
                                         "must be an input object type.",
                                         variableName));
        }