internal static IInterpetedImplementation Implementation(InterpetedMemberDefinition parameterDefinition, InterpetedMemberDefinition contextDefinition, IInterpetedOperation[] body, InterpetedContext context, IInterpetedScopeTemplate scope, IMethodType implementationType) => Root(new Func <IRunTimeAnyRoot, RunTimeAnyRootEntry>[] { InterpetedImplementationIntention(parameterDefinition, contextDefinition, body, context, scope, implementationType) }).Has <IInterpetedImplementation>();
internal static IInterpetedMethod <TIn, TOut> InternalMethod <TIn, TOut>(InterpetedMemberDefinition <TIn> parameterDefinition, IInterpetedOperation <IInterpetedAnyType>[] body, InterpetedContext context, IInterpetedScopeTemplate scope, IMethodType methodType) where TIn : IInterpetedAnyType where TOut : IInterpetedAnyType => Root(new Func <IRunTimeAnyRoot, RunTimeAnyRootEntry>[] { InterpetedMethodIntention <TIn, TOut>(parameterDefinition, body, context, scope, methodType) }).Has <IInterpetedMethod <TIn, TOut> >();
public ExpressionResult ParseGqlarg(IMethodType fieldArgumentContext, EntityGraphQLParser.GqlargContext context) { ExpressionResult gqlVarValue = null; if (context.gqlVar() != null) { string varKey = context.gqlVar().GetText().TrimStart('$'); object value = variables.GetValueFor(varKey); gqlVarValue = (ExpressionResult)Expression.Constant(value); } else { // this is an expression gqlVarValue = constantVisitor.Visit(context.gqlvalue); } string argName = context.gqlfield.GetText(); if (fieldArgumentContext != null && fieldArgumentContext.HasArgumentByName(argName)) { var argType = fieldArgumentContext.GetArgumentType(argName); if (gqlVarValue != null && gqlVarValue.Type == typeof(string) && gqlVarValue.NodeType == ExpressionType.Constant) { string strValue = (string)((ConstantExpression)gqlVarValue).Value; if ( (argType.Type == typeof(Guid) || argType.Type == typeof(Guid?) || argType.Type == typeof(RequiredField <Guid>) || argType.Type == typeof(RequiredField <Guid?>)) && ConstantVisitor.GuidRegex.IsMatch(strValue)) { return((ExpressionResult)Expression.Constant(Guid.Parse(strValue))); } if (argType.Type.IsConstructedGenericType && argType.Type.GetGenericTypeDefinition() == typeof(EntityQueryType <>)) { string query = strValue; if (query.StartsWith("\"")) { query = query.Substring(1, context.gqlvalue.GetText().Length - 2); } return(BuildEntityQueryExpression(fieldArgumentContext, fieldArgumentContext.Name, argName, query)); } var argumentNonNullType = argType.Type.IsNullableType() ? Nullable.GetUnderlyingType(argType.Type) : argType.Type; if (argumentNonNullType.GetTypeInfo().IsEnum) { var enumName = strValue; var valueIndex = Enum.GetNames(argumentNonNullType).ToList().FindIndex(n => n == enumName); if (valueIndex == -1) { throw new EntityGraphQLCompilerException($"Value {enumName} is not valid for argument {context.gqlfield.GetText()}"); } var enumValue = Enum.GetValues(argumentNonNullType).GetValue(valueIndex); return((ExpressionResult)Expression.Constant(enumValue)); } } } return(gqlVarValue); }
internal static Func <IRunTimeAnyRoot, RunTimeAnyRootEntry> InterpetedMethodIntention( InterpetedMemberDefinition parameterDefinition, IInterpetedOperation[] body, InterpetedContext context, IInterpetedScopeTemplate scope, IMethodType methodType) => root => { var item = new InterpetedMethod(parameterDefinition, body, context, scope, methodType, root); return(new RunTimeAnyRootEntry(item, methodType)); };
private static object GetGqlArgs(IMethodType field, ISchemaProvider schema, IReadOnlyDictionary <Type, string> combinedMapping, string noArgs = "") { if (field.Arguments == null || !field.Arguments.Any()) { return(noArgs); } var all = field.Arguments.Select(f => ToCamelCaseStartsLower(f.Key) + ": " + ClrToGqlType(f.Value.TypeNotNullable, false, f.Value.Type, schema, combinedMapping)); return($"({string.Join(", ", all)})"); }
public void Init( InterpetedMemberDefinition parameterDefinition, IInterpetedOperation[] methodBody, IInterpetedScopeTemplate scope, IMethodType methodType) { ParameterDefinition = parameterDefinition ?? throw new ArgumentNullException(nameof(parameterDefinition)); Body = methodBody ?? throw new ArgumentNullException(nameof(methodBody)); Scope = scope ?? throw new ArgumentNullException(nameof(scope)); MethodType = methodType ?? throw new ArgumentNullException(nameof(methodType)); }
internal static Func <IRunTimeAnyRoot, RunTimeAnyRootEntry> InterpetedMethodIntention <TIn, TOut>( InterpetedMemberDefinition <TIn> parameterDefinition, IInterpetedOperation <IInterpetedAnyType>[] body, InterpetedContext context, IInterpetedScopeTemplate scope, IMethodType methodType) where TIn : IInterpetedAnyType where TOut : IInterpetedAnyType => root => { var item = new InterpetedMethod <TIn, TOut>(parameterDefinition, body, context, scope, methodType, root); return(new RunTimeAnyRootEntry(item, methodType)); };
public InterpetedMethod( InterpetedMemberDefinition parameterDefinition, IInterpetedOperation[] body, InterpetedContext context, IInterpetedScopeTemplate scope, IMethodType methodType, IRunTimeAnyRoot root) : base(root) { ParameterDefinition = parameterDefinition ?? throw new System.ArgumentNullException(nameof(parameterDefinition)); Body = body ?? throw new System.ArgumentNullException(nameof(body)); Context = context ?? throw new System.ArgumentNullException(nameof(context)); Scope = scope ?? throw new System.ArgumentNullException(nameof(scope)); MethodType = methodType ?? throw new ArgumentNullException(nameof(methodType)); }
public InterpetedImplementation( InterpetedMemberDefinition parameterDefinition, InterpetedMemberDefinition contextDefinition, IInterpetedOperation[] body, InterpetedContext context, IInterpetedScopeTemplate scope, IMethodType implementationType, IRunTimeAnyRoot root) : base(root) { ParameterDefinition = parameterDefinition ?? throw new ArgumentNullException(nameof(parameterDefinition)); this.contextDefinition = contextDefinition ?? throw new ArgumentNullException(nameof(contextDefinition)); Body = body ?? throw new ArgumentNullException(nameof(body)); InterpetedContext = context ?? throw new ArgumentNullException(nameof(context)); Scope = scope ?? throw new ArgumentNullException(nameof(scope)); ImplementationType = implementationType ?? throw new ArgumentNullException(nameof(implementationType)); }
public Dictionary <string, ExpressionResult> ParseGqlCall(string fieldName, EntityGraphQLParser.GqlCallContext context) { var argList = context.gqlarguments.children.Where(c => c.GetType() == typeof(EntityGraphQLParser.GqlargContext)).Cast <EntityGraphQLParser.GqlargContext>(); IMethodType methodType = schemaProvider.GetFieldOnContext(currentExpressionContext, fieldName, claims); var args = argList.ToDictionary(a => a.gqlfield.GetText(), a => { var argName = a.gqlfield.GetText(); if (!methodType.Arguments.ContainsKey(argName)) { throw new EntityGraphQLCompilerException($"No argument '{argName}' found on field '{methodType.Name}'"); } var r = ParseGqlarg(methodType, a); return(r); }); return(args); }
public override ExpressionResult VisitGqlcall(EntityGraphQLParser.GqlcallContext context) { var fieldName = context.method.GetText(); var argList = context.gqlarguments.children.Where(c => c.GetType() == typeof(EntityGraphQLParser.GqlargContext)).Cast <EntityGraphQLParser.GqlargContext>(); IMethodType methodType = schemaProvider.GetFieldType(currentContext, fieldName, argList.Select(a => a.gqlfield.GetText().ToLower())); var args = argList.ToDictionary(a => a.gqlfield.GetText(), a => { fieldArgumentContext = methodType; var r = VisitGqlarg(a); fieldArgumentContext = null; return(r); }, StringComparer.OrdinalIgnoreCase); if (schemaProvider.HasMutation(fieldName)) { return(MakeMutationExpression(fieldName, (MutationType)methodType, args)); } return(MakeFieldExpression(fieldName, args)); }
private ExpressionResult BuildEntityQueryExpression(IMethodType fieldArgumentContext, string fieldName, string argName, string query) { if (string.IsNullOrEmpty(query)) { return(null); } var prop = ((Field)fieldArgumentContext).ArgumentTypesObject.GetType().GetProperties().FirstOrDefault(p => p.Name == argName && p.PropertyType.GetGenericTypeDefinition() == typeof(EntityQueryType <>)); if (prop == null) { throw new EntityGraphQLCompilerException($"Can not find argument {argName} of type EntityQuery on field {fieldName}"); } var eqlt = prop.GetValue(((Field)fieldArgumentContext).ArgumentTypesObject) as BaseEntityQueryType; var contextParam = Expression.Parameter(eqlt.QueryType, $"q_{eqlt.QueryType.Name}"); ExpressionResult expressionResult = EntityQueryCompiler.CompileWith(query, contextParam, schemaProvider, claims, methodProvider, variables).ExpressionResult; expressionResult = (ExpressionResult)Expression.Lambda(expressionResult.Expression, contextParam); return(expressionResult); }
public override ExpressionResult VisitGqlcall(EntityGraphQLParser.GqlcallContext context) { var fieldName = context.method.GetText(); var argList = context.gqlarguments.children.Where(c => c.GetType() == typeof(EntityGraphQLParser.GqlargContext)).Cast <EntityGraphQLParser.GqlargContext>(); IMethodType methodType = schemaProvider.GetFieldOnContext(currentContext, fieldName, claims); var args = argList.ToDictionary(a => a.gqlfield.GetText(), a => { var argName = a.gqlfield.GetText(); if (!methodType.Arguments.ContainsKey(argName)) { throw new EntityGraphQLCompilerException($"No argument '{argName}' found on field '{methodType.Name}'"); } fieldArgumentContext = methodType; var r = VisitGqlarg(a); fieldArgumentContext = null; return(r); }); if (schemaProvider.HasMutation(fieldName)) { return(MakeMutationExpression((MutationType)methodType, args)); } return(MakeFieldExpression(fieldName, args)); }
public static Func <IRunTimeAnyRoot, RunTimeAnyRootEntry> ExternalMethodIntention(Func <IInterpetedAnyType, IInterpetedAnyType> value, IMethodType methodType) => root => { var item = new InterpetedExternalMethod(value, methodType, root); var res = new RunTimeAnyRootEntry(item, methodType); return(res); };
public void Init(Func <TIn, TOut> backing, IMethodType methodType) { Backing = backing ?? throw new ArgumentNullException(nameof(backing)); MethodType = methodType ?? throw new ArgumentNullException(nameof(methodType)); }
public static Func <IRunTimeAnyRoot, RunTimeAnyRootEntry> ExternalMethodIntention <TIn, TOut>(Func <TIn, TOut> value, IMethodType methodType) where TIn : IInterpetedAnyType where TOut : IInterpetedAnyType => root => { var item = new InterpetedExternalMethod <TIn, TOut>(value, methodType, root); var res = new RunTimeAnyRootEntry(item, methodType); return(res); };
public static IInterpetedMethod <TIn, TOut> ExternalMethod <TIn, TOut>(Func <TIn, TOut> backing, IMethodType methodType) where TIn : IInterpetedAnyType where TOut : IInterpetedAnyType => new RunTimeAnyRoot(new Func <IRunTimeAnyRoot, RunTimeAnyRootEntry>[] { ExternalMethodIntention(backing, methodType) }).Has <IInterpetedMethod <TIn, TOut> >();
private static List <InputValue> BuildArgs(ISchemaProvider schema, CombinedMapping combinedMapping, IMethodType field) { var args = new List <InputValue>(); foreach (var arg in field.Arguments) { Type clrType = arg.Value.Type.GetNonNullableType(); var gqlTypeName = clrType.IsEnumerableOrArray() ? clrType.GetEnumerableOrArrayType().Name : clrType.Name; var type = BuildType(schema, clrType, gqlTypeName, combinedMapping, true); args.Add(new InputValue { Name = arg.Key, Type = type, DefaultValue = null, Description = null, }); } return(args); }
private static List <Models.InputValue> BuildArgs(ISchemaProvider schema, IReadOnlyDictionary <Type, string> combinedMapping, IMethodType field) { var args = new List <Models.InputValue>(); foreach (var arg in field.Arguments) { var gqlTypeName = arg.Value.Type.IsEnumerableOrArray() ? arg.Value.Type.GetEnumerableOrArrayType().Name : arg.Value.Type.Name; var type = BuildType(schema, arg.Value.Type, gqlTypeName, combinedMapping); args.Add(new Models.InputValue { Name = arg.Key, Type = type, DefaultValue = null, Description = null, }); } return(args); }
public bool CanExecute(IMethodType methodType) { return(this.IsPermitted(methodType, Operations.Execute)); }
public static IInterpetedMethod ExternalMethod(Func <IInterpetedAnyType, IInterpetedAnyType> backing, IMethodType methodType) => new RunTimeAnyRoot(new Func <IRunTimeAnyRoot, RunTimeAnyRootEntry>[] { ExternalMethodIntention(backing, methodType) }).Has <IInterpetedMethod>();
private static object GetGqlReturnType(IMethodType field, ISchemaProvider schema, IReadOnlyDictionary <Type, string> combinedMapping) { return(ClrToGqlType(field.ReturnTypeNotNullable, field.ReturnElementTypeNullable, field.ReturnTypeClr, schema, combinedMapping)); }
public InterpetedExternalMethod(Func <IInterpetedAnyType, IInterpetedAnyType> backing, IMethodType methodType, IRunTimeAnyRoot root) : base(root) { this.Backing = backing ?? throw new ArgumentNullException(nameof(backing)); this.MethodType = methodType ?? throw new ArgumentNullException(nameof(methodType)); }
public bool CanExecute(IMethodType methodType) => this.IsPermitted(methodType, Operations.Execute);
public Method(SessionObject @object, IMethodType methodType) { this.Object = @object; this.MethodType = methodType; }