Esempio n. 1
0
        public void Include_ShouldKeepArgumentInList()
        {
            // Arrange
            var infoId = new QueryArgumentInfo
            {
                QueryArgumentInfoType = QueryArgumentInfoType.GraphQL,
                QueryArgument         = new QueryArgument(typeof(IntGraphType))
                {
                    Name = "Id"
                },
                IsNonNullGraphType = true,
                GraphQLPath        = "Id",
                EntityPath         = new List <string> {
                    "Id"
                }
            };

            _sut.Add(infoId);
            var infoX = new QueryArgumentInfo
            {
                QueryArgumentInfoType = QueryArgumentInfoType.GraphQL,
                QueryArgument         = new QueryArgument(typeof(IntGraphType))
                {
                    Name = "X"
                },
                IsNonNullGraphType = true,
                GraphQLPath        = "X",
                EntityPath         = new List <string> {
                    "X"
                }
            };

            _sut.Add(infoX);

            // Act
            var list = _sut.Include("Id");

            // Assert
            list.Count.Should().Be(1);
            list[0].Should().Be(infoId);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }