Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
feat: new AddApolloFederationV2 that accepts target version (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszkuc authored Oct 19, 2023
1 parent 57d1a0e commit 59f22df
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ public static IRequestExecutorBuilder AddApolloFederationV2(
return builder.ConfigureSchema(s => ApolloFederationSchemaBuilderExtensionsV2.AddApolloFederationV2(s));
}

/// <summary>
/// Adds support for Apollo Federation V2 to the schema.
/// </summary>
/// <param name="builder">
/// The <see cref="IRequestExecutorBuilder"/>.
/// </param>
/// <param name="version">
/// Target Federation version
/// </param
/// <returns>
/// Returns the <see cref="IRequestExecutorBuilder"/>.
/// </returns>
/// <exception cref="ArgumentNullException">
/// The <paramref name="builder"/> is <c>null</c>.
/// </exception>
public static IRequestExecutorBuilder AddApolloFederationV2(
this IRequestExecutorBuilder builder,
FederationVersion version)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.ConfigureSchema(s => ApolloFederationSchemaBuilderExtensionsV2.AddApolloFederationV2(s, version));
}

/// <summary>
/// Adds support for Apollo Federation V2 to the schema.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions Federation/Extensions/ApolloFederationSchemaBuilderExtensionsV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ public static ISchemaBuilder AddApolloFederationV2(this ISchemaBuilder builder)
return AddApolloFederationV2(builder, new FederatedSchema());
}

/// <summary>
/// Adds support for Apollo Federation to the schema.
/// </summary>
/// <param name="builder">
/// The <see cref="ISchemaBuilder"/>.
/// </param>
/// <returns>
/// Returns the <see cref="ISchemaBuilder"/>.
/// </returns>
/// <param name="version">
/// Target Federation version
/// </param>
/// <exception cref="ArgumentNullException">
/// The <paramref name="builder"/> is <c>null</c>.
/// </exception>
public static ISchemaBuilder AddApolloFederationV2(this ISchemaBuilder builder, FederationVersion version)
{
return AddApolloFederationV2(builder, new FederatedSchema(version));
}

/// <summary>
/// Adds support for Apollo Federation to the schema.
/// </summary>
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,17 @@ dotnet run -- schema export --output schema.graphql
#### Specifying Federation Version

By default, `ApolloGraphQL.HotChocolate.Federation` will generate schema using latest supported Federation version. If you would like to opt-in to use older versions you can
so by specifying the version on your custom schema object and passing it to the `AddApolloFederationV2` extension.
so by specifying the version when configuring `AddApolloFederationV2` extension.

```csharp
builder.Services
.AddGraphQLServer()
.AddApolloFederationV2(FederationVersion.FEDERATION_23)
// register your types and services
;
```

Alternatively you can also provide custom `FederatedSchema` that targets specific Federation version

```csharp
public class CustomSchema : FederatedSchema
Expand All @@ -234,17 +244,11 @@ public class CustomSchema : FederatedSchema
}
}

var builder = WebApplication.CreateBuilder(args);

builder.Services
.AddGraphQLServer()
.AddApolloFederationV2(new CustomSchema())
// register your types and services
;

var app = builder.Build();
app.MapGraphQL();
app.Run();
```

#### `@composedDirective` usage
Expand Down

0 comments on commit 59f22df

Please sign in to comment.