Class: Laika
Laika.Laika
Class responsible for managing interceptions.
By default a singleton is installed on globalThis
(usually window
) under laika
.
Read more in the module page or scroll down to see it's functionality.
example
laika.log.startLogging();
Constructors
constructor
• new Laika(__namedParameters?
)
Parameters
Name | Type |
---|---|
__namedParameters | Object |
__namedParameters.referenceName? | string |
Defined in
Properties
log
• log: LogApi
A set of functions that controls logging and recording of all (or selected) operations.
Read more on the LogApi page.
example
laika.log.startLogging();
Defined in
Methods
createLink
▸ createLink(onRequest?
): ApolloLink
Use this function to create an Apollo Link that uses this Laika instance. Useful in unit tests.
Parameters
Name | Type |
---|---|
onRequest? | (operation : Operation , forward : NextLink ) => void |
Returns
ApolloLink
Defined in
intercept
▸ intercept(matcher?
, connectFutureLinksOrMitmFn?
, keepNonSubscriptionConnectionsOpen?
): InterceptApi
Provides functionality to intercept, and optionally mock or modify each operation's subscription.
The API returned is heavily inspired on jest's mocking functionality (jest.fn()
)
and is described in length here: InterceptApi.
Every interceptor you create should be as specific as needed in a given session. At the very least, ensure the order of creating interceptors is from most specific, to least specific.
This is because any operations that are executed by your client will end up being intercepted by the first interceptor that matches the constraints of the Matcher.
See Pitfalls for more information.
example
const getActiveUsersInterceptor = laika.intercept({
clientName: 'users',
operationName: 'getActiveUsers',
});
Parameters
Name | Type | Default value | Description |
---|---|---|---|
matcher? | Matcher | undefined | Leave undefined if you want to intercept every operation, otherwise provide either a matcher function or a matcher object with properties like clientName and/or a partial set of variables that have to match for a given operation to be intercepted |
connectFutureLinksOrMitmFn | undefined | boolean | ManInTheMiddleFn | false | If true, future links will still be called (e.g. reach the backend) and return responses. If set to a function, can serve for man-in-the-middle tinkering with the result. |
keepNonSubscriptionConnectionsOpen | boolean | false | If true, queries and mutations will behave a little like subscriptions, in that you will be able to fire updates even after the initial response. Experimental. |
Returns
Defined in
modifyRemote
▸ modifyRemote(matcher
, mapFn
): Object
Modify backend (or mocked) responses before they reach subscribers.
Parameters
Name | Type | Description |
---|---|---|
matcher | undefined | Matcher | Leave undefined if you want to intercept every operation, otherwise provide either a matcher function or a matcher object with properties like clientName and/or a partial set of variables that have to match for a given operation to be intercepted |
mapFn | (result : FetchResult <Record <string , any >, Record <string , any >, Record <string , any >>, operation : Operation ) => FetchResult <Record <string , any >, Record <string , any >, Record <string , any >> | Mapping function to alter the responses. |
Returns
Object
Name | Type |
---|---|
restore | () => void |