NpgsqlGraphQL 0.0.1-preview

This is a prerelease version of NpgsqlGraphQL.
dotnet add package NpgsqlGraphQL --version 0.0.1-preview
                    
NuGet\Install-Package NpgsqlGraphQL -Version 0.0.1-preview
                    
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="NpgsqlGraphQL" Version="0.0.1-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NpgsqlGraphQL" Version="0.0.1-preview" />
                    
Directory.Packages.props
<PackageReference Include="NpgsqlGraphQL" />
                    
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 NpgsqlGraphQL --version 0.0.1-preview
                    
#r "nuget: NpgsqlGraphQL, 0.0.1-preview"
                    
#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 NpgsqlGraphQL@0.0.1-preview
                    
#: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=NpgsqlGraphQL&version=0.0.1-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=NpgsqlGraphQL&version=0.0.1-preview&prerelease
                    
Install as a Cake Tool

NpgsqlGraphQL

Tiny .NET client and GraphQL.NET transport adapter experiment for PostgreSQL's pg_graphql extension.

This package does not implement a GraphQL schema generator or EF Core provider. PostgreSQL's pg_graphql extension owns schema reflection and execution. This library only calls graphql.resolve(...) through Npgsql and plugs that execution into GraphQL.NET's ASP.NET Core transport.

Usage

await using var client = new NpgsqlGraphqlClient(connectionString);

await client.EnsureExtensionAsync();

var json = await client.ResolveAsync(
    """
    query Blogs($first: Int!) {
      blogCollection(first: $first) {
        edges {
          node {
            id
            title
          }
        }
      }
    }
    """,
    new { first = 10 });

ASP.NET Core

using Npgsql.GraphQL;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddNpgsqlGraphQL(
    "Host=localhost;Port=5432;Database=postgres;Username=pgAdmin;Password=123456");

var app = builder.Build();

app.MapNpgsqlGraphQL("/graphql");

app.Run();

With PostgreSQL session settings for RLS or multi-tenancy:

builder.Services.AddNpgsqlGraphQL(options =>
{
    options.ConnectionString = builder.Configuration.GetConnectionString("Postgres");
    options.SetSessionSetting("app.source", "graphql");
    options.MapClaimToSessionSetting("app.user_id", "sub");
});

app.MapNpgsqlGraphQL("/graphql", options =>
{
    options.CsrfProtectionEnabled = false;
});

Request:

POST /graphql
Content-Type: application/json

{
  "query": "query { blogCollection(first: 10) { edges { node { id title } } } }"
}

Frontend clients

The endpoint is a normal GraphQL HTTP endpoint, so frontend applications can use standard clients:

  • React: Apollo Client, urql, Relay, or plain fetch.
  • Vue: Vue Apollo or any framework-agnostic GraphQL client.
  • TypeScript: GraphQL Code Generator can generate typed operations from schema/query documents.

The frontend still writes GraphQL operations, but they are usually colocated in .graphql files or gql tags and can be type-generated instead of hand-parsed.

Notes

  • Requires PostgreSQL with the pg_graphql extension installed.
  • EnsureExtensionAsync runs create extension if not exists pg_graphql;.
  • Query execution is delegated to graphql.resolve.
  • The ASP.NET Core endpoint uses GraphQL.NET's HTTP transport and serializers.
  • NpgsqlGraphqlDocumentExecuter implements GraphQL.NET's IDocumentExecuter<ISchema> and delegates execution to PostgreSQL.
  • No .NET GraphQL schema is required; the ExecutionOptions.Schema value is ignored because schema reflection lives in PostgreSQL.
  • PostgreSQL session settings are applied inside a transaction with set_config(..., true).
  • PostgreSQL GraphQL error extensions.code is mapped to GraphQL.NET's ExecutionError.Code.
  • When GraphQL.NET enables execution metrics, the response includes an extensions.npgsql.durationMs value.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1-preview 70 5/29/2026