### Tokenize GraphQL Source with Lexer.Lex Source: https://context7.com/graphql-dotnet/parser/llms.txt Demonstrates how to use the Lexer.Lex method to tokenize GraphQL source strings. This method identifies token kinds and values, and supports starting the lexing process from specific character positions. ```csharp using GraphQLParser; // Tokenize a simple string value var token = Lexer.Lex("\"hello\""); Console.WriteLine($"Kind: {token.Kind}"); // Output: Kind: STRING Console.WriteLine($"Value: {token.Value}"); // Output: Value: hello Console.WriteLine($"Start: {token.Start}"); // Output: Start: 0 Console.WriteLine($"End: {token.End}"); // Output: End: 7 // Tokenize different token types var nameToken = Lexer.Lex("query"); Console.WriteLine($"Kind: {nameToken.Kind}, Value: {nameToken.Value}"); // Kind: NAME, Value: query var intToken = Lexer.Lex("42"); Console.WriteLine($"Kind: {intToken.Kind}, Value: {intToken.Value}"); // Kind: INT, Value: 42 var floatToken = Lexer.Lex("3.14159"); Console.WriteLine($"Kind: {floatToken.Kind}, Value: {floatToken.Value}"); // Kind: FLOAT, Value: 3.14159 // Start lexing from a specific position var source = "{ field }"; var braceToken = Lexer.Lex(source, 0); // Returns BRACE_L var fieldToken = Lexer.Lex(source, 2); // Returns NAME "field" Console.WriteLine($"Brace: {braceToken.Kind}, Field: {fieldToken.Kind} '{fieldToken.Value}'"); ``` -------------------------------- ### Traverse GraphQL AST with ASTVisitor Source: https://context7.com/graphql-dotnet/parser/llms.txt Demonstrates how to implement custom AST processing by inheriting from ASTVisitor. Includes examples for collecting field names and counting node types within a GraphQL document. ```csharp using GraphQLParser; using GraphQLParser.AST; using GraphQLParser.Visitors; public class FieldCollector : ASTVisitor { public class Context : IASTVisitorContext { public CancellationToken CancellationToken => default; public List FieldNames { get; } = new(); } protected override ValueTask VisitFieldAsync(GraphQLField field, Context context) { context.FieldNames.Add(field.Name.Value.ToString()); return base.VisitFieldAsync(field, context); } } var document = Parser.Parse("query { user { name email posts { title content } } }"); var collector = new FieldCollector(); var context = new FieldCollector.Context(); await collector.VisitAsync(document, context); ``` -------------------------------- ### GraphQL Lexer Function Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Implements the lexer functionality for GraphQL, responsible for tokenizing a given source string into a sequence of tokens. It takes the source ROM and an optional start position, returning the first token. ```csharp public static class Lexer { public static GraphQLParser.Token Lex(GraphQLParser.ROM source, int start = 0) { } ``` -------------------------------- ### GraphQL Location Structure Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Represents a location in the GraphQL source text, defined by start and end positions. This struct implements IEquatable for comparison and provides methods for deconstruction and equality checks. ```csharp public readonly struct GraphQLLocation : System.IEquatable { public GraphQLLocation(int start, int end) { } public int End { get; } public int Start { get; } public void Deconstruct(out int start, out int end) { } public bool Equals(GraphQLParser.AST.GraphQLLocation other) { } public override bool Equals(object? obj) { } public override int GetHashCode() { } public override string ToString() { } public static bool operator !=(GraphQLParser.AST.GraphQLLocation left, GraphQLParser.AST.GraphQLLocation right) { } public static bool operator ==(GraphQLParser.AST.GraphQLLocation left, GraphQLParser.AST.GraphQLLocation right) { } ``` -------------------------------- ### GraphQL Token Struct Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Represents a single token generated by the GraphQL lexer. It includes the token's kind, its string value, and its start and end positions within the source. This struct is fundamental for the parsing process. ```csharp public readonly struct Token { public Token(GraphQLParser.TokenKind kind, GraphQLParser.ROM value, int start, int end) { } public int End { get; } public GraphQLParser.TokenKind Kind { get; } public int Start { get; } public GraphQLParser.ROM Value { get; } public override string ToString() { } ``` -------------------------------- ### GraphQL Location Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Represents a location in the source text, defined by start and end positions. ```APIDOC ## GraphQLLocation ### Description Represents a location within the source GraphQL document, defined by its starting and ending character positions. ### Struct Definition ```csharp public readonly struct GraphQLLocation : System.IEquatable { public GraphQLLocation(int start, int end); public int End { get; } public int Start { get; } public void Deconstruct(out int start, out int end); public bool Equals(GraphQLParser.AST.GraphQLLocation other); public override bool Equals(object? obj); public override int GetHashCode(); public override string ToString(); public static bool operator !=(GraphQLParser.AST.GraphQLLocation left, GraphQLParser.AST.GraphQLLocation right); public static bool operator ==(GraphQLParser.AST.GraphQLLocation left, GraphQLParser.AST.GraphQLLocation right); } ``` ``` -------------------------------- ### Convert AST nodes to SDL using SDLPrinter Source: https://context7.com/graphql-dotnet/parser/llms.txt Shows how to use the SDLPrinter class to convert AST nodes back into Schema Definition Language. It covers printing to strings, StringBuilders, and TextWriters, as well as configuring output with SDLPrinterOptions. ```csharp using GraphQLParser; using GraphQLParser.Visitors; using System.Text; var document = Parser.Parse(@"query{hero{name age}}"); var printer = new SDLPrinter(); // Print to string string sdl = printer.Print(document); // Print to StringBuilder var sb = new StringBuilder(); printer.Print(document, sb); // Async printing to TextWriter using var writer = new StringWriter(); await printer.PrintAsync(document, writer); // Print with custom options var customPrinter = new SDLPrinter(new SDLPrinterOptions { PrintComments = true, PrintDescriptions = true, IndentSize = 4 }); var schemaDoc = Parser.Parse(@"...", new ParserOptions { Ignore = IgnoreOptions.None }); string formattedSdl = customPrinter.Print(schemaDoc); ``` -------------------------------- ### Lexer Usage Source: https://github.com/graphql-dotnet/parser/blob/master/README.md Demonstrates how to use the Lexer to convert GraphQL text into tokens. The lexer is optimized for minimal memory allocation. ```APIDOC ## Lexer Usage ### Description Generates token based on input text. Lexer takes advantage of `ReadOnlyMemory` and in most cases does not allocate memory on the managed heap at all. ### Method Static method call ### Endpoint N/A (Library function) ### Parameters N/A ### Request Example ```csharp var token = Lexer.Lex("\"str\""); ``` ### Response #### Success Response (Token) - **token** (object) - The first token found in the input string. #### Response Example (Visual representation of the token, e.g., type, value, location) ``` -------------------------------- ### Implement GraphQL AST Visitor Methods Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt A set of protected asynchronous methods used to visit different nodes in a GraphQL AST. These methods accept a specific AST node type and a context object, allowing for customized handling of schema definitions, types, and values. ```csharp protected override System.Threading.Tasks.ValueTask VisitEnumTypeExtensionAsync(GraphQLParser.AST.GraphQLEnumTypeExtension enumTypeExtension, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitEnumValueAsync(GraphQLParser.AST.GraphQLEnumValue enumValue, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitFieldAsync(GraphQLParser.AST.GraphQLField field, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitObjectTypeDefinitionAsync(GraphQLParser.AST.GraphQLObjectTypeDefinition objectTypeDefinition, TContext context) { } ``` -------------------------------- ### Implement AST Node Visitor in C# Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt This method provides a template for visiting AST nodes asynchronously. It accepts an AST node and a generic context, allowing for custom processing logic during tree traversal. ```csharp public override System.Threading.Tasks.ValueTask VisitAsync(GraphQLParser.AST.ASTNode? node, TContext context) { // Implementation logic goes here return System.Threading.Tasks.ValueTask.CompletedTask; } ``` -------------------------------- ### AST Visitor Pattern Implementation Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt The ASTVisitor class provides a base implementation for traversing the GraphQL Abstract Syntax Tree using asynchronous methods. It allows developers to define custom logic for visiting specific nodes within the tree. ```csharp public class ASTVisitor where TContext : IASTVisitorContext { public virtual async ValueTask VisitAsync(ASTNode? node, TContext context) { // Implementation for traversing nodes } protected virtual ValueTask VisitFieldAsync(GraphQLField field, TContext context) { } protected virtual ValueTask VisitDocumentAsync(GraphQLDocument document, TContext context) { } } ``` -------------------------------- ### Parser Usage Source: https://github.com/graphql-dotnet/parser/blob/master/README.md Shows how to use the Parser to convert GraphQL text into an Abstract Syntax Tree (AST). Includes options for ignoring comments and locations. ```APIDOC ## Parser Usage ### Description Parses provided GraphQL expression into AST (abstract syntax tree). Parser also takes advantage of `ReadOnlyMemory` but still allocates memory for AST. ### Method Static method call ### Endpoint N/A (Library function) ### Parameters #### Query Parameters - **options** (ParserOptions) - Optional. Allows specifying `IgnoreOptions` like `Comments` or `Locations` to optimize memory usage. ### Request Example ```csharp var ast1 = Parser.Parse(@" { field }"); var ast2 = Parser.Parse(@" { field }", new ParserOptions { Ignore = IgnoreOptions.Comments }); ``` ### Response #### Success Response (AST) - **ast** (GraphQLDocument or specific AST node) - The generated Abstract Syntax Tree. #### Response Example (Representation of the AST structure) ``` -------------------------------- ### SDLPrinter Usage Source: https://github.com/graphql-dotnet/parser/blob/master/README.md Explains how to use the SDLPrinter to generate Schema Definition Language (SDL) from a parsed GraphQL AST. ```APIDOC ## SDLPrinter Usage ### Description For printing SDL from AST, you can use `SDLPrinter`. This is a highly optimized visitor for asynchronous non-blocking SDL output into provided `TextWriter`. Extension methods are also provided for printing directly to a string, which utilize the `StringBuilder` and `StringWriter` classes. ### Method Instantiate `SDLPrinter` and call `Print` or `PrintAsync` methods. ### Endpoint N/A (Library function) ### Parameters #### Request Body - **document** (GraphQLDocument) - The AST document to print. - **writer** (TextWriter) - Optional. The writer to output the SDL to. - **sb** (StringBuilder) - Optional. Used by extension methods for string building. - **options** (SDLPrinterOptions) - Optional. For configuring print behavior (e.g., `PrintComments`, `EachDirectiveLocationOnNewLine`). ### Request Example ```csharp var document = Parser.Parse("query { hero { name age } }"); // print to a string with default options var sdl = new SDLPrinter().Print(document); // print to a string builder var sb = new StringBuilder(); new SDLPrinter().Print(document, sb); // print to a string with some options var sdlPrinter = new SDLPrinter( new SDLPrinterOptions { PrintComments = true, EachDirectiveLocationOnNewLine = true, EachUnionMemberOnNewLine = true, }); var sdl = sdlPrinter.Print(document); // print to a stream asynchronously using var writer = new StreamWriter(stream); await sdlPrinter.PrintAsync(document, writer, default); await writer.FlushAsync(); ``` ### Response #### Success Response (SDL String or Written Output) - **sdl** (string) - The generated SDL string. - Output written to the provided `TextWriter`. #### Response Example ```graphql query { hero { name age } } ``` ``` -------------------------------- ### Iterate GraphQL AST Definitions Source: https://context7.com/graphql-dotnet/parser/llms.txt Demonstrates how to traverse a parsed GraphQL document's definitions, categorizing them by type (Object, Enum, Fragment, or Operation) and extracting relevant metadata. ```csharp foreach (var definition in document.Definitions) { switch (definition) { case GraphQLObjectTypeDefinition objType: Console.WriteLine($"Object Type: {objType.Name.Value}"); break; case GraphQLEnumTypeDefinition enumType: Console.WriteLine($"Enum: {enumType.Name.Value}"); break; case GraphQLFragmentDefinition fragment: Console.WriteLine($"Fragment: {fragment.FragmentName.Name.Value} on {fragment.TypeCondition.Type.Name.Value}"); break; case GraphQLOperationDefinition operation: Console.WriteLine($"Operation: {operation.Operation} {operation.Name?.Value ?? "(anonymous)"}"); break; } } ``` -------------------------------- ### Print AST Node to String Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Uses the SDLPrinterExtensions to convert a GraphQL AST node into a formatted SDL string. This is a convenient wrapper for the printer functionality. ```csharp var printer = new GraphQLParser.Visitors.SDLPrinter(options); string sdl = printer.Print(astNode); ``` -------------------------------- ### SDLSorter - Sorting GraphQL AST Source: https://github.com/graphql-dotnet/parser/blob/master/README.md Demonstrates how to sort a GraphQL Abstract Syntax Tree (AST) using the SDLSorter. It sorts the document based on a predefined order and allows for custom comparison logic. ```APIDOC ## SDLSorter - Sorting GraphQL AST ### Description An AST document can be sorted with the `SDLSorter` using a predefined sort order. You can specify the string comparison; by default it uses a culture-invariant case-insensitive comparison. Any further customization is possible by deriving from `SDLSorterOptions` and overriding the `Compare` methods. ### Method N/A (Static method) ### Endpoint N/A ### Parameters N/A ### Request Example ```csharp var document = Parser.Parse("query { hero { name age } }"); SDLSorter.Sort(document); var sdl = new SDLPrinter().Print(document); ``` ### Response N/A #### Success Response (200) N/A #### Response Example ```graphql query { hero { age name } } ``` ``` -------------------------------- ### Visualize AST structure with StructurePrinter Source: https://context7.com/graphql-dotnet/parser/llms.txt Shows how to output a hierarchical text representation of a parsed GraphQL document. This is useful for debugging AST nodes and can optionally include location information. ```csharp using GraphQLParser; using GraphQLParser.Visitors; var document = Parser.Parse(@"query GetUser($id: ID!) { user(id: $id) { name email } }"); var structurePrinter = new StructurePrinter(); using var writer = new StringWriter(); await structurePrinter.PrintAsync(document, writer); Console.WriteLine(writer.ToString()); var locationPrinter = new StructurePrinter(new StructurePrinterOptions { PrintNames = true, PrintLocations = true, IndentSize = 4 }); var simpleDoc = Parser.Parse("{ field }"); using var locWriter = new StringWriter(); await locationPrinter.PrintAsync(simpleDoc, locWriter); Console.WriteLine(locWriter.ToString()); ``` -------------------------------- ### Printing AST to SDL String Source: https://github.com/graphql-dotnet/parser/blob/master/README.md The SDLPrinter is an optimized AST visitor for generating Schema Definition Language (SDL) output from a parsed GraphQL AST. It supports various options for formatting and can print to strings, StringBuilders, or streams asynchronously, often with minimal memory allocation. ```csharp var document = Parser.Parse("query { hero { name age } }"); // print to a string with default options var sdl = new SDLPrinter().Print(document); ``` ```csharp // print to a string builder var sb = new StringBuilder(); new SDLPrinter().Print(document, sb); ``` ```csharp // print to a string with some options var sdlPrinter = new SDLPrinter( new SDLPrinterOptions { PrintComments = true, EachDirectiveLocationOnNewLine = true, EachUnionMemberOnNewLine = true, }); var sdl = sdlPrinter.Print(document); ``` ```csharp // print to a stream asynchronously using var writer = new StreamWriter(stream); await sdlPrinter.PrintAsync(document, writer, default); await writer.FlushAsync(); ``` -------------------------------- ### CountVisitor Implementation Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt A concrete implementation of an AST visitor designed to count nodes based on a provided condition. It extends the base ASTVisitor and requires a context that implements ICountContext. ```csharp public class CountVisitor : GraphQLParser.Visitors.ASTVisitor where TContext : GraphQLParser.Visitors.ICountContext { public CountVisitor() { } public override System.Threading.Tasks.ValueTask VisitAsync(GraphQLParser.AST.ASTNode? node, TContext context) { } ``` -------------------------------- ### Parse GraphQL Documents into AST with Parser.Parse Source: https://context7.com/graphql-dotnet/parser/llms.txt Shows how to convert GraphQL source text into a GraphQLDocument AST. It covers accessing definitions, variables, and selection sets, as well as configuring ParserOptions for memory optimization and comment handling. ```csharp using GraphQLParser; using GraphQLParser.AST; // Parse a simple query var document = Parser.Parse(@" query GetUser($id: ID!) { user(id: $id) { name email posts { title createdAt } } } "); // Access the parsed AST var operation = document.Definitions[0] as GraphQLOperationDefinition; Console.WriteLine($"Operation: {operation.Operation}"); // Output: Operation: Query Console.WriteLine($"Name: {operation.Name?.Value}"); // Output: Name: GetUser // Access variables var variable = operation.Variables?.Items[0]; Console.WriteLine($"Variable: ${variable?.Variable.Name.Value}: {((GraphQLNamedType)variable?.Type)?.Name.Value}!"); // Access selection set var userField = operation.SelectionSet?.Selections[0] as GraphQLField; Console.WriteLine($"Field: {userField?.Name.Value}"); // Parse with memory-optimized options var optimizedDoc = Parser.Parse(@"{ hero { name } }", new ParserOptions { Ignore = IgnoreOptions.All, // Ignore comments and locations MaxDepth = 64 // Limit recursion depth }); // Parse with comment preservation var docWithComments = Parser.Parse(@" # This is a comment query { field } ", new ParserOptions { Ignore = IgnoreOptions.None }); Console.WriteLine($"Has unattached comments: {docWithComments.UnattachedComments?.Count > 0}"); ``` -------------------------------- ### GraphQL Parser Options Struct Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Defines options for the GraphQL parser, allowing customization of the parsing process. Key options include ignoring specific elements like comments or locations, and setting a maximum depth for the AST. ```csharp public struct ParserOptions { public GraphQLParser.IgnoreOptions Ignore { get; set; } public int? MaxDepth { get; set; } ``` -------------------------------- ### StructurePrinter - Visualizing GraphQL AST Source: https://github.com/graphql-dotnet/parser/blob/master/README.md Explains how to use the StructurePrinter to traverse and print the structure of a GraphQL AST to a TextWriter. This is useful for debugging and understanding the AST's hierarchy. ```APIDOC ## StructurePrinter - Visualizing GraphQL AST ### Description You can also find a `StructurePrinter` visitor that prints AST into the provided `TextWriter` as a hierarchy of node types. It can be useful when debugging for better understanding the AST structure. ### Method N/A (Instance method) ### Endpoint N/A ### Parameters N/A ### Request Example ```csharp public static async Task PrintStructure(string sdl) { var document = Parser.Parse(sdl); using var writer = new StringWriter(); var printer = new StructurePrinter() await printer.PrintAsync(document, writer); var rendered = writer.ToString(); Console.WriteLine(rendered); } ``` ### Response N/A #### Success Response (200) N/A #### Response Example ``` Document OperationDefinition Name [a] SelectionSet Field Name [name] Field Name [age] ``` ``` -------------------------------- ### MaxDepthVisitor Implementation Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt An AST visitor implementation focused on calculating the maximum depth of a GraphQL AST. It utilizes a context that implements IMaxDepthContext to store depth information and manage parent nodes. ```csharp public class MaxDepthVisitor : GraphQLParser.Visitors.ASTVisitor where TContext : GraphQLParser.Visitors.IMaxDepthContext { public MaxDepthVisitor() { } public override System.Threading.Tasks.ValueTask VisitAsync(GraphQLParser.AST.ASTNode? node, TContext context) { } ``` -------------------------------- ### IPrintContext Interface Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Extends IASTVisitorContext to provide properties and methods necessary for printing the GraphQL AST to a text writer, including indentation and tracking the last visited node. ```csharp public interface IPrintContext : GraphQLParser.Visitors.IASTVisitorContext { int IndentLevel { get; set; } bool IndentPrinted { get; set; } [System.Obsolete("Use LastVisitedNode instead")] bool LastDefinitionPrinted { get; set; } GraphQLParser.AST.ASTNode? LastVisitedNode { get; set; } bool NewLinePrinted { get; set; } System.Collections.Generic.Stack Parents { get; } System.IO.TextWriter Writer { get; } ``` -------------------------------- ### AST Visitor Pattern Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Provides the base class for visiting nodes in the GraphQL Abstract Syntax Tree (AST). ```APIDOC ## AST Visitor Pattern ### Description The `ASTVisitor` class provides a framework for traversing the Abstract Syntax Tree (AST) of a GraphQL document. It defines virtual methods for visiting various AST node types, allowing custom logic to be executed at each node. ### Base Class - **ASTVisitor** - Generic class where `TContext` is a type implementing `GraphQLParser.Visitors.IASTVisitorContext`. - Provides a default constructor: `ASTVisitor()` ### Core Methods - **VisitAsync(GraphQLParser.AST.ASTNode? node, TContext context)** - The main entry point for visiting a node. It dispatches to the appropriate `Visit...Async` method based on the node type. ### Visit Methods (Examples) - **VisitAliasAsync(GraphQLParser.AST.GraphQLAlias alias, TContext context)**: Visits a GraphQL Alias node. - **VisitArgumentAsync(GraphQLParser.AST.GraphQLArgument argument, TContext context)**: Visits a GraphQL Argument node. - **VisitArgumentsAsync(GraphQLParser.AST.GraphQLArguments arguments, TContext context)**: Visits a collection of GraphQL Arguments. - **VisitArgumentsDefinitionAsync(GraphQLParser.AST.GraphQLArgumentsDefinition argumentsDefinition, TContext context)**: Visits GraphQL Arguments Definition. - **VisitAsync(System.Collections.Generic.List? nodes, TContext context)**: Helper method to visit a list of AST nodes. - **VisitBooleanValueAsync(GraphQLParser.AST.GraphQLBooleanValue booleanValue, TContext context)**: Visits a GraphQL Boolean Value node. - **VisitCommentAsync(GraphQLParser.AST.GraphQLComment comment, TContext context)**: Visits a GraphQL Comment node. - **VisitDescriptionAsync(GraphQLParser.AST.GraphQLDescription description, TContext context)**: Visits a GraphQL Description node. - **VisitDirectiveAsync(GraphQLParser.AST.GraphQLDirective directive, TContext context)**: Visits a GraphQL Directive node. - **VisitDirectiveDefinitionAsync(GraphQLParser.AST.GraphQLDirectiveDefinition directiveDefinition, TContext context)**: Visits a GraphQL Directive Definition node. - **VisitDirectiveLocationsAsync(GraphQLParser.AST.GraphQLDirectiveLocations directiveLocations, TContext context)**: Visits GraphQL Directive Locations. - **VisitDirectivesAsync(GraphQLParser.AST.GraphQLDirectives directives, TContext context)**: Visits a collection of GraphQL Directives. - **VisitDocumentAsync(GraphQLParser.AST.GraphQLDocument document, TContext context)**: Visits the root GraphQL Document node. - **VisitEnumTypeDefinitionAsync(GraphQLParser.AST.GraphQLEnumTypeDefinition enumTypeDefinition, TContext context)**: Visits an Enum Type Definition node. - **VisitEnumTypeExtensionAsync(GraphQLParser.AST.GraphQLEnumTypeExtension enumTypeExtension, TContext context)**: Visits an Enum Type Extension node. - **VisitEnumValueAsync(GraphQLParser.AST.GraphQLEnumValue enumValue, TContext context)**: Visits an Enum Value node. - **VisitEnumValueDefinitionAsync(GraphQLParser.AST.GraphQLEnumValueDefinition enumValueDefinition, TContext context)**: Visits an Enum Value Definition node. - **VisitEnumValuesDefinitionAsync(GraphQLParser.AST.GraphQLEnumValuesDefinition enumValuesDefinition, TContext context)**: Visits Enum Values Definition. - **VisitFieldAsync(GraphQLParser.AST.GraphQLField field, TContext context)**: Visits a Field node. - **VisitFieldDefinitionAsync(GraphQLParser.AST.GraphQLFieldDefinition fieldDefinition, TContext context)**: Visits a Field Definition node. - **VisitFieldsDefinitionAsync(GraphQLParser.AST.GraphQLFieldsDefinition fieldsDefinition, TContext context)**: Visits Fields Definition. - **VisitFloatValueAsync(GraphQLParser.AST.GraphQLFloatValue floatValue, TContext context)**: Visits a Float Value node. *Note: All `Visit...Async` methods are virtual and can be overridden in derived classes to implement custom visitor logic.* ``` -------------------------------- ### GraphQL AST Visitor Base Class Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Provides a base class for AST visitors, defining asynchronous methods for visiting various GraphQL AST nodes. These methods are intended to be overridden by concrete visitor implementations. ```csharp protected override System.Threading.Tasks.ValueTask VisitOperationDefinitionAsync(GraphQLParser.AST.GraphQLOperationDefinition operationDefinition, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitRootOperationTypeDefinitionAsync(GraphQLParser.AST.GraphQLRootOperationTypeDefinition rootOperationTypeDefinition, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitScalarTypeDefinitionAsync(GraphQLParser.AST.GraphQLScalarTypeDefinition scalarTypeDefinition, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitScalarTypeExtensionAsync(GraphQLParser.AST.GraphQLScalarTypeExtension scalarTypeExtension, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitSchemaDefinitionAsync(GraphQLParser.AST.GraphQLSchemaDefinition schemaDefinition, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitSchemaExtensionAsync(GraphQLParser.AST.GraphQLSchemaExtension schemaExtension, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitSelectionSetAsync(GraphQLParser.AST.GraphQLSelectionSet selectionSet, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitStringValueAsync(GraphQLParser.AST.GraphQLStringValue stringValue, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitTypeConditionAsync(GraphQLParser.AST.GraphQLTypeCondition typeCondition, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitUnionMemberTypesAsync(GraphQLParser.AST.GraphQLUnionMemberTypes unionMemberTypes, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitUnionTypeDefinitionAsync(GraphQLParser.AST.GraphQLUnionTypeDefinition unionTypeDefinition, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitUnionTypeExtensionAsync(GraphQLParser.AST.GraphQLUnionTypeExtension unionTypeExtension, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitVariableAsync(GraphQLParser.AST.GraphQLVariable variable, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitVariableDefinitionAsync(GraphQLParser.AST.GraphQLVariableDefinition variableDefinition, TContext context) { } protected override System.Threading.Tasks.ValueTask VisitVariablesDefinitionAsync(GraphQLParser.AST.GraphQLVariablesDefinition variablesDefinition, TContext context) { } ``` -------------------------------- ### SDLSorter for GraphQL AST Nodes Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Implements an AST visitor to sort GraphQL Abstract Syntax Tree nodes. It provides a static Sort method and comparison logic for AST nodes and directive locations. ```csharp public sealed class SDLSorter : GraphQLParser.Visitors.ASTVisitor { protected override System.Threading.Tasks.ValueTask VisitAsync(System.Collections.Generic.List? nodes, GraphQLParser.Visitors.SDLSorterOptions context) where T : GraphQLParser.AST.ASTNode { } protected override System.Threading.Tasks.ValueTask VisitDirectiveLocationsAsync(GraphQLParser.AST.GraphQLDirectiveLocations directiveLocations, GraphQLParser.Visitors.SDLSorterOptions context) { } public static void Sort(GraphQLParser.AST.ASTNode node, GraphQLParser.Visitors.SDLSorterOptions? options = null) { } } ``` -------------------------------- ### DefaultVisitorContext Implementation Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt A minimal implementation of the IASTVisitorContext interface, primarily providing a CancellationToken for asynchronous operations. ```csharp public struct DefaultVisitorContext : GraphQLParser.Visitors.IASTVisitorContext { public System.Threading.CancellationToken CancellationToken { get; } ``` -------------------------------- ### AST Visitor Base Class Methods Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Provides a set of protected virtual methods for visiting different types of AST nodes within the GraphQL parser. These methods are intended to be overridden by derived visitor classes to implement specific traversal logic. ```csharp protected virtual System.Threading.Tasks.ValueTask VisitStringValueAsync(GraphQLParser.AST.GraphQLStringValue stringValue, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitTypeConditionAsync(GraphQLParser.AST.GraphQLTypeCondition typeCondition, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitUnionMemberTypesAsync(GraphQLParser.AST.GraphQLUnionMemberTypes unionMemberTypes, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitUnionTypeDefinitionAsync(GraphQLParser.AST.GraphQLUnionTypeDefinition unionTypeDefinition, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitUnionTypeExtensionAsync(GraphQLParser.AST.GraphQLUnionTypeExtension unionTypeExtension, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitVariableAsync(GraphQLParser.AST.GraphQLVariable variable, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitVariableDefinitionAsync(GraphQLParser.AST.GraphQLVariableDefinition variableDefinition, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitVariablesDefinitionAsync(GraphQLParser.AST.GraphQLVariablesDefinition variablesDefinition, TContext context) { } ``` -------------------------------- ### Asynchronous AST Visitor Methods for GraphQL-dotnet Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt A set of protected virtual methods designed to be overridden in a visitor class. These methods return a ValueTask and accept an AST node and a context object, facilitating efficient, non-blocking traversal of GraphQL document structures. ```csharp protected virtual System.Threading.Tasks.ValueTask VisitFragmentDefinitionAsync(GraphQLParser.AST.GraphQLFragmentDefinition fragmentDefinition, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitObjectTypeDefinitionAsync(GraphQLParser.AST.GraphQLObjectTypeDefinition objectTypeDefinition, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitOperationDefinitionAsync(GraphQLParser.AST.GraphQLOperationDefinition operationDefinition, TContext context) { } protected virtual System.Threading.Tasks.ValueTask VisitSelectionSetAsync(GraphQLParser.AST.GraphQLSelectionSet selectionSet, TContext context) { } ``` -------------------------------- ### Parse GraphQL source into AST nodes using Parser.Parse Source: https://context7.com/graphql-dotnet/parser/llms.txt Demonstrates how to use the generic Parser.Parse method to parse specific GraphQL definitions such as enums, object types, value literals, and directives. This approach allows for targeted parsing without requiring a full document structure. ```csharp using GraphQLParser; using GraphQLParser.AST; // Parse a specific type definition string enumText = "enum Color { RED GREEN BLUE }"; var enumDef = Parser.Parse(enumText); // Parse an object type definition string typeText = @"type User { id: ID! name: String! email: String posts: [Post!]! }"; var typeDef = Parser.Parse(typeText); // Parse a value literal string valueText = @"{ a: 1, b: ""text"", c: RED, d: $var }"; var objValue = Parser.Parse(valueText) as GraphQLObjectValue; // Parse a directive definition string directiveText = "directive @deprecated(reason: String = \"No longer supported\") on FIELD_DEFINITION | ENUM_VALUE"; var directive = Parser.Parse(directiveText); ``` -------------------------------- ### PrintContextExtensions Methods Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Extension methods for the IPrintContext interface, providing utility functions for writing content, including lines and double lines, to the associated text writer. ```csharp public static System.Threading.Tasks.ValueTask WriteAsync(this TContext context, GraphQLParser.ROM value) where TContext : GraphQLParser.Visitors.IPrintContext { } public static System.Threading.Tasks.ValueTask WriteDoubleLineAsync(this TContext context) where TContext : GraphQLParser.Visitors.IPrintContext { } public static System.Threading.Tasks.ValueTask WriteLineAsync(this TContext context) where TContext : GraphQLParser.Visitors.IPrintContext { } ``` -------------------------------- ### Parsing GraphQL to AST Source: https://github.com/graphql-dotnet/parser/blob/master/README.md The Parser converts GraphQL expressions into an Abstract Syntax Tree (AST). It also leverages ReadOnlyMemory for efficiency, though AST creation involves memory allocation. Options are available to ignore comments and/or token locations to further optimize memory usage. ```csharp var ast1 = Parser.Parse(@"{ field }"); ``` ```csharp var ast2 = Parser.Parse(@"{ field }", new ParserOptions { Ignore = IgnoreOptions.Comments }); ``` ```csharp string text1 = "enum Color { RED }" var ast1 = Parser.Parse(text1); ``` ```csharp string text2 = "{ a: 1, b: \"abc\", c: RED, d: $id }" var ast2 = Parser.Parse(text2); // returns GraphQLObjectValue ``` -------------------------------- ### Sort GraphQL AST nodes with SDLSorter Source: https://context7.com/graphql-dotnet/parser/llms.txt Demonstrates how to use SDLSorter to alphabetically organize fields and definitions within a GraphQL document. It supports in-place modification of the AST and custom string comparison options. ```csharp using GraphQLParser; using GraphQLParser.Visitors; var document = Parser.Parse(@"type User { zipCode: String address: String name: String! email: String id: ID! } query getUsers { zebra apple banana }"); SDLSorter.Sort(document); var printer = new SDLPrinter(); Console.WriteLine(printer.Print(document)); var caseSensitiveOptions = new SDLSorterOptions(StringComparison.Ordinal); var doc2 = Parser.Parse(@"type Query { Zebra: String, alpha: String, Beta: String }"); SDLSorter.Sort(doc2, caseSensitiveOptions); Console.WriteLine(printer.Print(doc2)); ``` -------------------------------- ### Configure SDL Printer Options Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Defines the configuration settings for the SDL printer, including indentation size and formatting preferences for directives and union members. These options control how the generated SDL output is structured. ```csharp var options = new GraphQLParser.Visitors.SDLPrinterOptions { IndentSize = 2, PrintComments = true, PrintDescriptions = true, ArgumentsPrintMode = GraphQLParser.Visitors.SDLPrinterArgumentsMode.PreferNewLine }; ``` -------------------------------- ### StructurePrinter for GraphQL AST Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt A visitor that prints the structure of a GraphQL Abstract Syntax Tree to a TextWriter. It supports configurable options for indentation, printing locations, and names. ```csharp public class StructurePrinter : GraphQLParser.Visitors.StructurePrinter { public StructurePrinter() { } public StructurePrinter(GraphQLParser.Visitors.StructurePrinterOptions options) { } public virtual System.Threading.Tasks.ValueTask PrintAsync(GraphQLParser.AST.ASTNode node, System.IO.TextWriter writer, System.Threading.CancellationToken cancellationToken = default) { } } ``` -------------------------------- ### Handle zero-allocation strings with ROM Source: https://context7.com/graphql-dotnet/parser/llms.txt Shows the usage of the ROM struct, a wrapper around ReadOnlyMemory that facilitates zero-allocation string handling, slicing, and comparisons. ```csharp using GraphQLParser; ROM rom1 = "hello world"; ReadOnlySpan span = rom1.Span; ROM sliced = rom1.Slice(6); Console.WriteLine($"Equal: {rom1 == "hello world"}"); string str = (string)rom1; var doc = Parser.Parse("query { field }"); ROM source = doc.Source; ``` -------------------------------- ### SDLPrinter Class Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt A concrete implementation of SDLPrinter that uses a default print context. This class is designed for printing the Schema Definition Language (SDL) representation of a GraphQL schema. ```csharp public class SDLPrinter : GraphQLParser.Visitors.SDLPrinter { public SDLPrinter() { } ``` -------------------------------- ### Implement GraphQL Parser Exceptions Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Custom exception classes used to handle syntax errors and depth limitations during the parsing process. These exceptions provide context regarding the source location where the error occurred. ```csharp public class GraphQLParserException : System.Exception { public GraphQLParserException(string description, GraphQLParser.ROM source, int location) { } public string Description { get; } public GraphQLParser.Location Location { get; } } public class GraphQLSyntaxErrorException : GraphQLParserException { public GraphQLSyntaxErrorException(string description, GraphQLParser.ROM source, int location) : base(description, source, location) { } } public class GraphQLMaxDepthExceededException : GraphQLParserException { public GraphQLMaxDepthExceededException(GraphQLParser.ROM source, int location) : base("Max depth exceeded", source, location) { } ``` -------------------------------- ### NullVisitorContext Implementation Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt A minimal implementation of IASTVisitorContext that provides a read-only CancellationToken. Useful in scenarios where no context-specific information is needed. ```csharp public struct NullVisitorContext : GraphQLParser.Visitors.IASTVisitorContext { public System.Threading.CancellationToken CancellationToken { get; } ``` -------------------------------- ### Exception Handling Source: https://context7.com/graphql-dotnet/parser/llms.txt Guidelines for handling syntax errors and depth limit violations during query parsing. ```APIDOC ## Exception Handling ### Description Details on how to catch and process errors thrown by the parser, specifically syntax errors and depth limit violations. ### Exceptions - **GraphQLSyntaxErrorException**: Thrown when the query string is malformed. - **GraphQLMaxDepthExceededException**: Thrown when the AST depth exceeds the configured limit. ### Error Response Structure - **Message** (string) - Human-readable error description. - **Line** (int) - Line number where the error occurred. - **Column** (int) - Column index where the error occurred. ### Implementation Example try { var doc = Parser.Parse(query, new ParserOptions { MaxDepth = 50 }); } catch (GraphQLMaxDepthExceededException ex) { Console.WriteLine($"Depth Error: {ex.Message}"); } ``` -------------------------------- ### GraphQL AST Node Extension Methods Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Provides extension methods for GraphQL AST nodes to facilitate common operations. These include counting nested elements, finding specific nodes by name, calculating depth, and retrieving operation definitions. These methods enhance the usability of the AST. ```csharp public static class ASTNodeExtensions { public static int AllNestedCount(this GraphQLParser.AST.ASTNode node) { } public static TNode? Find(this GraphQLParser.AST.ASTListNode node, GraphQLParser.ROM name) where TNode : class, GraphQLParser.AST.INamedNode { } public static GraphQLParser.AST.GraphQLFragmentDefinition? FindFragmentDefinition(this GraphQLParser.AST.GraphQLDocument document, GraphQLParser.ROM name) { } public static int FragmentsCount(this GraphQLParser.AST.GraphQLDocument document) { } public static GraphQLParser.AST.DirectiveLocation GetDirectiveLocation(this GraphQLParser.AST.ASTNode node) { } public static int MaxNestedDepth(this GraphQLParser.AST.ASTNode node) { } public static GraphQLParser.AST.GraphQLOperationDefinition? OperationWithName(this GraphQLParser.AST.GraphQLDocument document, GraphQLParser.ROM operationName) { } public static int OperationsCount(this GraphQLParser.AST.GraphQLDocument document) { } ``` -------------------------------- ### IMaxDepthContext Interface Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Extends IASTVisitorContext to provide properties for tracking the maximum depth of the AST and a stack for managing parent nodes during traversal. ```csharp public interface IMaxDepthContext : GraphQLParser.Visitors.IASTVisitorContext { int MaxDepth { get; set; } System.Collections.Generic.Stack Parents { get; } ``` -------------------------------- ### GraphQL AST Node Definitions Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Overview of the core AST node structures used to represent GraphQL syntax elements. ```APIDOC ## GraphQL AST Node Structure ### Description The GraphQL-DotNet parser uses a set of strongly-typed classes to represent the AST of a GraphQL document. Each class inherits from ASTNode and provides specific properties for GraphQL elements like Arguments, Directives, and Type Definitions. ### Key Classes - **GraphQLAlias**: Represents a field alias in a query. - **GraphQLArgument**: Represents a key-value pair passed to a field or directive. - **GraphQLDirective**: Represents a directive applied to a node. - **GraphQLDocument**: The root node containing a list of definitions. ### Parameters #### Common Properties - **Kind** (ASTNodeKind) - Required - The type of AST node. - **Name** (GraphQLName) - Required (for named nodes) - The identifier of the node. ### Response Example { "Kind": "Document", "Definitions": [ { "Kind": "ObjectTypeDefinition", "Name": { "Value": "Query" } } ] } ``` -------------------------------- ### StructurePrinterOptions Configuration Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Options to configure the behavior of the StructurePrinter, such as indentation size and whether to print source locations and node names. ```csharp public class StructurePrinterOptions { public StructurePrinterOptions() { } public int IndentSize { get; set; } public bool PrintLocations { get; set; } public bool PrintNames { get; set; } } ``` -------------------------------- ### GraphQL Executable Definitions Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Defines the base AST node for executable definitions in GraphQL, such as queries, mutations, and subscriptions. ```APIDOC ## GraphQL Executable Definitions ### Description This section details the base AST node for executable definitions in GraphQL, which include operations like queries, mutations, and subscriptions. ### AST Node #### `GraphQLExecutableDefinition` (Abstract) Abstract base class for all executable definitions. - **`SelectionSet`** (GraphQLParser.AST.GraphQLSelectionSet) - Required - The selection set defining the fields to be retrieved or modified. - **`Directives`** (GraphQLParser.AST.GraphQLDirectives?) - Optional - Directives applied to the executable definition. ``` -------------------------------- ### Define Base AST Node Classes Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Defines the foundational ASTNode and ASTListNode classes. These classes provide the structure for all nodes in the GraphQL document tree, including support for comments, locations, and list-based node collections. ```csharp public abstract class ASTNode { protected ASTNode() { } public abstract GraphQLParser.AST.ASTNodeKind Kind { get; } public virtual System.Collections.Generic.List? Comments { get; set; } public virtual GraphQLParser.AST.GraphQLLocation Location { get; set; } } public abstract class ASTListNode : GraphQLParser.AST.ASTNode, System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.Generic.IReadOnlyList, System.Collections.IEnumerable { protected ASTListNode(System.Collections.Generic.List items) { } public int Count { get; } public TNode this[int index] { get; } public System.Collections.Generic.List Items { get; set; } public System.Collections.Generic.IEnumerator GetEnumerator() { } } ``` -------------------------------- ### Visualize AST Hierarchy with StructurePrinter Source: https://github.com/graphql-dotnet/parser/blob/master/README.md The StructurePrinter visitor traverses a GraphQL AST and outputs a hierarchical representation of node types to a TextWriter. This is primarily used for debugging and understanding the internal structure of parsed GraphQL documents. ```csharp public static async Task PrintStructure(string sdl) { var document = Parser.Parse(sdl); using var writer = new StringWriter(); var printer = new StructurePrinter(); await printer.PrintAsync(document, writer); var rendered = writer.ToString(); Console.WriteLine(rendered); } ``` -------------------------------- ### Visitor Context Interfaces Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Defines the contracts for visitor contexts, including ICountContext, IMaxDepthContext, and IPrintContext. ```APIDOC ## Visitor Context Interfaces ### Description Context interfaces define the state available to visitors during traversal. ### Key Interfaces - **ICountContext**: Tracks node counts and filtering logic. - **IMaxDepthContext**: Tracks the depth of the AST traversal using a stack of parents. - **IPrintContext**: Manages state for printing SDL, including indentation and text writing. ### Implementation - **DefaultCountContext**: Implements ICountContext. - **DefaultMaxDepthContext**: Implements IMaxDepthContext. ``` -------------------------------- ### Handle GraphQL Parsing Exceptions Source: https://context7.com/graphql-dotnet/parser/llms.txt Provides patterns for catching and reporting GraphQLSyntaxErrorException and GraphQLMaxDepthExceededException. Includes a safe parsing wrapper to handle errors gracefully. ```csharp public static (GraphQLDocument? Document, string? Error) SafeParse(string query) { try { var doc = Parser.Parse(query, new ParserOptions { MaxDepth = 100 }); return (doc, null); } catch (GraphQLSyntaxErrorException ex) { return (null, $"Syntax error at line {ex.Line}, column {ex.Column}: {ex.Description}"); } catch (GraphQLMaxDepthExceededException ex) { return (null, $"Query too complex: {ex.Message}"); } } ``` -------------------------------- ### Lexing GraphQL Input to Tokens Source: https://github.com/graphql-dotnet/parser/blob/master/README.md The Lexer generates tokens from input GraphQL text. It is optimized to minimize memory allocation by utilizing ReadOnlyMemory. The Lex method returns the first token found in the input string. ```csharp var token = Lexer.Lex("\"str\""); ``` -------------------------------- ### GraphQL Fragment Definitions Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Defines the AST node for GraphQL fragment definitions. ```APIDOC ## GraphQL Fragment Definitions ### Description This section describes the Abstract Syntax Tree (AST) node for defining GraphQL fragments. ### AST Node #### `GraphQLFragmentDefinition` Represents a named fragment definition. - **`Name`** (GraphQLParser.AST.GraphQLFragmentName) - Required - The name of the fragment. - **`TypeCondition`** (GraphQLParser.AST.GraphQLTypeCondition) - Required - The type condition for the fragment. - **`SelectionSet`** (GraphQLParser.AST.GraphQLSelectionSet) - Required - The selection set defining the fields included in the fragment. - **`Directives`** (GraphQLParser.AST.GraphQLDirectives?) - Optional - Directives applied to the fragment definition. ``` -------------------------------- ### GraphQL Arguments Definition List Node Source: https://github.com/graphql-dotnet/parser/blob/master/src/GraphQLParser.ApiTests/GraphQLParser.approved.txt Represents a list of argument definitions for a field or directive. It inherits from ASTListNode. ```csharp public class GraphQLArgumentsDefinition : GraphQLParser.AST.ASTListNode { public GraphQLArgumentsDefinition(System.Collections.Generic.List items) { } public override GraphQLParser.AST.ASTNodeKind Kind { get; } } ```