Example #1
0
        /// This is our top level node.
        /// {
        ///   entityQuery { fields [, field] },
        ///   entityQuery { fields [, field] },
        ///   ...
        /// }
        public override IGraphQLNode VisitDataQuery(EntityGraphQLParser.DataQueryContext context)
        {
            var root          = new GraphQLNode("root", null, null, null, null);
            var operationName = GetOperationName(context.operationName());

            // Just visit each child node. All top level will be entityQueries
            foreach (var c in context.gqlBody().children)
            {
                var n = Visit(c);
                if (n != null)
                {
                    root.Fields.Add(n);
                }
            }
            return(root);
        }
        /// <summary>
        /// This is one of our top level node.
        /// query MyQuery {
        ///   entityQuery { fields [, field] },
        ///   entityQuery { fields [, field] },
        ///   ...
        /// }
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override IGraphQLBaseNode VisitDataQuery(EntityGraphQLParser.DataQueryContext context)
        {
            var operation = GetOperation(context.operationName());

            foreach (var item in operation.Arguments.Where(a => a.DefaultValue != null))
            {
                variables[item.ArgName] = Expression.Lambda(item.DefaultValue.Expression).Compile().DynamicInvoke();
            }
            var query = new GraphQLNode(schemaProvider, fragments, operation.Name, null, null, null, null, null);

            // Just visit each child node. All top level will be entityQueries
            foreach (var c in context.gqlBody().children)
            {
                var n = Visit(c);
                if (n != null)
                {
                    query.AddField((IGraphQLNode)n);
                }
            }
            rootQueries.Add(query);
            return(query);
        }