Exemplo n.º 1
0
        public MutationType(ISchemaProvider schema, string methodName, GqlTypeInfo returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims, bool isAsync, Func <string, string> fieldNamer)
        {
            this.schema = schema;
            Description = description;
            ReturnType  = returnType;
            this.mutationClassInstance = mutationClassInstance;
            this.method     = method;
            Name            = methodName;
            AuthorizeClaims = authorizeClaims;
            this.isAsync    = isAsync;

            argInstanceType = method.GetParameters()
                              .FirstOrDefault(p => p.GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null || p.ParameterType.GetTypeInfo().GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null)?.ParameterType;
            if (argInstanceType != null)
            {
                foreach (var item in argInstanceType.GetProperties())
                {
                    if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item))
                    {
                        continue;
                    }
                    argumentTypes.Add(fieldNamer(item.Name), ArgType.FromProperty(schema, item));
                }
                foreach (var item in argInstanceType.GetFields())
                {
                    if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item))
                    {
                        continue;
                    }
                    argumentTypes.Add(fieldNamer(item.Name), ArgType.FromField(schema, item));
                }
            }
        }
Exemplo n.º 2
0
        public MutationType(ISchemaProvider schema, string methodName, GqlTypeInfo returnType, object mutationClassInstance, MethodInfo method, string description, RequiredClaims authorizeClaims, bool isAsync, Func <MemberInfo, string> fieldNamer)
        {
            Description = description;
            ReturnType  = returnType;
            this.mutationClassInstance = mutationClassInstance;
            this.method     = method;
            Name            = methodName;
            AuthorizeClaims = authorizeClaims;
            this.isAsync    = isAsync;

            argInstanceType = method.GetParameters()
                              .FirstOrDefault(p => p.GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null || p.ParameterType.GetTypeInfo().GetCustomAttribute(typeof(MutationArgumentsAttribute)) != null)?.ParameterType;
            if (argInstanceType != null)
            {
                foreach (var item in argInstanceType.GetProperties())
                {
                    if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item))
                    {
                        continue;
                    }
                    argumentTypes.Add(fieldNamer(item), ArgType.FromProperty(schema, item));
                }
                foreach (var item in argInstanceType.GetFields())
                {
                    if (GraphQLIgnoreAttribute.ShouldIgnoreMemberFromInput(item))
                    {
                        continue;
                    }
                    argumentTypes.Add(fieldNamer(item), ArgType.FromField(schema, item));
                }
            }
            //== JT: Start Here
            else
            {
                /*== JT
                 * When parameters are the standard System Types like; Int, String, etc or using the EntityGraphQL.Schema.RequiredField,
                 * loop through the parameters and NOT the object's properties
                 * NOTE: some parameters might be Services
                 * EX: public ReturnModel RemoveById(DataContext context, RequiredField<int> id)
                 */
                // !! Forcing a single parameter ONLY. Anything more than that should require a POCO !!
                ParameterInfo item = method.GetParameters()
                                     .FirstOrDefault(p => p.ParameterType.Namespace.StartsWith("EntityGraphQL.Schema") || p.ParameterType.Namespace.StartsWith("System"));

                if (item.ParameterType.Name == "Nullable`1")
                {
                    Type argType = item.ParameterType.GetGenericArguments()[0];
                    argInstanceType = argType;
                }
                else
                {
                    argInstanceType = item.ParameterType;
                }
                //TODO: see if able to use the "fieldNamer()" function
                argumentTypes.Add(SchemaGenerator.ToCamelCaseStartsLower(item.Name), ArgType.FromParameter(schema, item));
            }
            //==
        }
Exemplo n.º 3
0
 public Field(ISchemaProvider schema, string name, LambdaExpression resolve, string description, object argTypes, GqlTypeInfo returnType, RequiredClaims claims) : this(name, resolve, description, returnType, claims)
 {
     ArgumentTypesObject = argTypes;
     allArguments        = argTypes.GetType().GetProperties().ToDictionary(p => p.Name, p => ArgType.FromProperty(schema, p));
     argTypes.GetType().GetFields().ToDictionary(p => p.Name, p => ArgType.FromField(schema, p)).ToList().ForEach(kvp => allArguments.Add(kvp.Key, kvp.Value));
 }