GraphQL .NET 服务器项目教程
serverASP.NET Core GraphQL Server项目地址:https://gitcode.com/gh_mirrors/server16/server
1. 项目的目录结构及介绍
GraphQL .NET 服务器项目的目录结构如下:
/src
├── /GraphQL.Server.Transports.AspNetCore
├── /GraphQL.Server.Transports.WebSockets
├── /GraphQL.Server.Ui.Altair
├── /GraphQL.Server.Ui.GraphiQL
├── /GraphQL.Server.Ui.Playground
├── /GraphQL.Server.Authorization.AspNetCore
├── /GraphQL.Server.Common
├── /GraphQL.Server.Internal
├── /GraphQL.Server.Transports.AspNetCore.NewtonsoftJson
├── /GraphQL.Server.Transports.AspNetCore.SystemTextJson
├── /GraphQL.Server.Transports.Subscriptions.Abstractions
├── /GraphQL.Server.Transports.Subscriptions.WebSockets
├── /GraphQL.Server.Transports.WebSockets.Common
├── /GraphQL.Server.Ui.Voyager
/samples
├── /Samples.Server
├── /Samples.Server.Authorization
├── /Samples.Server.Core
├── /Samples.Server.NoAuthorization
├── /Samples.Server.SystemTextJson
/test
├── /GraphQL.Server.Tests
├── /GraphQL.Server.Ui.Tests
├── /GraphQL.Server.Transports.WebSockets.Tests
├── /GraphQL.Server.Transports.Subscriptions.WebSockets.Tests
├── /GraphQL.Server.Transports.AspNetCore.NewtonsoftJson.Tests
├── /GraphQL.Server.Transports.AspNetCore.SystemTextJson.Tests
目录结构介绍
-
/src
:包含项目的核心源代码。GraphQL.Server.Transports.AspNetCore
:提供 ASP.NET Core 传输支持。GraphQL.Server.Transports.WebSockets
:提供 WebSocket 传输支持。GraphQL.Server.Ui.Altair
、GraphQL.Server.Ui.GraphiQL
、GraphQL.Server.Ui.Playground
、GraphQL.Server.Ui.Voyager
:提供不同的 GraphQL 用户界面。GraphQL.Server.Authorization.AspNetCore
:提供 ASP.NET Core 授权支持。GraphQL.Server.Common
、GraphQL.Server.Internal
:包含通用和内部辅助类。GraphQL.Server.Transports.AspNetCore.NewtonsoftJson
、GraphQL.Server.Transports.AspNetCore.SystemTextJson
:提供不同的 JSON 序列化支持。GraphQL.Server.Transports.Subscriptions.Abstractions
、GraphQL.Server.Transports.Subscriptions.WebSockets
:提供订阅抽象和 WebSocket 订阅支持。GraphQL.Server.Transports.WebSockets.Common
:包含 WebSocket 通用辅助类。
-
/samples
:包含示例项目,展示如何使用 GraphQL .NET 服务器。Samples.Server
、Samples.Server.Authorization
、Samples.Server.Core
、Samples.Server.NoAuthorization
、Samples.Server.SystemTextJson
:不同的示例项目。
-
/test
:包含项目的测试代码。GraphQL.Server.Tests
、GraphQL.Server.Ui.Tests
、GraphQL.Server.Transports.WebSockets.Tests
、GraphQL.Server.Transports.Subscriptions.WebSockets.Tests
、GraphQL.Server.Transports.AspNetCore.NewtonsoftJson.Tests
、GraphQL.Server.Transports.AspNetCore.SystemTextJson.Tests
:不同的测试项目。
2. 项目的启动文件介绍
项目的启动文件通常位于示例项目的 Program.cs
和 Startup.cs
文件中。
Program.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace Samples.Server
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(web
serverASP.NET Core GraphQL Server项目地址:https://gitcode.com/gh_mirrors/server16/server