Configs2026年7月13日·1 分钟阅读

GraphQL.NET — GraphQL Implementation for .NET

A mature, community-driven GraphQL implementation for .NET that provides schema definition, query execution, validation, and subscription support for building GraphQL APIs in C#.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
GraphQL.NET Overview
直接安装命令
npx -y tokrepo@latest install 2065c18d-7e95-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

GraphQL.NET is the original and most widely used GraphQL implementation for the .NET platform. It provides a complete server-side toolkit for defining schemas, executing queries, handling mutations, and supporting subscriptions — all in idiomatic C#.

What GraphQL.NET Does

  • Defines GraphQL schemas using code-first C# types or schema-first SDL strings
  • Executes queries with validation, authorization, and complexity analysis
  • Supports subscriptions for real-time data via WebSocket transports
  • Integrates with ASP.NET Core through middleware and endpoint routing
  • Handles batched queries, persisted queries, and DataLoader for N+1 prevention

Architecture Overview

GraphQL.NET follows a layered architecture: the Schema layer defines types and fields, the Document Executer parses and validates incoming queries against the schema, and Field Resolvers fetch data from underlying sources. The library uses an async-first execution model, resolving fields concurrently where possible. DataLoader batches and caches database calls within a single request.

Self-Hosting & Configuration

  • Install core packages: GraphQL, GraphQL.MicrosoftDI, and a serializer like GraphQL.SystemTextJson
  • Register schema and types in the DI container with services.AddGraphQL()
  • Map the GraphQL endpoint with app.UseGraphQL() or custom middleware
  • Configure authorization with AuthorizeWithPolicy on fields and types
  • Enable the GraphiQL or Playground IDE for interactive query testing

Key Features

  • Both code-first and schema-first definition approaches
  • Built-in query complexity and depth analysis to prevent abuse
  • DataLoader pattern for efficient batched data fetching
  • Comprehensive validation following the GraphQL specification
  • Active community with regular releases and extensive documentation

Comparison with Similar Tools

  • Hot Chocolate — Newer .NET GraphQL server with annotation-based types; GraphQL.NET has a longer track record and larger installed base
  • Hasura — Auto-generates GraphQL from Postgres; GraphQL.NET gives full control over schema and resolvers
  • Apollo Server — Node.js GraphQL server; GraphQL.NET serves the same role in the .NET ecosystem
  • Strawberry (Python) — Python GraphQL library; GraphQL.NET targets C# developers

FAQ

Q: Does GraphQL.NET support .NET 8? A: Yes, it targets .NET Standard 2.0+ and works with all modern .NET versions.

Q: How do I prevent expensive queries? A: Configure MaxDepth and MaxComplexity on the execution options to reject abusive queries.

Q: Can I use it with Entity Framework Core? A: Yes, field resolvers can call EF Core queries, and DataLoader helps batch database access.

Q: What serializers are supported? A: System.Text.Json and Newtonsoft.Json via separate NuGet packages.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产