From c181a0cbaf2e82d2edd9cace540bac5e63d9ccd5 Mon Sep 17 00:00:00 2001 From: Tassilo Singhammer Date: Sun, 7 Jan 2024 17:04:57 +0100 Subject: [PATCH] Adds example with positional record --- .../v12/api-reference/apollo-federation.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/website/src/docs/hotchocolate/v12/api-reference/apollo-federation.md b/website/src/docs/hotchocolate/v12/api-reference/apollo-federation.md index e29b8d4c68f..9654e2f6bb1 100644 --- a/website/src/docs/hotchocolate/v12/api-reference/apollo-federation.md +++ b/website/src/docs/hotchocolate/v12/api-reference/apollo-federation.md @@ -709,3 +709,23 @@ query { } } ``` + +## C# Records +Records can be decorated almost in the same way as classes to add Apollo Federation support. +The above Product example as a positional record would look like this: + +```csharp +public record Product([property: ID][property: Key] string Id, string Name, float Price) +{ + [ReferenceResolver] + public static async Task ResolveReference( + // Represents the value that would be in the Id property of a Product + string id, + // Example of a service that can resolve the Products + ProductBatchDataLoader dataLoader + ) + { + return await dataloader.LoadAsync(id); + } +} +```