VOOZH about

URL: https://www.nuget.org/packages/graphql-parser/

⇱ NuGet Gallery | GraphQL-Parser 9.5.1




👁 Image
GraphQL-Parser 9.5.1

dotnet add package GraphQL-Parser --version 9.5.1
 
 
NuGet\Install-Package GraphQL-Parser -Version 9.5.1
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GraphQL-Parser" Version="9.5.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GraphQL-Parser" Version="9.5.1" />
 
Directory.Packages.props
<PackageReference Include="GraphQL-Parser" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GraphQL-Parser --version 9.5.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GraphQL-Parser, 9.5.1"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GraphQL-Parser@9.5.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GraphQL-Parser&version=9.5.1
 
Install as a Cake Addin
#tool nuget:?package=GraphQL-Parser&version=9.5.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

GraphQL.NET Parser

👁 codecov
👁 Nuget
👁 Nuget
👁 GitHub Release Date
👁 GitHub commits since latest release (by date)
👁 GitHub contributors
👁 Size

This library contains a lexer and parser as well as the complete GraphQL AST model that allows you to work with GraphQL documents compatible with the October 2021 spec.

The parser from this library is used by the GraphQL.NET project and was verified by many test data sets.

Preview versions of this package are available on GitHub Packages.

1. Lexer

Generates token based on input text. Lexer takes advantage of ReadOnlyMemory<char> and in most cases does not allocate memory on the managed heap at all.

Usage:

var token = Lexer.Lex("\"str\"");

Lex method always returns the first token it finds. In this case the result would look like following.

2. Parser

Parses provided GraphQL expression into AST (abstract syntax tree). Parser also takes advantage of ReadOnlyMemory<char> but still allocates memory for AST.

Usage:

var ast1 = Parser.Parse(@"
{
 field
}");

var ast2 = Parser.Parse(@"
{
 field
}", new ParserOptions { Ignore = IgnoreOptions.Comments });

By default ParserOptions.Ignore is IgnoreOptions.None. If you want to ignore all comments use IgnoreOptions.Comments. If you don't need information about tokens locations in the source document, then use flag IgnoreOptions.Locations. Or just use IgnoreOptions.All and this will maximize the saving of memory allocated in the managed heap for AST.

You can parse not only entire GraphQLDocument but also concrete AST nodes. Use generic overload.

string text1 = "enum Color { RED }"
var ast1 = Parser.Parse<GraphQLEnumTypeDefinition>(text1);

string text2 = "{ a: 1, b: \"abc\", c: RED, d: $id }";
var ast2 = Parser.Parse<GraphQLValue>(text2); // returns GraphQLObjectValue

3. ASTVisitor

ASTVisitor provides API to traverse AST of the parsed GraphQL document. Default implementation traverses all AST nodes of the provided one. You can inherit from it and override desired methods to implement your own AST processing algorithm.

SDLPrinter

For printing SDL from AST, you can use SDLPrinter. This is a highly optimized visitor for asynchronous non-blocking SDL output into provided TextWriter. In the majority of cases it does not allocate memory in the managed heap at all. Extension methods are also provided for printing directly to a string, which utilize the StringBuilder and StringWriter classes.

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();

Output:

query {
 hero {
 name
 age
 }
}

SDLSorter

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 futher customization is possible by deriving from SDLSorterOptions and overriding the Compare methods.

var document = Parser.Parse("query { hero { name age } }");
SDLSorter.Sort(document);
var sdl = new SDLPrinter().Print(document);

Output:

query {
 hero {
 age
 name
 }
}

StructurePrinter

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. Consider the following GraphQL document:

query a { name age }

After StructurePrinter processing the output text will be

Document
 OperationDefinition
 Name [a]
 SelectionSet
 Field
 Name [name]
 Field
 Name [age]

Usage:

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);
}

Contributors

This project exists thanks to all the people who contribute. <a href="https://github.com/graphql-dotnet/parser/graphs/contributors"><img src="https://contributors-img.web.app/image?repo=graphql-dotnet/parser" /></a>

PRs are welcome! Looking for something to work on? The list of open issues is a great place to start. You can help the project by simply responding to some of the asked questions.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (31)

Showing the top 5 NuGet packages that depend on GraphQL-Parser:

Package Downloads
GraphQL

GraphQL for .NET

HQ

This package contains the full-stack build for HQ.io.

CoreSharp.GraphQL

GraphQL CQRS integration and extension

SER.Graphql.Reflection.NetCore

This is a complement to graphql-dotnet (https://github.com/graphql-dotnet/graphql-dotnet) to avoid boilerplate

GraphQL.IntrospectionModel

Types for GraphQL introspection model and building SDL

GitHub repositories (9)

Showing the top 9 popular GitHub repositories that depend on GraphQL-Parser:

Repository Stars
graphql-dotnet/graphql-dotnet
GraphQL for .NET
nozzlegear/ShopifySharp
ShopifySharp is a .NET library that helps developers easily authenticate with and manage Shopify stores using Shopify's GraphQL API.
byme8/ZeroQL
C# GraphQL client with Linq-like syntax
graphql-dotnet/examples
Examples for GraphQL.NET
formcms/formcms
AI Agent: Open-source headless CMS built with ASP.NET Core (C#) and React, featuring REST APIs, GraphQL, and a GrapesJS page designer.
friflo/Friflo.Json.Fliox
C# ORM - High Performance, SQL, NoSQL, Messaging, Pub-Sub
nnecrkvenuOX/formcms
AI Agent: Open-source headless CMS built with ASP.NET Core (C#) and React, featuring REST APIs, GraphQL, and a GrapesJS page designer.
nightroman/FarNet
Far Manager framework for .NET modules and scripts in PowerShell, F#, JavaScript.
MoienTajik/GraphQL.Tools
GraphQL.Tools is a GraphQL to C# compiler (code-generator) which turns your GraphQL schema into a set of C# classes, interfaces, and enums.
Version Downloads Last Updated
9.5.1 126,246 2/2/2026
9.5.0 18,210,211 8/20/2024
9.4.0 35,921 8/18/2024
9.3.1 357,441 12/11/2023
9.3.0 118,740 10/16/2023
9.2.1 32,738 10/12/2023
9.2.0 4,651,987 7/26/2023
9.1.0 84,000 4/21/2023
9.0.2 23,452 4/21/2023
9.0.1 23,220 4/20/2023
9.0.0 23,277 4/20/2023
8.4.2 2,903,925 12/11/2023
8.4.1 25,225 10/12/2023
8.4.0 1,178,061 7/26/2023
8.3.0 12,137,902 4/21/2023
8.2.0 27,978 4/15/2023
8.1.0 2,704,972 8/15/2022
8.0.0 5,543,705 3/30/2022
7.2.0 9,916,299 7/7/2021
7.1.0 1,697,428 4/7/2021
Loading failed