Esempio n. 1
0
        private static Builders.FieldBuilder <IDictionary <string, object>, TReturn> EfFieldFromContext <TDbContext, TSource, TReturn>(this IEfGraph <TDbContext, TSource> graph, string name, Func <ResolveEfFieldContext <TDbContext, TSource>, LambdaExpression> expression, bool nullable = false, Type graphType = null) where TDbContext : DbContext where TSource : class
        {
            //obtain the type
            try
            {
                if (graphType == null)
                {
                    graphType = typeof(TReturn).GetGraphTypeFromType(nullable);
                }
            }
            catch (ArgumentOutOfRangeException exp)
            {
                throw new ArgumentException(
                          $"The GraphQL type for Field: '{name}' on parent type: '{graph.Name ?? graph.GetType().Name}' could not be derived implicitly. \n",
                          exp
                          );
            }

            var builder = FieldBuilder.Create <IDictionary <string, object>, TReturn>(graphType)
                          .Name(name)
                          .Resolve(EfGraphResolver)
                          //.Description(expression.DescriptionOf())
                          //.DeprecationReason(expression.DeprecationReasonOf())
                          //.DefaultValue(expression.DefaultValueOf())
            ;

            builder.FieldType.SetExpressionMetadata <TDbContext, TSource>(expression);
            graph.AddField(builder.FieldType);
            return(builder);
        }
Esempio n. 2
0
 public static Builders.FieldBuilder <IDictionary <string, object>, TReturn> EfFieldFromContext <TDbContext, TSource, TReturn>(this IEfGraph <TDbContext, TSource> graph, string name, Func <ResolveEfFieldContext <TDbContext, TSource>, Expression <Func <TDbContext, TSource, TReturn> > > resolveExpression, bool nullable = false, Type graphType = null) where TDbContext : DbContext where TSource : class
 {
     return(EfFieldFromContext <TDbContext, TSource, TReturn>(graph, name, context => (LambdaExpression)resolveExpression(context), nullable, graphType));
 }
Esempio n. 3
0
 public static Builders.FieldBuilder <IDictionary <string, object>, TProperty> EfField <TDbContext, TSource, TProperty>(this IEfGraph <TDbContext, TSource> graph, string name, Expression <Func <TSource, TProperty> > expression, bool nullable = false, Type graphType = null) where TDbContext : DbContext where TSource : class
 {
     return(EfFieldFromContext <TDbContext, TSource, TProperty>(graph, name, context => (LambdaExpression)expression, nullable, graphType));
 }
Esempio n. 4
0
        public static Builders.FieldBuilder <IDictionary <string, object>, IEnumerable <TProperty> > EfQueryField <TDbContext, TSource, TProperty>(this IEfGraph <TDbContext, TSource> graph, string name, Expression <Func <TDbContext, TSource, IEnumerable <TProperty> > > expression, Type graphType = null, IEnumerable <QueryArgument> arguments = null) where TDbContext : DbContext where TSource : class
        {
            var builder = EfField(graph, name, expression, false, graphType);

            builder.FieldType.SetEFQueryMetadata(true);
            builder.FieldType.AddWhereArgument(arguments);
            return(builder);
        }
Esempio n. 5
0
        public static Builders.FieldBuilder <IDictionary <string, object>, TProperty> EfNavigationField <TDbContext, TSource, TProperty>(this IEfGraph <TDbContext, TSource> graph, string name, Expression <Func <TSource, TProperty> > expression, bool nullable = false, Type graphType = null) where TDbContext : DbContext where TSource : class
        {
            var builder = EfField(graph, name, expression, nullable, graphType);

            builder.FieldType.SetEFGraphMetadata(true);
            return(builder);
        }
Esempio n. 6
0
        public static Builders.FieldBuilder <IDictionary <string, object>, TProperty> EfField <TDbContext, TSource, TProperty>(this IEfGraph <TDbContext, TSource> graph, Expression <Func <TSource, TProperty> > expression, bool nullable = false, Type graphType = null) where TDbContext : DbContext where TSource : class
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }
            //obtain the name
            string name;

            try
            {
                name = expression.NameOf();
            }
            catch
            {
                throw new ArgumentException(
                          $"Cannot infer a Field name from the expression: '{expression.Body.ToString()}' " +
                          $"on parent GraphQL type: '{graph.Name ?? graph.GetType().Name}'.");
            }

            return(EfField(graph, name, expression, nullable, graphType));
        }