示例#1
0
        private QueryArgumentInfoList PopulateQueryArgumentInfoList(Type?parentGraphType, Type graphQLType,
                                                                    string parentGraphQLPath, IReadOnlyCollection <string> parentEntityPath, int level)
        {
            var list = new QueryArgumentInfoList();

            if (level > _options.MaxRecursionLevel || !(Activator.CreateInstance(graphQLType) is IComplexGraphType complexGraphQLInstance))
            {
                return(list);
            }

            foreach (var ft in complexGraphQLInstance.Fields)
            {
                string graphPath = $"{parentGraphQLPath}{ft.Name}";

                Type   thisModel = graphQLType.ModelType();
                string resolvedParentEntityPath = _propertyPathResolver.Resolve(thisModel, ft.Name);

                var entityPath = new List <string>(parentEntityPath)
                {
                    resolvedParentEntityPath
                };

                bool isNonNullGraphType = ft.Type.IsNonNullGraphType();
                Type childGraphQLType   = ft.Type.GraphType();
                if (childGraphQLType.IsObjectGraphType())
                {
                    list.AddRange(PopulateQueryArgumentInfoList(parentGraphType, childGraphQLType, graphPath, entityPath, level + 1));
                }
                else if (childGraphQLType.IsListGraphType() && _options.SupportListGraphType)
                {
                    var genericType = childGraphQLType.GenericTypeArguments.First();
                    list.AddRange(PopulateQueryArgumentInfoList(childGraphQLType, genericType, graphPath, entityPath, level + 1));
                }
                else if (!childGraphQLType.IsListGraphType())
                {
                    list.Add(new QueryArgumentInfo
                    {
                        ParentGraphType = parentGraphType,
                        QueryArgument   = new QueryArgument(childGraphQLType)
                        {
                            Name = graphPath
                        },
                        GraphQLPath           = graphPath,
                        EntityPath            = entityPath,
                        IsNonNullGraphType    = isNonNullGraphType,
                        QueryArgumentInfoType = QueryArgumentInfoType.GraphQL
                    });
                }
            }

            return(list);
        }
示例#2
0
        private QueryArgumentInfoList PopulateQueryArgumentInfoList(Type graphQLType, string parentGraphQLPath, string parentEntityPath, int level)
        {
            var list = new QueryArgumentInfoList();

            if (level > _options.MaxRecursionLevel || !(Activator.CreateInstance(graphQLType) is IComplexGraphType complexGraphQLInstance))
            {
                return(list);
            }

            complexGraphQLInstance.Fields.ToList().ForEach(ft =>
            {
                string graphPath = $"{parentGraphQLPath}{ft.Name}";

                Type thisModel = graphQLType.ModelType();
                string resolvedParentEntityPath = _propertyPathResolver.Resolve(thisModel, ft.Name);
                string entityPath = !string.IsNullOrEmpty(parentEntityPath) ? $"{parentEntityPath}.{resolvedParentEntityPath}" : resolvedParentEntityPath;

                bool isNonNullGraphType = ft.Type.IsNonNullGraphType();
                Type childGraphQLType   = ft.Type.GraphType();
                if (childGraphQLType.IsObjectGraphType())
                {
                    list.AddRange(PopulateQueryArgumentInfoList(childGraphQLType, graphPath, entityPath, level + 1));
                }
                else
                {
                    list.Add(new QueryArgumentInfo
                    {
                        QueryArgument = new QueryArgument(childGraphQLType)
                        {
                            Name = graphPath
                        },
                        GraphQLPath           = graphPath,
                        EntityPath            = entityPath,
                        IsNonNullGraphType    = isNonNullGraphType,
                        QueryArgumentInfoType = QueryArgumentInfoType.GraphQL
                    });
                }
            });

            return(list);
        }