public static IPreparedOperation Compile( string operationId, DocumentNode document, OperationDefinitionNode operation, ISchema schema, ObjectType rootType, InputParser inputParser, IEnumerable <ISelectionOptimizer>?optimizers = null) { if (operationId == null) { throw new ArgumentNullException(nameof(operationId)); } if (document == null) { throw new ArgumentNullException(nameof(document)); } if (operation == null) { throw new ArgumentNullException(nameof(operation)); } if (schema == null) { throw new ArgumentNullException(nameof(schema)); } if (rootType == null) { throw new ArgumentNullException(nameof(rootType)); } if (operation.SelectionSet.Selections.Count == 0) { throw OperationCompiler_NoOperationSelections(operation); } var fragments = new FragmentCollection(schema, document); var compiler = new OperationCompiler(schema, fragments, inputParser); var selectionSetLookup = new Dictionary <SelectionSetNode, SelectionVariants>(); var backlog = new Stack <CompilerContext>(); // creates and enqueues the root compiler context. CompilerContext.New( backlog, rootType, operation.SelectionSet, optimizers?.ToImmutableList() ?? ImmutableList <ISelectionOptimizer> .Empty, selectionSetLookup); // processes the backlog and by doing so traverses the query graph. compiler.Visit(backlog); return(new Operation(operationId, document, operation, rootType, selectionSetLookup)); }
public static IReadOnlyDictionary <SelectionSetNode, SelectionVariants> Compile( ISchema schema, FragmentCollection fragments, OperationDefinitionNode operation, IEnumerable <ISelectionOptimizer>?optimizers = null) { var compiler = new OperationCompiler(schema, fragments); var selectionSetLookup = new Dictionary <SelectionSetNode, SelectionVariants>(); ObjectType rootType = schema.GetOperationType(operation.Operation); var backlog = new Stack <CompilerContext>(); // creates and enqueues the root compiler context. CompilerContext.New( backlog, rootType, operation.SelectionSet, optimizers?.ToImmutableList() ?? ImmutableList <ISelectionOptimizer> .Empty, selectionSetLookup); // processes the backlog and by doing so traverses the query graph. compiler.Visit(backlog); return(selectionSetLookup); }