Пример #1
0
        // Transform  (db, args, mut) => db.Entities.First(args)  into  args => db => db.Entities.First(args)
        private static GraphQLFieldBuilder <TContext, TEntity> AddMutation <TContext, TArgs, TEntity, TMutReturn>(this GraphQLSchema <TContext> context, string name, Expression <Func <TContext, TArgs, TMutReturn, TEntity> > queryableGetter, Func <TContext, TArgs, TMutReturn> mutation)
        {
            var innerLambda = Expression.Lambda <Func <TContext, TEntity> >(queryableGetter.Body, queryableGetter.Parameters[0]);
            var info        = GetQueryInfo(innerLambda);

            if (info.ResolutionType != ResolutionType.Unmodified)
            {
                return(context.AddMutationInternal(name, GetFinalMutationFunc <TContext, TArgs, TMutReturn, IEnumerable <TEntity> >(info.BaseQuery, queryableGetter.Parameters[1], queryableGetter.Parameters[2]), info.ResolutionType, mutation));
            }
            return(context.AddUnmodifiedMutationInternal(name, GetFinalMutationFunc <TContext, TArgs, TMutReturn, TEntity>(info.OriginalQuery, queryableGetter.Parameters[1], queryableGetter.Parameters[2]), mutation));
        }
Пример #2
0
        // Transform  (db, args, mut) => db.Entities.Where(args)  into  args => db => db.Entities.Where(args)
        private static GraphQLFieldBuilder <TContext, TEntity> AddListMutation <TContext, TArgs, TEntity, TMutReturn>(this GraphQLSchema <TContext> context, string name, Expression <Func <TContext, TArgs, TMutReturn, IEnumerable <TEntity> > > queryableGetter, Func <TContext, TArgs, TMutReturn> mutation)
        {
            var innerLambda = Expression.Lambda <Func <TContext, IEnumerable <TEntity> > >(queryableGetter.Body, queryableGetter.Parameters[0]);

            return(context.AddMutationInternal(name, GetFinalMutationFunc <TContext, TArgs, TMutReturn, IEnumerable <TEntity> >(innerLambda, queryableGetter.Parameters[1], queryableGetter.Parameters[2]), ResolutionType.ToList, mutation));
        }