private static EventDescription CreateEvent(
            IResolverContext executionContext)
        {
            IReadOnlyList <IFieldSelection> selections =
                executionContext.CollectFields(
                    executionContext.RootType,
                    executionContext.Operation.SelectionSet);

            if (selections.Count == 1)
            {
                IFieldSelection          selection = selections[0];
                var                      arguments = new List <ArgumentNode>();
                IVariableValueCollection variables = executionContext.Variables;

                foreach (ArgumentNode argument in selection.Selection.Arguments)
                {
                    if (argument.Value is VariableNode v)
                    {
                        IValueNode value = variables.GetVariable <IValueNode>(v.Name.Value);
                        arguments.Add(argument.WithValue(value));
                    }
                    else
                    {
                        arguments.Add(argument);
                    }
                }

                return(new EventDescription(selection.Field.Name, arguments));
            }
            else
            {
                throw new QueryException(CoreResources.Subscriptions_SingleRootField);
            }
        }
Exemple #2
0
        public async Task <ArticleDto> GetArticleAsync(
            IResolverContext ctx,
            int dbId)
        {
            var articleType = ctx.Schema.Types.Single(t => t.Name.Value == "Article");
            var fields      = ctx.CollectFields(articleType as ObjectType);

            return(await Task.FromResult(new ArticleDto(dbId, fields)));
        }
        private static void CollectSelections(
            IResolverContext context,
            IFieldSelection selection,
            ICollection <IFieldSelection> collected)
        {
            if (selection.Field.Type.IsLeafType())
            {
                collected.Add(selection);
            }

            if (selection.Field.Type.NamedType() is ObjectType objectType)
            {
                foreach (IFieldSelection child in context.CollectFields(
                             objectType, selection.Selection.SelectionSet))
                {
                    CollectSelections(context, child, collected);
                }
            }
        }