public SelectionSetProvider( IGraphTypeProvider graphTypeProvider, IGraphSchemaProvider schemaProvider, IQueryResultTypeGenerator typeGenerator, ILogger <SelectionSetProvider> logger, IOptions <GraphOptions> optionsAccessor) { Guard.ArgumentNotNull(schemaProvider, nameof(schemaProvider)); _graphTypeProvider = graphTypeProvider ?? throw new ArgumentNullException(nameof(graphTypeProvider)); _selections = new ConcurrentDictionary <string, ICollection <ISelectionNode> >(); _typeGenerator = Guard.ArgumentNotNull(typeGenerator, nameof(typeGenerator)); _schema = schemaProvider.Schema; _fieldNameConverter = Guard.ArgumentNotNull(optionsAccessor, nameof(optionsAccessor)).Value.FieldNameConverter; _logger = Guard.ArgumentNotNull(logger, nameof(logger)); _log4MissCache = LoggerMessage.Define <DateTimeOffset, string, string>(LogLevel.Trace, 0, "[{0}]Selection set cache missing. Operation: {1}; Reason: {2}."); }
public static bool SetIncludeAllFieldsFlags( this IFieldSelection selection, GraphField graphField, IQueryResultTypeGenerator typeGenerator, ref bool generateQueryResultType, out bool isSubQueryTree) { Guard.ArgumentNotNull(selection, nameof(selection)); Guard.ArgumentNotNull(graphField, nameof(graphField)); EnsureSpecifyRequiredArguments(selection, graphField); isSubQueryTree = true; bool?flags = null; if (graphField.HasCustomResolver() || selection.Directives.Any() || selection.SelectionSet.Any(it => it is IFragment)) { generateQueryResultType = false; isSubQueryTree = false; flags = false; } var subFieldSelections = selection.SelectionSet.OfType <IFieldSelection>().ToArray(); foreach (var subSelection in subFieldSelections) { var subFields = graphField.GraphType.Fields.Values.Where(it => it.Name == subSelection.Name).ToArray(); if (subFields.Length > 1) { throw new GraphException($"{graphField.GraphType.Name} is a union GraphType, please perform query using fragement."); } if (subFields.Length == 0) { throw new GraphException($"Field '{subSelection.Name}' is not defined in the GraphType '{graphField.GraphType.Name}'"); } if (!SetIncludeAllFieldsFlags(subSelection, subFields[0], typeGenerator, ref generateQueryResultType, out var isSubtree)) { flags = false; if (!isSubtree) { isSubQueryTree = false; } } } var fragements = selection.SelectionSet.OfType <IFragment>().ToArray(); foreach (var fragement in fragements) { foreach (IFieldSelection fieldSelection in fragement.SelectionSet) { var fields = fragement.GraphType.Fields.Values.Where(it => it.Name == fieldSelection.Name).ToArray(); if (fields.Length > 1) { throw new GraphException($"{graphField.GraphType.Name} is a union GraphType, please perform query using fragement."); } if (fields.Length == 0) { throw new GraphException($"Field '{fieldSelection.Name}' is not defined in the GraphType '{fragement.GraphType.Name}'"); } if (!SetIncludeAllFieldsFlags(fieldSelection, fields[0], typeGenerator, ref generateQueryResultType, out var isSubtree)) { flags = false; if (!isSubtree) { isSubQueryTree = false; } } } } if (isSubQueryTree == false) { selection.Properties[GraphDefaults.PropertyNames.IsSubQueryTree] = false; } else { if (graphField.GraphType.Fields.Any() && generateQueryResultType) { selection.Properties[GraphDefaults.PropertyNames.QueryResultType] = typeGenerator.Generate(selection, graphField); selection.Properties[GraphDefaults.PropertyNames.IsSubQueryTree] = false; } } if (!IncludeAllMembers(selection, graphField) || flags == false) { selection.Properties[GraphDefaults.PropertyNames.IncludeAllFields] = false; return(false); } selection.Properties[GraphDefaults.PropertyNames.IncludeAllFields] = true; return(true); }