Faust Plugin System Filters
Below are the different types of filters available to you in the Faust Plugin System. Each filter callback contains two parameters, the first parameter is the filtered data. For instance the first parameter in the possibleTemplatesList
filter is possibleTemplates
, a string array of templates. The second parameter of every filter is a context
object. This object may contain information needed to make modifications to the filtered data.
INFO
Check out this comprehensive guide to including Faust plugins in your project: https://faustjs.org/guide/how-to-create-a-plugin
apolloClientInMemoryCacheOptions
Allows you to modify the Apollo Client’s InMemoryCache
config.
//config
import {
InMemoryCacheConfig,
} from '@apollo/client';
addFilter(
hookName: 'apolloClientInMemoryCacheOptions',
namespace: string,
callback: (
inMemoryCacheObject: InMemoryCacheConfig,
context: Record<string, never>,
) => InMemoryCacheConfig,
priority?: number | undefined,
): void;
Code language: JavaScript (javascript)
apolloClientOptions
Allows you to modify the Apollo Client’s options.
// config
import {
ApolloClientOptions,
NormalizedCacheObject,
} from '@apollo/client';
addFilter(
hookName: 'apolloClientOptions',
namespace: string,
callback: (
apolloClientOptions: ApolloClientOptions<NormalizedCacheObject>,
context: Record<string, never>,
) => ApolloClientOptions<NormalizedCacheObject>,
priority?: number | undefined,
): void;
Code language: JavaScript (javascript)
Example
class PersistedQueriesPlugin {
apply({ addFilter }) {
addFilter('apolloClientOptions', 'faust', (apolloClientOptions) => {
const existingLink = apolloClientOptions?.link;
return {
...apolloClientOptions,
link: existingLink instanceof HttpLink ? persistedQueriesLink.concat( existingLink ) : persistedQueriesLink.concat(httpLink)
}
});
}
}
Code language: PHP (php)
possibleTemplatesList
Allows you to modify the templates that are returned for a given URI.
Context Object
seedNode: SeedNode
: The seed node requested from the seed query
// config
addFilter(
hookName: 'possibleTemplatesList',
namespace: string,
callback: (
possibleTemplates: string[],
context: { seedNode: SeedNode },
) => string[],
priority?: number | undefined,
): void;
Code language: TypeScript (typescript)
seedQueryDocumentNode
Allows you to override the Seed Query.
Context Object
resolvedUrl: string
: The resolved URL for the given route.
// config
addFilter(
hookName: 'seedQueryDocumentNode',
namespace: string,
callback: (
seedQuery: DocumentNode,
context: { resolvedUrl: string },
) => DocumentNode,
priority?: number | undefined,
): void;
Code language: JavaScript (javascript)
graphqlEndpoint
Allows you to override the GraphQL Endpoint.
Context Object
wpUrl: string
: The URL to the WordPress site
// config
addFilter(
hookName: 'graphqlEndpoint',
namespace: string,
callback: (graphqlEndpoint: string, context: { wpUrl: string }) => string,
priority?: number | undefined,
): void;
Code language: TypeScript (typescript)
wpHostname
Allows you to override the WordPress site URLs hostname
.
Context Object
wpUrl: string
: The URL to the WordPress site
// config
addFilter(
hookName: 'wpHostname',
namespace: string,
callback: (wpHostname: string, context: { wpUrl: string }) => string,
priority?: number | undefined,
): void;
Code language: JavaScript (javascript)
wpUrl
Allows you to override the WordPress site URL.
Context Object
wpUrl: string
: The URL to the WordPress site
// config
addFilter(
hookName: 'wpUrl',
namespace: string,
callback: (wpUrl: string, context: Record<string, never>) => string,
priority?: number | undefined,
): void;
Code language: TypeScript (typescript)
toolbarNodes
Note: This filter is part of an experimental feature. You can opt-in to using this feature by setting experimentalToolbar: true
within your project’s faust.config.js.
Allows you to modify Faust’s Toolbar nodes.
Context Object
seedNode: SeedNode
: The seed node requested from the seed query
// config
addFilter(
hookName: 'toolbarNodes',
namespace: string,
callback: (
toolbarNodes: FaustToolbarNodes,
context: { seedNode: SeedNode },
) => FaustToolbarNodes,
priority?: number | undefined,
): void;
Code language: TypeScript (typescript)
resolvedUrl
Allows you to override the resolved URL in the Faust template system.
Context Object
nextContext: GetServerSidePropsContext | GetStaticPropsContext
: The Next.js context object from eithergetServerSideProps
orgetStaticProps
.
// config
addFilter(
hookName: 'resolvedUrl',
namespace: string,
callback: (
resolvedUrl: string | null,
context: {
nextContext: GetServerSidePropsContext | GetStaticPropsContext;
},
) => string | null,
priority?: number | undefined,
): void;
Code language: TypeScript (typescript)