Configure Authentication

In this section, we'll configure authentication for our API. Let's say we'd like to disable authentication by default, but enable it for all Mutation Operations. Here's how we can do that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// wundergraph.operations.ts
import { configureWunderGraphOperations } from '@wundergraph/sdk';
import type { OperationsConfiguration } from './generated/wundergraph.operations';
export default configureWunderGraphOperations<OperationsConfiguration>({
operations: {
defaultConfig: {
authentication: {
required: false,
},
},
mutations: (config) => ({
...config,
authentication: {
required: true,
},
}),
},
});

As in the other examples, we're using the default configuration as a base and add an override function for the mutations field. We'll pipe through all defaults and override the authentication field to be required for all Mutation Operations.

Previous
Defaults

Was this article helpful to you?
Provide feedback

Edit this page