private static async Task <object> CompleteInterfaceValueAsync( IExecutorContext executorContext, ObjectType actualType, IReadOnlyCollection <GraphQLFieldSelection> fields, object value, NodePath path, InterfaceType interfaceType) { if (!actualType.Implements(interfaceType)) { throw new CompleteValueException( "Cannot complete value as interface. " + $"Actual type {actualType.Name} does not implement {interfaceType.Name}", path, fields.First()); } var subSelectionSet = SelectionSets.MergeSelectionSets(fields); var data = await SelectionSets.ExecuteSelectionSetAsync( executorContext, subSelectionSet, actualType, value, path).ConfigureAwait(false); return(data); }
public static object?Handle( IExecutorContext context, ObjectDefinition objectDefinition, string fieldName, TypeBase fieldType, FieldSelection fieldSelection, object?completedValue, Exception error, NodePath path) { if (error is not QueryExecutionException) { error = new QueryExecutionException( "", error, path, fieldSelection); } if (fieldType is NonNullType) { throw error; } context.AddError(error); return(completedValue); }
private static async Task <object> CompleteUnionValueAsync( IExecutorContext executorContext, ObjectType actualType, IReadOnlyCollection <GraphQLFieldSelection> fields, object value, NodePath path, UnionType unionType) { if (!unionType.IsPossible(actualType)) { throw new CompleteValueException( "Cannot complete value as union. " + $"Actual type {actualType.Name} is not possible for {unionType.Name}", path, fields.First()); } var subSelectionSet = SelectionSets.MergeSelectionSets(fields); var data = await SelectionSets.ExecuteSelectionSetAsync( executorContext, subSelectionSet, actualType, value, path).ConfigureAwait(false); return(data); }
public virtual async Task <object> CompleteValueAsync(IExecutorContext executorContext, ObjectType objectType, IField field, IType fieldType, GraphQLFieldSelection selection, List <GraphQLFieldSelection> fields, Dictionary <string, object> coercedVariableValues, NodePath path) { object completedValue = null; completedValue = await CompleteValueAsync( executorContext, objectType, field, fieldType, ActualType, selection, fields, Value, coercedVariableValues, path).ConfigureAwait(false); return(completedValue); }
public virtual ExecuteAction Execute(IExecutorContext context) { _currentIndex++; if (_currentIndex == _node.OperandCount) { Result[] results = new Result[_node.OperandCount]; for (int i = 0; i < _node.OperandCount; i++) { results[i] = _subVisitors[i].Result; } this.EndVisit(_node.Expression.Eval((Evaluator)context, results)); return(ExecuteAction.End); } if (_currentIndex > _node.OperandCount) { throw new InvalidOperationException(); } ExprNode subNode = (ExprNode)_node.Operands[_currentIndex]; _subVisitors[_currentIndex] = context.CreateExecutor(subNode); context.Push(_subVisitors[_currentIndex]); return(ExecuteAction.Continue); }
private async Task <object> CompleteNonNullValueAsync( IExecutorContext executorContext, ObjectType objectType, IField field, ObjectType actualType, GraphQLFieldSelection selection, IReadOnlyCollection <GraphQLFieldSelection> fields, object value, NodePath path, NonNull nonNull) { var innerType = nonNull.OfType; var completedResult = await CompleteValueAsync( executorContext, objectType, field, innerType, actualType, selection, fields, value, path).ConfigureAwait(false); if (completedResult == null) { throw new NullValueForNonNullException( objectType.Name, selection.Name.Value, path, selection); } return(completedResult); }
public async Task <IDictionary <string, object?> > ExecuteGroupedFieldSetAsync( IExecutorContext context, IReadOnlyDictionary <string, List <FieldSelection> > groupedFieldSet, ObjectDefinition objectDefinition, object?objectValue, NodePath path) { var tasks = new Dictionary <string, Task <object?> >(); foreach (var fieldGroup in groupedFieldSet) { var executionTask = FieldGroups.ExecuteFieldGroupAsync( context, objectDefinition, objectValue, //todo: following is dirty new KeyValuePair <string, IReadOnlyCollection <FieldSelection> >(fieldGroup.Key, fieldGroup.Value), path.Fork()); tasks.Add(fieldGroup.Key, executionTask); } await Task.WhenAll(tasks.Values).ConfigureAwait(false); return(tasks.ToDictionary(kv => kv.Key, kv => kv.Value.Result)); }
private async Task <object> CompleteNonNullValueAsync( IExecutorContext executorContext, ObjectType objectType, IField field, ObjectType actualType, GraphQLFieldSelection selection, List <GraphQLFieldSelection> fields, object value, Dictionary <string, object> coercedVariableValues, NodePath path, NonNull nonNull) { var innerType = nonNull.WrappedType; var completedResult = await CompleteValueAsync( executorContext, objectType, field, innerType, actualType, selection, fields, value, coercedVariableValues, path).ConfigureAwait(false); if (completedResult == null) { throw new NullValueForNonNullException( objectType.Name, selection.Name.Value, path, selection); } return(completedResult); }
public override async Task <IDictionary <string, object> > ExecuteGroupedFieldSetAsync( IExecutorContext context, Dictionary <string, List <GraphQLFieldSelection> > groupedFieldSet, ObjectType objectType, object objectValue, Dictionary <string, object> coercedVariableValues, NodePath path) { var data = new ConcurrentDictionary <string, object>(); var tasks = new ConcurrentBag <Task>(); foreach (var fieldGroup in groupedFieldSet) { var executionTask = Task.Run(async() => { var responseKey = fieldGroup.Key; var result = await ExecuteFieldGroupAsync( context, objectType, objectValue, coercedVariableValues, fieldGroup, path.Fork()).ConfigureAwait(false); data[responseKey] = result; }); tasks.Add(executionTask); } await Task.WhenAll(tasks).ConfigureAwait(false); return(data); }
public static object Handle( IExecutorContext context, ObjectType objectType, string fieldName, IType fieldType, GraphQLFieldSelection fieldSelection, object completedValue, Exception error, NodePath path) { if (!(error is QueryExecutionException)) { error = new QueryExecutionException( "", error, path, fieldSelection); } if (fieldType is NonNull) { throw error; } context.AddError(error); return(completedValue); }
public override ExecuteAction Execute(IExecutorContext context) { this.CurrentIndex++; if (this.CurrentIndex == 0) { this.SubVisitors[this.CurrentIndex] = context.CreateExecutor((ExprNode)this.Node.Operands[this.CurrentIndex]); context.Push(this.SubVisitors[this.CurrentIndex]); return ExecuteAction.Continue; } else if (this.CurrentIndex == 1) { Result result = this.SubVisitors[0].Result; int resultIndex = -1; if ((bool) ConvertHelper.ChangeType(result.Value, typeof(bool))) { resultIndex = 1; } else { resultIndex = 2; } this.SubVisitors[1] = context.CreateExecutor((ExprNode)this.Node.Operands[resultIndex]); context.Push(this.SubVisitors[1]); return ExecuteAction.Continue; } else { this.EndVisit(this.SubVisitors[1].Result); return ExecuteAction.End; } }
private static async Task <ExecutionResult> ExecuteSubscriptionEventAsync( IExecutorContext context, OperationDefinition subscription, IReadOnlyDictionary <string, object?> coercedVariableValues, object evnt, Func <Exception, ExecutionError> formatError) { var subscriptionType = context.Schema.Subscription; var selectionSet = subscription.SelectionSet; var path = new NodePath(); var data = await SelectionSets.ExecuteSelectionSetAsync( context, selectionSet, subscriptionType, evnt, path).ConfigureAwait(false); var result = new ExecutionResult { Errors = context.FieldErrors.Select(formatError).ToList(), Data = data?.ToDictionary(kv => kv.Key, kv => kv.Value) }; return(result); }
public async Task <IDictionary <string, object?> > ExecuteGroupedFieldSetAsync( IExecutorContext context, IReadOnlyDictionary <string, List <FieldSelection> > groupedFieldSet, ObjectDefinition objectDefinition, object?objectValue, NodePath path) { var responseMap = new Dictionary <string, object?>(); foreach (var fieldGroup in groupedFieldSet) { var responseKey = fieldGroup.Key; try { var result = await FieldGroups.ExecuteFieldGroupAsync( context, objectDefinition, objectValue, new KeyValuePair <string, IReadOnlyCollection <FieldSelection> >(fieldGroup.Key, fieldGroup.Value), path.Fork()).ConfigureAwait(false); responseMap[responseKey] = result; } catch (QueryExecutionException e) { responseMap[responseKey] = null; context.AddError(e); } } return(responseMap); }
public override ExecuteAction Execute(IExecutorContext context) { base.CurrentIndex++; if (base.CurrentIndex == 0) { base.SubVisitors[base.CurrentIndex] = context.CreateExecutor((ExprNode)base.Node.Operands[base.CurrentIndex]); context.Push(base.SubVisitors[base.CurrentIndex]); return(ExecuteAction.Continue); } if (base.CurrentIndex == 1) { Result result = base.SubVisitors[0].Result; int num = -1; if ((bool)result.Value) { num = 1; } else { num = 2; } base.SubVisitors[1] = context.CreateExecutor((ExprNode)base.Node.Operands[num]); context.Push(base.SubVisitors[1]); return(ExecuteAction.Continue); } base.EndVisit(base.SubVisitors[1].Result); return(ExecuteAction.End); }
public override ExecuteAction Execute(IExecutorContext context) { this.CurrentIndex++; if (this.CurrentIndex == 0) { this.SubVisitors[this.CurrentIndex] = context.CreateExecutor((ExprNode)this.Node.Operands[this.CurrentIndex]); context.Push(this.SubVisitors[this.CurrentIndex]); return(ExecuteAction.Continue); } else if (this.CurrentIndex == 1) { Result result = this.SubVisitors[0].Result; int resultIndex = -1; if ((bool)result.Value) { resultIndex = 1; } else { resultIndex = 2; } this.SubVisitors[1] = context.CreateExecutor((ExprNode)this.Node.Operands[resultIndex]); context.Push(this.SubVisitors[1]); return(ExecuteAction.Continue); } else { this.EndVisit(this.SubVisitors[1].Result); return(ExecuteAction.End); } }
private async Task <object> CompleteListValueAsync( IExecutorContext executorContext, ObjectType objectType, IField field, IType fieldType, ObjectType actualType, GraphQLFieldSelection selection, IReadOnlyCollection <GraphQLFieldSelection> fields, object value, NodePath path, List listType) { if (!(value is IEnumerable values)) { throw new CompleteValueException( $"Cannot complete value for list field '{selection.Name.Value}':'{fieldType}'. " + "Resolved value is not a collection", path, selection); } var innerType = listType.OfType; var result = new List <object>(); int i = 0; foreach (var resultItem in values) { var itemPath = path.Fork().Append(i++); try { var completedResultItem = await CompleteValueAsync( executorContext, objectType, field, innerType, actualType, selection, fields, resultItem, itemPath).ConfigureAwait(false); result.Add(completedResultItem); } catch (Exception e) { if (innerType is NonNull) { throw; } executorContext.AddError(e); result.Add(null); } } return(result); }
public override ExecuteAction Execute(IExecutorContext context) { if (this.CurrentIndex == 0) { Result result = this.SubVisitors[0].Result; if ((bool)result.Value) { this.EndVisit(new Result(true)); return ExecuteAction.End; } else { return base.Execute(context); } } return base.Execute(context); }
public override ExecuteAction Execute(IExecutorContext context) { if (base.CurrentIndex == 0) { if ((bool)base.SubVisitors[0].Result.Value) { base.EndVisit(new Result(true)); return(ExecuteAction.End); } return(base.Execute(context)); } return(base.Execute(context)); }
private static async Task <object> CompleteObjectValueAsync(IExecutorContext executorContext, List <GraphQLFieldSelection> fields, object value, Dictionary <string, object> coercedVariableValues, NodePath path, ObjectType fieldObjectType) { var subSelectionSet = SelectionSets.MergeSelectionSets(fields); var data = await SelectionSets.ExecuteSelectionSetAsync( executorContext, subSelectionSet, fieldObjectType, value, coercedVariableValues, path).ConfigureAwait(false); return(data); }
private static async Task <object> CompleteObjectValueAsync( IExecutorContext executorContext, IReadOnlyCollection <GraphQLFieldSelection> fields, object value, NodePath path, ObjectType fieldObjectType) { var subSelectionSet = SelectionSets.MergeSelectionSets(fields); var data = await SelectionSets.ExecuteSelectionSetAsync( executorContext, subSelectionSet, fieldObjectType, value, path).ConfigureAwait(false); return(data); }
protected async Task <object> ExecuteFieldGroupAsync( IExecutorContext context, ObjectType objectType, object objectValue, Dictionary <string, object> coercedVariableValues, KeyValuePair <string, List <GraphQLFieldSelection> > fieldGroup, NodePath path) { if (objectType == null) { throw new ArgumentNullException(nameof(objectType)); } var schema = context.Schema; var fields = fieldGroup.Value; var fieldName = fields.First().Name.Value; path.Append(fieldName); // __typename hack if (fieldName == "__typename") { return(objectType.Name); } var fieldType = schema .GetField(objectType.Name, fieldName)? .Type; if (fieldType == null) { throw new GraphQLError( $"Object '{objectType.Name}' does not have field '{fieldName}'"); } var responseValue = await ExecuteFieldAsync( context, objectType, objectValue, fields, fieldType, coercedVariableValues, path).ConfigureAwait(false); return(responseValue); }
public override ExecuteAction Execute(IExecutorContext context) { if (this.CurrentIndex == 0) { Result result = this.SubVisitors[0].Result; if (!(bool) ConvertHelper.ChangeType(result.Value, typeof(bool))) { this.EndVisit(new Result(false)); return ExecuteAction.End; } else { return base.Execute(context); } } return base.Execute(context); }
public override ExecuteAction Execute(IExecutorContext context) { if (this.CurrentIndex == 0) { Result result = this.SubVisitors[0].Result; if (!(bool)ConvertHelper.ChangeType(result.Value, typeof(bool))) { this.EndVisit(new Result(false)); return(ExecuteAction.End); } else { return(base.Execute(context)); } } return(base.Execute(context)); }
public override ExecuteAction Execute(IExecutorContext context) { if (this.CurrentIndex == 0) { Result result = this.SubVisitors[0].Result; if ((bool)result.Value) { this.EndVisit(new Result(true)); return(ExecuteAction.End); } else { return(base.Execute(context)); } } return(base.Execute(context)); }
public static async Task <object> ExecuteFieldGroupAsync( IExecutorContext context, ObjectType objectType, object objectValue, KeyValuePair <string, IReadOnlyCollection <GraphQLFieldSelection> > fieldGroup, NodePath path) { if (objectType == null) { throw new ArgumentNullException(nameof(objectType)); } var schema = context.Schema; var fields = fieldGroup.Value; var fieldName = fields.First().Name.Value; path.Append(fieldName); // __typename hack if (fieldName == "__typename") { return(objectType.Name); } var fieldType = schema .GetField(objectType.Name, fieldName)? .Type; if (fieldType == null) { throw new QueryExecutionException( $"Object '{objectType.Name}' does not have field '{fieldName}'", path); } var responseValue = await ExecuteFieldAsync( context, objectType, objectValue, fields, fieldType, path).ConfigureAwait(false); return(responseValue); }
public ResolverContext( ObjectType objectType, object objectValue, IField field, FieldSelection selection, IReadOnlyCollection <FieldSelection> fields, IReadOnlyDictionary <string, object?> arguments, NodePath path, IExecutorContext executionContext) { ObjectType = objectType ?? throw new ArgumentNullException(nameof(objectType)); ObjectValue = objectValue; Field = field ?? throw new ArgumentNullException(nameof(field)); Selection = selection ?? throw new ArgumentNullException(nameof(selection)); Fields = fields; Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); Path = path ?? throw new ArgumentNullException(nameof(path)); ExecutionContext = executionContext; }
public ResolverContext( ISchema schema, //todo: remove and get from execution ObjectType objectType, object objectValue, IField field, GraphQLFieldSelection selection, IReadOnlyDictionary <string, object> arguments, NodePath path, IExecutorContext executionContext) { Schema = schema ?? throw new ArgumentNullException(nameof(schema)); ObjectType = objectType ?? throw new ArgumentNullException(nameof(objectType)); ObjectValue = objectValue; Field = field ?? throw new ArgumentNullException(nameof(field)); Selection = selection ?? throw new ArgumentNullException(nameof(selection)); Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); Path = path ?? throw new ArgumentNullException(nameof(path)); ExecutionContext = executionContext; }
public static SubscriptionResult MapSourceToResponseEventAsync( IExecutorContext context, ISubscriberResult subscriberResult, OperationDefinition subscription, IReadOnlyDictionary <string, object?> coercedVariableValues, Func <Exception, ExecutionError> formatError, CancellationToken cancellationToken) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (subscriberResult == null) { throw new ArgumentNullException(nameof(subscriberResult)); } if (subscription == null) { throw new ArgumentNullException(nameof(subscription)); } if (coercedVariableValues == null) { throw new ArgumentNullException(nameof(coercedVariableValues)); } if (formatError == null) { throw new ArgumentNullException(nameof(formatError)); } var responseStream = Channel.CreateUnbounded <ExecutionResult>(); var reader = subscriberResult.Reader; // execute event var _ = reader.TransformAndWriteTo(responseStream, item => ExecuteSubscriptionEventAsync( context, subscription, coercedVariableValues, item, formatError)); return(new SubscriptionResult(responseStream)); }
public virtual ExecuteAction Execute(IExecutorContext context) { _currentIndex++; if (_currentIndex == _node.OperandCount) { Result[] results = new Result[_node.OperandCount]; for (int i = 0; i < _node.OperandCount; i++) results[i] = _subVisitors[i].Result; this.EndVisit(_node.Expression.Eval((Evaluator)context, results)); return ExecuteAction.End; } if (_currentIndex > _node.OperandCount) { throw new InvalidOperationException(); } ExprNode subNode = (ExprNode)_node.Operands[_currentIndex]; _subVisitors[_currentIndex] = context.CreateExecutor(subNode); context.Push(_subVisitors[_currentIndex]); return ExecuteAction.Continue; }
public Task <object> CompleteValueAsync(IExecutorContext executorContext, ObjectType objectType, IField field, IType fieldType, GraphQLFieldSelection selection, IReadOnlyCollection <GraphQLFieldSelection> fields, NodePath path) { var value = _data[selection.Name.Value]; var resolveResult = new ResolveResult(value); return(resolveResult.CompleteValueAsync( executorContext, objectType, field, fieldType, selection, fields, path)); }
public virtual async Task <object> CompleteValueAsync(IExecutorContext executorContext, ObjectType objectType, IField field, IType fieldType, GraphQLFieldSelection selection, IReadOnlyCollection <GraphQLFieldSelection> fields, NodePath path) { object completedValue = null; completedValue = await CompleteValueAsync( executorContext, objectType, field, fieldType, ActualType, selection, fields, Value, path).ConfigureAwait(false); return(completedValue); }
public static async Task <IDictionary <string, object> > ExecuteSelectionSetAsync( IExecutorContext executorContext, GraphQLSelectionSet selectionSet, ObjectType objectType, object objectValue, NodePath path) { var groupedFieldSet = CollectFields( executorContext.Schema, executorContext.Document, objectType, selectionSet, executorContext.CoercedVariableValues); var resultMap = await executorContext.Strategy.ExecuteGroupedFieldSetAsync( executorContext, groupedFieldSet, objectType, objectValue, path).ConfigureAwait(false); return(resultMap); }
public virtual ExecuteAction Execute(IExecutorContext context) { this._currentIndex++; if (this._currentIndex == this._node.OperandCount) { OPCTrendLib.Result[] argArray = new OPCTrendLib.Result[this._node.OperandCount]; for (int i = 0; i < this._node.OperandCount; i++) { argArray[i] = this._subVisitors[i].Result; } this.EndVisit(this._node.Expression.Eval((Evaluator)context, argArray)); return(ExecuteAction.End); } if (this._currentIndex > this._node.OperandCount) { throw new InvalidOperationException(); } ExprNode node = (ExprNode)this._node.Operands[this._currentIndex]; this._subVisitors[this._currentIndex] = context.CreateExecutor(node); context.Push(this._subVisitors[this._currentIndex]); return(ExecuteAction.Continue); }
public Task <object> CompleteValueAsync( IExecutorContext executorContext, ObjectType objectType, IField field, IType fieldType, GraphQLFieldSelection selection, List <GraphQLFieldSelection> fields, Dictionary <string, object> coercedVariableValues, NodePath path) { var value = _data[selection.Name.Value]; var resolveResult = new ResolveResult(value); return(resolveResult.CompleteValueAsync( executorContext, objectType, field, fieldType, selection, fields, coercedVariableValues, path)); }
public virtual void Initialize(IExecutorContext context, ExprNode node) { _node = node; Reset(context); }
public virtual void Reset(IExecutorContext context) { _subVisitors = new IExecutor[_node.OperandCount]; _currentIndex = -1; }
public override void Reset(IExecutorContext context) { base.Reset(context); }
public override ExecuteAction Execute(IExecutorContext context) { return base.Execute(context); }
public override ExecuteAction Execute(IExecutorContext context) { this.EndVisit(this.Node.Expression.Eval((Evaluator)context, null)); return ExecuteAction.End; }
public override void Reset(IExecutorContext context) { }