You can see the full code in practice in thesocialnetwork
example on GitHub.
AuthExchange
. You provide a function that returns a token and it applies that token to a given header to make an authenticated request.
It’s important that AuthExchange
comes before FetchExchange
, WebSocketExchange
or any other exchange that transmits the data.
getToken
function is not asynchronous, we recommend that you first load the token from storage and store it as a statically available variable.
You can find the full example in thesocialnetwork
example on GitHub.
ExtensionsExchange
lets you add custom values to the extension
field of a GraphQL query. Adding a custom authentication property to query extensions can be useful when you can’t access request headers on the server (e.g. when using subscriptions).
ExtensionsExchange
lets you specify a function that should be synchronously called for each request. The function should either return nil
value when there are no extensions or an AnyCodable
value containing additional request information.