From 5d4f0eeb38ec0e47a068e64083074b34a9ec4ea5 Mon Sep 17 00:00:00 2001 From: Shane Krueger Date: Sun, 18 Aug 2024 21:48:35 -0400 Subject: [PATCH] Add notes regarding endpoint routing (#65) --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 74844fb..6c92a52 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ sample of the application builder code: ```csharp var app = builder.Build(); app.UseDeveloperExceptionPage(); +app.UseWebSockets(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGraphQL("graphql"); @@ -120,6 +121,28 @@ app.UseEndpoints(endpoints => { await app.RunAsync(); ``` +Using endpoint routing is particularly useful when you want to select a specific +CORS configuration for the GraphQL endpoint. See the CORS section below for a sample. + +Please note that when using endpoint routing, you cannot use WebSocket connections +while a UI package is also configured at the same URL. You will need to use a +different URL for the UI package, or use UI middleware prior to endpoint routing. +So long as different URLs are used, there are no issues. Below is a sample when +the UI and GraphQL reside at the same URL: + +```csharp +var app = builder.Build(); +app.UseDeveloperExceptionPage(); +app.UseWebSockets(); +app.UseRouting(); +app.UseGraphQLVoyager("/graphql"); +app.UseEndpoints(endpoints => +{ + endpoints.MapGraphQL("/graphql"); +}); +await app.RunAsync(); +``` + ### Configuration with a MVC controller Although not recommended, you may set up a controller action to execute GraphQL