public MountainSchema(IDependencyResolver resolver) : base(resolver)
        {
            Query        = resolver.Resolve <MountainQuery>();
            Mutation     = resolver.Resolve <MountainMutation>();
            Subscription = resolver.Resolve <MountainSubscription>();

            RegisterDirective(new LowercaseDirective());
            RegisterDirective(new OrderbyDirective());

            var builder = new FieldMiddlewareBuilder();

            builder.Use <LowercaseFieldsMiddleware>();
            builder.ApplyTo(this);

            builder.Use(next =>
            {
                return(context =>
                {
                    return next(context).ContinueWith(x =>
                    {
                        var c = context;
                        var result = x.Result;

                        result = OrderbyQuery.OrderIfNecessary(context, result);

                        return result;
                    });
                });
            });
            builder.ApplyTo(this);

            //builder.Use<CustomGraphQlExecutor<MountainSchema>>();
            //builder.ApplyTo(this);
        }
Exemplo n.º 2
0
 private void InitializeQueryVariables()
 {
     _TopQuery     = new TopQuery(MaxAzureTableResult);
     _SkipQuery    = new SkipQuery();
     _OrderbyQuery = new OrderbyQuery();
     _FilterQuery  = new FilterQuery();
     _Pagination   = new Pagination();
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获得初步比较粗的字段语句
        /// </summary>
        private void GetOrderbyColumnSql(string orderBy)
        {
            if (string.IsNullOrWhiteSpace(orderBy))
            {
                return;
            }
            var allPoint = GetAllMatchPoint(orderBy, "^,");

            if (allPoint.Count > 0)
            {
                for (int i = 0; i < allPoint.Count; i++)
                {
                    if (i == 0)
                    {
                        var first = orderBy.Substring(0, allPoint[i].Point);
                        if (string.IsNullOrWhiteSpace(first))
                        {
                            continue;
                        }
                        //移除SELECT相关数据
                        var findSelect = GetAllMatchPoint(first, "^ORDER\\s+BY\\s*").First();
                        var startPoint = findSelect.Point + findSelect.ActualContent.Length;
                        first = orderBy.Substring(startPoint, first.Length - startPoint);
                        OrderbyQuery.Add(first);
                    }

                    if (i > 0 && i < allPoint.Count)
                    {
                        var newStartPoint = allPoint[i - 1].Point + allPoint[i - 1].ActualContent.Length;
                        SelectQuery.Add(orderBy.Substring(newStartPoint, allPoint[i].Point - newStartPoint));
                    }
                    if (i == allPoint.Count - 1)
                    {
                        var newStartPoint = allPoint[i].Point + allPoint[i].ActualContent.Length;
                        SelectQuery.Add(orderBy.Substring(newStartPoint, orderBy.Length - newStartPoint));
                    }
                }
            }
            else //仅仅一个select
            {
                var findSelect = GetAllMatchPoint(orderBy, "^ORDER\\s+BY\\s*").First();
                var startPoint = findSelect.Point + findSelect.ActualContent.Length;
                var first      = orderBy.Substring(startPoint, orderBy.Length - startPoint);
                OrderbyQuery.Add(first);
            }
        }