Exemplo n.º 1
0
        public void OnGraphInit(IObjectGraphType query, IObjectGraphType mutation)
        {
            var orderService = shopFactory.OrderService;
            //var orderResolver = new OrderResolver(orderService);
            var orderResolver = new FuncFieldResolver <IOrder>((ctx) => orderService.GetOrder(ctx.GetArgument <string>("id")));
            //var orderArticleResolver = new FuncFieldResolver<IEnumerable<IOrderArticle>>((ctx) => (ctx.Source as IOrder).Articles);

            var order        = shopFactory.CreateInstance <IOrder>();
            var orderArticle = shopFactory.CreateInstance <IOrderArticle>();

            GraphTypeTypeRegistry.Register(typeof(IOrderArticle), typeof(ReflectionObjectGraphType <IOrderArticle>));

            query.AddField(new FieldType()
            {
                Name = "orderarticle",
                //Resolver = orderResolver,
                Type         = orderArticle.GetType(),
                ResolvedType = new ReflectionObjectGraphType <IOrderArticle>()
            });

            query.AddField(new FieldType()
            {
                Name         = "order",
                Resolver     = orderResolver,
                Arguments    = TinyQuery.GetIdQuery(),
                Type         = order.GetType(),
                ResolvedType = new ReflectionObjectGraphType <IOrder>()
            });
        }
Exemplo n.º 2
0
        public FieldType AddQueryField <TSource, TReturn>(
            IObjectGraphType graph,
            string name,
            Func <ResolveEfFieldContext <TDbContext, TSource>, Task <IQueryable <TReturn> > > resolve,
            Type?itemGraphType = null,
            IEnumerable <QueryArgument>?arguments = null,
            string?description = null)
            where TReturn : class
        {
            Guard.AgainstNull(nameof(graph), graph);
            var field = BuildQueryField(itemGraphType, name, resolve, arguments, description);

            return(graph.AddField(field));
        }
Exemplo n.º 3
0
        public FieldType AddSingleField <TReturn>(
            IObjectGraphType graph,
            string name,
            Func <ResolveEfFieldContext <TDbContext, object>, IQueryable <TReturn> > resolve,
            Func <ResolveEfFieldContext <TDbContext, object>, TReturn, Task>?mutate = null,
            Type?graphType = null,
            IEnumerable <QueryArgument>?arguments = null,
            bool nullable      = false,
            string?description = null)
            where TReturn : class
        {
            var field = BuildSingleField(name, resolve, mutate, arguments, graphType, nullable, description);

            return(graph.AddField(field));
        }
        public static void Field(
            this IObjectGraphType obj,
            string name,
            IGraphType type,
            string description       = null,
            QueryArguments arguments = null,
            Func <ResolveFieldContext, object> resolve = null)
        {
            var field = new FieldType();

            field.Name         = name;
            field.Description  = description;
            field.Arguments    = arguments;
            field.ResolvedType = type;
            field.Resolver     = resolve != null ? new FuncFieldResolver <object>(resolve) : null;
            obj.AddField(field);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a field with the specified properties to a specified output graph type.
        /// </summary>
        /// <param name="obj">The graph type to add a field to.</param>
        /// <param name="name">The name of the field.</param>
        /// <param name="type">The graph type of this field.</param>
        /// <param name="description">The description of the field.</param>
        /// <param name="arguments">A list of arguments for the field.</param>
        /// <param name="resolve">A field resolver delegate. If not specified, <see cref="NameFieldResolver"/> will be used.</param>
        public static void Field( //TODO: v5 - change void to T where T : IObjectGraphType
            this IObjectGraphType obj,
            string name,
            IGraphType type,
            string description       = null,
            QueryArguments arguments = null,
            Func <IResolveFieldContext, object> resolve = null)
        {
            var field = new FieldType
            {
                Name         = name,
                Description  = description,
                Arguments    = arguments,
                ResolvedType = type,
                Resolver     = resolve != null ? new FuncFieldResolver <object>(resolve) : null
            };

            obj.AddField(field);
        }
        public void AddQueryConnectionField <TSource, TReturn>(
            IObjectGraphType graph,
            string name,
            Func <ResolveEfFieldContext <TDbContext, TSource>, IQueryable <TReturn> > resolve,
            Type?itemGraphType = null,
            IEnumerable <QueryArgument>?arguments = null,
            int pageSize       = 10,
            string?description = null)
            where TReturn : class
        {
            Guard.AgainstNull(nameof(graph), graph);
            Guard.AgainstNull(nameof(resolve), resolve);

            var connection = BuildQueryConnectionField(name, resolve, pageSize, itemGraphType, description);

            var field = graph.AddField(connection.FieldType);

            field.AddWhereArgument(arguments);
        }
        public static void FieldAsync(
            this IObjectGraphType obj,
            string name,
            IGraphType type,
            string description       = null,
            QueryArguments arguments = null,
            Func <IResolveFieldContext, Task <object> > resolve = null)
        {
            var field = new FieldType
            {
                Name         = name,
                Description  = description,
                Arguments    = arguments,
                ResolvedType = type,
                Resolver     = resolve != null ? new AsyncFieldResolver <object>(resolve) : null
            };

            obj.AddField(field);
        }
Exemplo n.º 8
0
 public static FieldType FieldAsync <TGraphType, TSourceType>(
     this IObjectGraphType obj,
     string name,
     string description       = null,
     QueryArguments arguments = null,
     Func <ResolveFieldContext <TSourceType>, Task <object> > resolve = null,
     string deprecationReason = null)
     where TGraphType : IGraphType
 {
     return(obj.AddField(new FieldType
     {
         Name = name,
         Description = description,
         DeprecationReason = deprecationReason,
         Type = typeof(TGraphType),
         Arguments = arguments,
         Resolver = resolve != null
             ? new AsyncFieldResolver <TSourceType, object>(resolve)
             : null,
     }));
 }