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)); } }
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)); } }
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); }
public object ParseLiteral() { try { if (_parsedValue == null) { _parsedValue = Type.ParseLiteral(Value); } return(_parsedValue); } catch (ArgumentException ex) { throw new QueryException( QueryError.CreateVariableError( ex.Message, Name)); } }
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)); }