private void ReportNonNullError() { ReportError(QueryError.CreateFieldError( "Cannot return null for non-nullable field.", Path, Selection.Selection)); }
public void CompleteValue( IFieldValueCompletionContext completionContext, Action <IFieldValueCompletionContext> nextHandler) { if (completionContext.Type.IsObjectType() || completionContext.Type.IsInterfaceType() || completionContext.Type.IsUnionType()) { ObjectType objectType = ResolveObjectType( completionContext.ResolverContext, completionContext.Type, completionContext.Value); if (objectType == null) { completionContext.ReportError(QueryError.CreateFieldError( "Could not resolve the schema type from " + $"`{completionContext.Value.GetType().GetTypeName()}`.", completionContext.Path, completionContext.Selection.Selection)); return; } CompleteObjectValue(completionContext, objectType); } else { nextHandler?.Invoke(completionContext); } }
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); }
private static void ResolveFieldSelection( ObjectType type, FieldNode fieldSelection, Action <QueryError> reportError, Dictionary <string, FieldSelection> fields) { NameString fieldName = fieldSelection.Name.Value; if (type.Fields.TryGetField(fieldName, out ObjectField field)) { string name = fieldSelection.Alias == null ? fieldSelection.Name.Value : fieldSelection.Alias.Value; if (fields.TryGetValue(name, out FieldSelection selection)) { fields[name] = selection.Merge(fieldSelection); } else { fields.Add(name, FieldSelection.Create( fieldSelection, field, name)); } } else { reportError(QueryError.CreateFieldError( "Could not resolve the specified field.", fieldSelection)); } }
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)); }
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 static IError WithSyntaxNodes( this IError error, params ISyntaxNode[] nodes) { return(new QueryError( error.Message, error.Path, QueryError.CreateLocations(nodes), error.Extensions?.ToImmutableDictionary())); }
public void Create_OnlyError_DataIsNull() { // arrange QueryError error = new QueryError("foo"); // act var result = new QueryResult(error); // assert Assert.Null(result.Data); }
public void ReportError(string message) { if (string.IsNullOrEmpty(message)) { throw new ArgumentNullException(nameof(message)); } ExecutionContext.ReportError(QueryError.CreateFieldError( message, Path, Selection.Selection)); _integrateResult(null); }
public void Create_WithOneError_ContainsOneError() { // arrange QueryError error = new QueryError("foo"); // act var result = new QueryResult(error); // assert Assert.Collection(result.Errors, t => Assert.Equal(error, t)); }
public IQueryError CreateError(string message) { if (string.IsNullOrEmpty(message)) { throw new ArgumentException( "A field error mustn't be null or empty.", nameof(message)); } return(QueryError.CreateFieldError( message, Path, FieldSelection.Selection)); }
public Task InvokeAsync(IQueryContext context) { if (_options.UseComplexityMultipliers == true && _options.MaxOperationComplexity.HasValue) { if (IsContextIncomplete(context)) { context.Result = QueryResult.CreateError(new QueryError( "The max complexity middleware expects the " + "query document to be parsed and the operation " + "to be resolved.")); return(Task.CompletedTask); } else { var visitorContext = MaxComplexityVisitorContext.New( context.Schema, context.Operation.Variables, _calculation); int complexity = _visitor.Visit( context.Document, context.Operation.Definition, visitorContext); if (IsAllowedComplexity(complexity)) { return(_next(context)); } else { Location[] locations = context.Operation.Definition.Location == null ? null : QueryError.ConvertLocation( context.Operation.Definition.Location); context.Result = QueryResult.CreateError(new QueryError( "The operation that shall be executed has a " + $"complexity of {complexity}. \n" + "The maximum allowed query complexity is " + $"{_options.MaxOperationComplexity}.", locations)); return(Task.CompletedTask); } } } return(_next(context)); }
public IError CreateError(string message) { if (string.IsNullOrEmpty(message)) { throw new ArgumentException( CoreResources.ResolverTask_ErrorMessageIsNull, nameof(message)); } return(QueryError.CreateFieldError( message, Path, FieldSelection.Selection)); }
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)); } }
public static object CompleteResolverResult( this IResolverContext resolverContext, object resolverResult) { if (resolverResult is IResolverResult r) { if (r.IsError) { return(QueryError.CreateFieldError( r.ErrorMessage, resolverContext.Path, resolverContext.FieldSelection)); } return(r.Value); } return(resolverResult); }
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)); }
public QueryException(QueryError error) { }