protected override Expression VisitParameter(ParameterExpression node) { var chain = new CallChain(this.context.GetChainPrefixFrom(node).ToList(), node, true); if (chain.Links.Any()) { this.context.SelectionChains.Add(chain); } return(base.VisitParameter(node)); }
public IEnumerable<CallChain> Expand(CallChain chainPrefix, Type type, Stack<string> visitedTypes) { if (typeof(IEnumerable).IsAssignableFrom(type) && type.IsGenericType) { var memberType = type.GetGenericArguments().Single(); return Expand(chainPrefix, memberType, visitedTypes); } var result = new List<CallChain>(); var graphQLTypeAttribute = type.GetCustomAttribute<GraphQLTypeAttribute>(); if (graphQLTypeAttribute == null) return result; visitedTypes.Push(graphQLTypeAttribute.Name); foreach (var field in type.GetProperties()) { var fieldAttribute = field.GetCustomAttribute<GraphQLFieldAttribute>(); if (fieldAttribute == null) continue; var copyOfLinks = chainPrefix.Links.ToList(); copyOfLinks.Add(new ChainLink(fieldAttribute.Name, false)); var chain = new CallChain(copyOfLinks, null, true); var graphQLTypeAttributeOnField = typeof(IEnumerable).IsAssignableFrom(field.PropertyType) && field.PropertyType.IsGenericType ? field.PropertyType.GetGenericArguments().Single().GetCustomAttribute<GraphQLTypeAttribute>() : field.PropertyType.GetCustomAttribute<GraphQLTypeAttribute>(); if (!visitedTypes.Contains(graphQLTypeAttributeOnField?.Name)) { if (!field.PropertyType.IsEnum && graphQLTypeAttributeOnField != null) { result.AddRange(Expand(chain, field.PropertyType, visitedTypes)); } else { result.Add(chain); } } } visitedTypes.Pop(); return result; }