Skip to content

Commit 9356078

Browse files
authored
Merge pull request #243 from wpengine/reference/faust-plugin-filters
Reference: faust plugin system filters
2 parents e5fbf92 + c482e51 commit 9356078

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed

src/pages/docs/nav.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
"title": "Reference",
5858
"route": "/docs/reference/",
5959
"children": [
60+
{
61+
"title": "Faust Plugin System Filters",
62+
"route": "/docs/reference/faust-plugin-system-filters"
63+
},
6064
{
6165
"title": "fromThemeJson",
6266
"route": "/docs/reference/from-theme-json"
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
export const metadata = {
2+
title: "Faust Plugin System Filters",
3+
description: "API information for Faust's plugin system.",
4+
};
5+
6+
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.
7+
8+
> [!INFO]
9+
> Check out this comprehensive guide to creating and including Faust plugins in your project: [Create a Plugin](/docs/how-to/create-a-plugin).
10+
11+
## `apolloClientInMemoryCacheOptions`
12+
13+
This allows you to modify the [Apollo Client’s `InMemoryCache` config](https://www.apollographql.com/docs/react/api/cache/InMemoryCache).
14+
15+
```ts title="faustFilters.config.ts"
16+
import {
17+
InMemoryCacheConfig,
18+
} from '@apollo/client';
19+
20+
addFilter(
21+
hookName: 'apolloClientInMemoryCacheOptions',
22+
namespace: string,
23+
callback: (
24+
inMemoryCacheObject: InMemoryCacheConfig,
25+
context: Record<string, never>,
26+
) => InMemoryCacheConfig,
27+
priority?: number | undefined,
28+
): void;
29+
```
30+
31+
## `apolloClientOptions`
32+
33+
Allows you to modify the [Apollo Client’s options](https://www.apollographql.com/docs/react/api/core/ApolloClient).
34+
35+
```ts title="faustFilters.config.ts"
36+
import {
37+
ApolloClientOptions,
38+
NormalizedCacheObject,
39+
} from '@apollo/client';
40+
41+
addFilter(
42+
hookName: 'apolloClientOptions',
43+
namespace: string,
44+
callback: (
45+
apolloClientOptions: ApolloClientOptions<NormalizedCacheObject>,
46+
context: Record<string, never>,
47+
) => ApolloClientOptions<NormalizedCacheObject>,
48+
priority?: number | undefined,
49+
): void;
50+
```
51+
52+
And here is an example:
53+
54+
```js title="plugins/persisted-queries-plugin.js"
55+
class PersistedQueriesPlugin {
56+
apply({ addFilter }) {
57+
addFilter("apolloClientOptions", "faust", (apolloClientOptions) => {
58+
const existingLink = apolloClientOptions?.link;
59+
return {
60+
...apolloClientOptions,
61+
link:
62+
existingLink instanceof HttpLink
63+
? persistedQueriesLink.concat(existingLink)
64+
: persistedQueriesLink.concat(httpLink),
65+
};
66+
});
67+
}
68+
}
69+
```
70+
71+
## `possibleTemplatesList`
72+
73+
Allows you to modify the templates that are returned for a given URI.
74+
75+
**Context Object**
76+
77+
- `seedNode: SeedNode`: The seed node requested from the seed query
78+
79+
```ts title="faustFilters.config.ts"
80+
addFilter(
81+
hookName: 'possibleTemplatesList',
82+
namespace: string,
83+
callback: (
84+
possibleTemplates: string[],
85+
context: { seedNode: SeedNode },
86+
) => string[],
87+
priority?: number | undefined,
88+
): void;
89+
```
90+
91+
## `seedQueryDocumentNode`
92+
93+
Allows you to override the Seed Query.
94+
95+
**Context Object**
96+
97+
- `resolvedUrl: string`: The resolved URL for the given route.
98+
99+
```ts title="faustFilters.config.ts"
100+
addFilter(
101+
hookName: 'seedQueryDocumentNode',
102+
namespace: string,
103+
callback: (
104+
seedQuery: DocumentNode,
105+
context: { resolvedUrl: string },
106+
) => DocumentNode,
107+
priority?: number | undefined,
108+
): void;
109+
```
110+
111+
## `graphqlEndpoint`
112+
113+
Allows you to override the GraphQL Endpoint.
114+
115+
**Context Object**
116+
117+
- `wpUrl: string`: The URL to the WordPress site
118+
119+
```ts title="faustFilters.config.ts"
120+
addFilter(
121+
hookName: 'graphqlEndpoint',
122+
namespace: string,
123+
callback: (graphqlEndpoint: string, context: { wpUrl: string }) => string,
124+
priority?: number | undefined,
125+
): void;
126+
```
127+
128+
## `wpHostname`
129+
130+
Allows you to override the WordPress site URLs `hostname`.
131+
132+
**Context Object**
133+
134+
- `wpUrl: string`: The URL to the WordPress site
135+
136+
```ts title="faustFilters.config.ts"
137+
addFilter(
138+
hookName: 'wpHostname',
139+
namespace: string,
140+
callback: (wpHostname: string, context: { wpUrl: string }) => string,
141+
priority?: number | undefined,
142+
): void;
143+
```
144+
145+
## `wpUrl`
146+
147+
Allows you to override the WordPress site URL.
148+
149+
**Context Object**
150+
151+
- `wpUrl: string`: The URL to the WordPress site
152+
153+
```ts title="faustFilters.config.ts"
154+
addFilter(
155+
hookName: 'wpUrl',
156+
namespace: string,
157+
callback: (wpUrl: string, context: Record<string, never>) => string,
158+
priority?: number | undefined,
159+
): void;
160+
```
161+
162+
## `toolbarNodes`
163+
164+
> [!Important]
165+
> This filter is part of an experimental feature that has been deprecated. This feature will continue to function as-is, but will no longer revive bug fixes or other improvements. You may opt-in to using this feature by setting `experimentalToolbar: true` within your project’s `faust.config.js`.
166+
167+
Allows you to modify Faust’s Toolbar nodes.
168+
169+
**Context Object**
170+
171+
- `seedNode: SeedNode`: The seed node requested from the seed query
172+
173+
```ts title="faustFilters.config.ts"
174+
addFilter(
175+
hookName: 'toolbarNodes',
176+
namespace: string,
177+
callback: (
178+
toolbarNodes: FaustToolbarNodes,
179+
context: { seedNode: SeedNode },
180+
) => FaustToolbarNodes,
181+
priority?: number | undefined,
182+
): void;
183+
```
184+
185+
## `resolvedUrl`
186+
187+
Allows you to override the resolved URL in the Faust template system.
188+
189+
**Context Object**
190+
191+
- `nextContext: GetServerSidePropsContext | GetStaticPropsContext: The Next.js context object from either getServerSidePropsorgetStaticProps`.
192+
193+
```ts title="faustFilters.config.ts"
194+
addFilter(
195+
hookName: 'resolvedUrl',
196+
namespace: string,
197+
callback: (
198+
resolvedUrl: string | null,
199+
context: {
200+
nextContext: GetServerSidePropsContext | GetStaticPropsContext;
201+
},
202+
) => string | null,
203+
priority?: number | undefined,
204+
): void;
205+
```

0 commit comments

Comments
 (0)