Esempio n. 1
0
        internal Field(string name, LambdaExpression resolve, string description, string returnSchemaType = null, Type returnClrType = null)
        {
            Name                = name;
            Description         = description;
            ReturnTypeClrSingle = returnSchemaType;
            ReturnTypeClr       = returnClrType;

            if (resolve != null)
            {
                Resolve       = resolve.Body;
                FieldParam    = resolve.Parameters.First();
                ReturnTypeClr = Resolve.Type;

                if (resolve.Body.NodeType == ExpressionType.MemberAccess)
                {
                    ReturnTypeNotNullable     = GraphQLNotNullAttribute.IsMemberMarkedNotNull(((MemberExpression)resolve.Body).Member);
                    ReturnElementTypeNullable = GraphQLElementTypeNullable.IsMemberElementMarkedNullable(((MemberExpression)resolve.Body).Member);
                }
                if (ReturnTypeClrSingle == null)
                {
                    if (resolve.Body.Type.IsEnumerableOrArray())
                    {
                        if (!resolve.Body.Type.IsArray && !resolve.Body.Type.GetGenericArguments().Any())
                        {
                            throw new ArgumentException($"We think {resolve.Body.Type} is IEnumerable<> or an array but didn't find it's enumerable type");
                        }
                        ReturnTypeClrSingle = resolve.Body.Type.GetEnumerableOrArrayType().Name;
                    }
                    else
                    {
                        ReturnTypeClrSingle = resolve.Body.Type.Name;
                    }
                }
            }
        }
Esempio n. 2
0
        internal Field(string name, LambdaExpression resolve, string description, string returnSchemaType, Type returnClrType, RequiredClaims authorizeClaims)
        {
            Name             = name;
            Description      = description;
            returnTypeSingle = returnSchemaType;
            ReturnTypeClr    = returnClrType;
            AuthorizeClaims  = authorizeClaims;

            if (resolve != null)
            {
                if (resolve.Body.NodeType == ExpressionType.Call && ((MethodCallExpression)resolve.Body).Method.DeclaringType == typeof(ArgumentHelper) && ((MethodCallExpression)resolve.Body).Method.Name == "WithService")
                {
                    // they are wanting services injected
                    var call             = (MethodCallExpression)resolve.Body;
                    var lambdaExpression = (LambdaExpression)((UnaryExpression)call.Arguments.First()).Operand;
                    Resolve  = lambdaExpression.Body;
                    Services = lambdaExpression.Parameters.Select(p => p.Type).ToList();
                }
                else
                {
                    Resolve = resolve.Body;
                }
                FieldParam    = resolve.Parameters.First();
                ReturnTypeClr = Resolve.Type;

                if (resolve.Body.NodeType == ExpressionType.MemberAccess)
                {
                    ReturnTypeNotNullable     = GraphQLNotNullAttribute.IsMemberMarkedNotNull(((MemberExpression)resolve.Body).Member);
                    ReturnElementTypeNullable = GraphQLElementTypeNullable.IsMemberElementMarkedNullable(((MemberExpression)resolve.Body).Member);
                }
            }
        }
Esempio n. 3
0
        internal Field(string name, LambdaExpression resolve, string description, string returnSchemaType, Type returnClrType, RequiredClaims authorizeClaims)
        {
            Name             = name;
            Description      = description;
            returnTypeSingle = returnSchemaType;
            ReturnTypeClr    = returnClrType;
            AuthorizeClaims  = authorizeClaims;

            if (resolve != null)
            {
                Resolve       = resolve.Body;
                FieldParam    = resolve.Parameters.First();
                ReturnTypeClr = Resolve.Type;

                if (resolve.Body.NodeType == ExpressionType.MemberAccess)
                {
                    ReturnTypeNotNullable     = GraphQLNotNullAttribute.IsMemberMarkedNotNull(((MemberExpression)resolve.Body).Member);
                    ReturnElementTypeNullable = GraphQLElementTypeNullable.IsMemberElementMarkedNullable(((MemberExpression)resolve.Body).Member);
                }
            }
        }