Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
title: "Authentication and Authorization"
---

# Authentication and Authorization

The mental model for auth in Fusion is straightforward: **authentication terminates at the gateway, authorization is a subgraph concern.**

The gateway validates tokens, extracts identity, and forwards the relevant information to subgraphs via HTTP headers. Each subgraph then enforces access control on its own fields using its own authorization framework.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ In stitching, your remote schemas are HotChocolate servers that may or may not p
// Products service - Program.cs
var builder = WebApplication.CreateBuilder(args);

builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddQueryType<ProductQueries>();

var app = builder.Build();
Expand Down Expand Up @@ -146,7 +146,7 @@ public static partial class ProductQueries

Key changes:

- **`builder.AddGraphQL("products-api")`** replaces `builder.Services.AddGraphQLServer()`. The string argument is the subgraph name used during composition.
- **`builder.AddGraphQL("products-api")`** replaces `builder.AddGraphQL()`. The string argument is the subgraph name used during composition.
- **`.AddProductTypes()`** is generated by the `HotChocolate.Types.Analyzers` package. It registers all types marked with `[QueryType]`, `[ObjectType<T>]`, etc.
- **`.ExportSchemaOnStartup()`** exports the subgraph's schema as a `.graphqls` file when the server starts (used for composition).
- **`app.RunWithGraphQLCommands(args)`** enables CLI commands like `dotnet run -- schema export`.
Expand Down Expand Up @@ -286,8 +286,8 @@ builder.Services
.AddHttpClient("inventory", c =>
c.BaseAddress = new Uri("http://localhost:5200/graphql"));

builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddRemoteSchema("products")
.AddRemoteSchema("inventory")
.AddTypeExtensionsFromFile("./Stitching.graphql");
Expand Down
2 changes: 1 addition & 1 deletion website/src/docs/fusion/v16/request-limits.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ builder
The maximum HTTP request body size defaults to approximately 20 MB:

```csharp
services.AddGraphQLGatewayServer(maxAllowedRequestSize: 5 * 1000 * 1024); // 5 MB
builder.AddGraphQLGateway(maxAllowedRequestSize: 5 * 1000 * 1024); // 5 MB
```

### Server Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Install the `HotChocolate.ApolloFederation` package:
Register the Apollo Federation services:

```csharp
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddApolloFederation();
```

Expand Down Expand Up @@ -239,8 +239,8 @@ Register the type in the GraphQL schema:
<Implementation>

```csharp
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddApolloFederation()
.AddType<Product>();
```
Expand All @@ -250,8 +250,8 @@ builder.Services
<Code>

```csharp
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddApolloFederation()
.AddType<ProductType>();
```
Expand Down Expand Up @@ -300,8 +300,8 @@ public class Product
public string Id { get; set; }
}

builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddApolloFederation()
.AddType<Product>();
```
Expand All @@ -321,8 +321,8 @@ public class ProductType : ObjectType<Product>
}
}

builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddApolloFederation()
.AddType<ProductType>();
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,16 @@ public class CustomFilteringConvention : FilterConvention
}
}

builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddFiltering<CustomFilteringConvention>();
```

You can also use convention and provider extensions instead of creating a custom `FilterConvention`:

```csharp
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddFiltering()
.AddConvention<IFilterConvention>(
new FilterConventionExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class MyDirectiveType : DirectiveType

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddDirectiveType<MyDirectiveType>();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ If you do not want XML comments to appear in the schema:

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.ModifyOptions(opt => opt.UseXmlDocumentation = false);
```

Expand Down Expand Up @@ -186,8 +186,8 @@ public class CustomNamingConventions : DefaultNamingConventions
// Program.cs
IReadOnlySchemaOptions capturedSchemaOptions;

builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.ModifyOptions(opt => capturedSchemaOptions = opt)
.AddConvention<INamingConventions>(sp =>
new CustomNamingConventions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ When you fire the `TypesChanged` event, Hot Chocolate phases out the old schema

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTypeModule<MyTypeModule>();
```

Expand Down Expand Up @@ -211,8 +211,8 @@ mutationDef.Fields.Add(createProductField);

var mutationType = ObjectType.CreateUnsafe(mutationDef);

builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddQueryType()
.AddMutationType(mutationType)
.AddType(productInputType)
Expand Down
4 changes: 2 additions & 2 deletions website/src/docs/hotchocolate/v16/building-a-schema/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Code-first enum types are not automatically inferred because multiple `EnumType<

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddType<UserRoleType>();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static partial class BookExtensions

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTypeExtension<BookExtensions>();
```

Expand Down Expand Up @@ -65,8 +65,8 @@ public class BookTypeExtensions : ObjectTypeExtension<Book>

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTypeExtension<BookTypeExtensions>();
```

Expand Down Expand Up @@ -98,8 +98,8 @@ public class BookQueries

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTypeExtension<BookQueries>();
```

Expand All @@ -125,8 +125,8 @@ public class QueryBookResolvers : ObjectTypeExtension<Query>

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTypeExtension<QueryBookResolvers>();
```

Expand All @@ -151,8 +151,8 @@ public class BookExtensions

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTypeExtension<BookExtensions>();
```

Expand All @@ -172,8 +172,8 @@ public class BookTypeExtensions : ObjectTypeExtension<Book>

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTypeExtension<BookTypeExtensions>();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static partial class MessageQueries

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddType<TextMessage>();
```

Expand Down Expand Up @@ -136,8 +136,8 @@ public class TextMessageType : ObjectType<TextMessage>

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddQueryType<QueryType>()
.AddType<TextMessageType>();
```
Expand Down Expand Up @@ -272,8 +272,8 @@ public class TextMessage : IDatedMessage

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddType<IDatedMessage>()
.AddType<TextMessage>();
```
Expand Down Expand Up @@ -306,8 +306,8 @@ public class TextMessageType : ObjectType<TextMessage>

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddQueryType<QueryType>()
.AddType<DatedMessageType>()
.AddType<TextMessageType>();
Expand Down
28 changes: 14 additions & 14 deletions website/src/docs/hotchocolate/v16/building-a-schema/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public class BookMutationsType : ObjectType<BookMutations>

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddMutationType<BookMutationsType>();
```

Expand Down Expand Up @@ -137,8 +137,8 @@ Hot Chocolate generates the input and payload types for you when mutation conven

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddMutationConventions(applyToAllMutations: true);
```

Expand Down Expand Up @@ -231,8 +231,8 @@ Override the global naming patterns through `MutationConventionOptions`:

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddMutationConventions(
new MutationConventionOptions
{
Expand Down Expand Up @@ -354,8 +354,8 @@ public interface IUserError

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddErrorInterfaceType<IUserError>();
```

Expand All @@ -377,8 +377,8 @@ public class CustomErrorInterfaceType : InterfaceType

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddErrorInterfaceType<CustomErrorInterfaceType>();
```

Expand All @@ -393,16 +393,16 @@ When a request contains multiple mutations, Hot Chocolate can wrap them in a tra

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddDefaultTransactionScopeHandler();
```

To customize the transaction behavior, implement `ITransactionScopeHandler` and register it:

```csharp
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddTransactionScopeHandler<CustomTransactionScopeHandler>();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ Since multiple classes could inherit from `ObjectType<Author>` with different co

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.AddType<AuthorType>();
```

Expand Down Expand Up @@ -399,8 +399,8 @@ You can also set this globally, which affects all types.

```csharp
// Program.cs
builder.Services
.AddGraphQLServer()
builder
.AddGraphQL()
.ModifyOptions(options =>
{
options.DefaultBindingBehavior = BindingBehavior.Explicit;
Expand Down
Loading