Example #1
0
        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);
        }
Example #2
0
    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);
    }
Example #3
0
    public static async Task <ExecutionResult> ExecuteMutationAsync(
        QueryContext context)
    {
        var(schema, _, operation, initialValue, coercedVariableValues) = context;
        var executionContext = context.BuildExecutorContext(new SerialExecutionStrategy());
        var path             = new NodePath();

        var mutationType = schema.Mutation;

        if (mutationType == null)
        {
            throw new QueryExecutionException(
                      "Schema does not support mutations. Mutation type is null.",
                      path);
        }

        var selectionSet = operation.SelectionSet;
        var data         = await SelectionSets.ExecuteSelectionSetAsync(
            executionContext,
            selectionSet,
            mutationType,
            initialValue,
            path).ConfigureAwait(false);


        return(new ExecutionResult
        {
            Errors = executionContext
                     .FieldErrors
                     .Select(context.FormatError).ToList(),
            Data = data?.ToDictionary(kv => kv.Key, kv => kv.Value)
        });
    }
Example #4
0
        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);
        }
Example #5
0
        void assignToSelection()
        {
            SelectionSetVM newSet = new SelectionSetVM(_selectedMaterialIndex);

            foreach (var filter in Filters)
            {
                foreach (var item in filter.FilterItems)
                {
                    if (item.IsSelected)
                    {
                        newSet.SelectedFilterValues.Add(new FilterSelection(filter.Name, item.Name));
                    }
                }
            }
            foreach (var elem in Elements)
            {
                if (elem.Include)
                {
                    newSet.ElementsIdsToInclude.Add(elem.UniqueID);
                }
                if (elem.Exclude)
                {
                    newSet.ElementsIdsToExclude.Add(elem.UniqueID);
                }
            }
            SelectionSets.Add(newSet);
            processSelectionSet(newSet);
            UpdateAll();
        }
Example #6
0
        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);
        }
        public GenSelectionSet CreateSelectionSet(IGraphType graphType, INode node)
        {
            if (graphType == null)
            {
                return(null);
            }
            var selectionSet = new GenSelectionSet {
                Namespace = this, Name = graphType.Name, GraphType = graphType, Node = node
            };

            if (!selectionSet.MapsToBuildInType)
            {
                SelectionSets.Add(selectionSet);
            }
            return(selectionSet);
        }
Example #8
0
        /// <summary>
        ///     For each subscription operation definition subscription in the document
        ///     Let subscriptionType be the root Subscription type in schema.
        ///     Let selectionSet be the top level selection set on subscription.
        ///     Let variableValues be the empty set.
        ///     Let groupedFieldSet be the result of CollectFields(subscriptionType, selectionSet, variableValues).
        ///     groupedFieldSet must have exactly one entry.
        /// </summary>
        public static CombineRule R5231SingleRootField()
        {
            return((context, rule) =>
            {
                rule.EnterDocument += document =>
                {
                    var subscriptions = document.Definitions
                                        .OfType <GraphQLOperationDefinition>()
                                        .Where(op => op.Operation == OperationType.Subscription)
                                        .ToList();

                    if (!subscriptions.Any())
                    {
                        return;
                    }

                    var schema = context.Schema;
                    //todo(pekka): should this report error?
                    if (schema.Subscription == null)
                    {
                        return;
                    }

                    var subscriptionType = schema.Subscription;
                    foreach (var subscription in subscriptions)
                    {
                        var selectionSet = subscription.SelectionSet;
                        var variableValues = new Dictionary <string, object>();

                        var groupedFieldSet = SelectionSets.CollectFields(
                            schema,
                            context.Document,
                            subscriptionType,
                            selectionSet,
                            variableValues);

                        if (groupedFieldSet.Count != 1)
                        {
                            context.Error(
                                ValidationErrorCodes.R5231SingleRootField,
                                "Subscription operations must have exactly one root field.",
                                subscription);
                        }
                    }
                };
            });
        }
Example #9
0
        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);
        }
Example #10
0
        void deleteSelected()
        {
            var itemsToRemove = SelectionSets.Where(a => a.IsSelected).ToList();

            foreach (var item in itemsToRemove)
            {
                SelectionSets.Remove(item);
            }
            foreach (var elem in Elements)
            {
                elem.Material = Materials[0].GWPMaterial;
            }
            foreach (var set in SelectionSets)
            {
                processSelectionSet(set);
            }
        }
Example #11
0
    public static async Task <ExecutionResult> ExecuteQueryAsync(
        QueryContext context)
    {
        var(schema, _, operation, initialValue, coercedVariableValues) = context;
        var queryType = schema.Query;
        var path      = new NodePath();

        if (queryType == null)
        {
            throw new QueryExecutionException(
                      "Schema does not support queries. Query type is null.",
                      path);
        }

        var selectionSet     = operation.SelectionSet;
        var executionContext = context.BuildExecutorContext(new ParallelExecutionStrategy());

        IDictionary <string, object?>?data;

        try
        {
            data = await SelectionSets.ExecuteSelectionSetAsync(
                executionContext,
                selectionSet,
                queryType,
                initialValue,
                path).ConfigureAwait(false);
        }
        catch (QueryExecutionException e)
        {
            executionContext.AddError(e);
            data = null;
        }

        return(new ExecutionResult
        {
            Errors = executionContext
                     .FieldErrors
                     .Select(context.FormatError)
                     .ToList(),
            Data = data?.ToDictionary(kv => kv.Key, kv => kv.Value)
        });
    }
Example #12
0
    public static async Task <ISubscriberResult> CreateSourceEventStreamAsync(
        IExecutorContext context,
        OperationDefinition subscription,
        IReadOnlyDictionary <string, object?> coercedVariableValues,
        object initialValue,
        CancellationToken cancellationToken)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }
        if (subscription == null)
        {
            throw new ArgumentNullException(nameof(subscription));
        }
        if (coercedVariableValues == null)
        {
            throw new ArgumentNullException(nameof(coercedVariableValues));
        }

        cancellationToken.ThrowIfCancellationRequested();

        var schema           = context.Schema;
        var subscriptionType = schema.Subscription;
        var groupedFieldSet  = SelectionSets.CollectFields(
            context.Schema,
            context.Document,
            subscriptionType,
            subscription.SelectionSet,
            coercedVariableValues
            );

        var fields         = groupedFieldSet.Values.First();
        var fieldName      = fields.First().Name;
        var fieldSelection = fields.First();

        var coercedArgumentValues = ArgumentCoercion.CoerceArgumentValues(
            schema,
            subscriptionType,
            fieldSelection,
            coercedVariableValues);

        var field          = schema.GetField(subscriptionType.Name, fieldName);
        var path           = new NodePath();
        var resolveContext = new ResolverContext(
            subscriptionType,
            initialValue,
            field,
            fieldSelection,
            fields,
            coercedArgumentValues,
            path,
            context);

        var subscriber = schema.GetSubscriber(subscriptionType.Name, fieldName);

        if (subscriber == null)
        {
            throw new QueryExecutionException(
                      $"Could not subscribe. Field '{subscriptionType}:{fieldName}' does not have subscriber",
                      path);
        }

        var subscribeResult = await subscriber(resolveContext, cancellationToken)
                              .ConfigureAwait(false);

        return(subscribeResult);
    }
 public GenSelectionSet FindSelectionSet(string name) => SelectionSets.Find(t => t.Name == name);