Skip to content

Commit e52f052

Browse files
committed
transfer new docs
1 parent 6ff9320 commit e52f052

File tree

77 files changed

+4656
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4656
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const metadata = {
2+
title: "Apollo Client Basics",
3+
description:
4+
"Learn about core Apollo Client concepts like queries, fragments, mutations, and caching as they relate to Faust.js and WordPress.",
5+
};
6+
7+
Faust.js uses `@apollo/client` under the hood to perform GraphQL operations against your WordPress backend. Having a solid understanding of Apollo Client queries, fragments, and mutations will help you get the most out of Faust.js.
8+
9+
## Apollo Client GraphQL Concepts
10+
11+
Below are core concepts for Apollo and GraphQL with links to the docs for your reference.
12+
13+
- [Queries](https://www.apollographql.com/docs/react/data/queries) – Retrieve data from your WordPress site.
14+
- [Fragments](https://www.apollographql.com/docs/react/data/fragments) – Modularize your queries to make them more maintainable.
15+
- [Mutations](https://www.apollographql.com/docs/graphos/get-started/concepts/graphql#mutations) – Update data in your WordPress backend.
16+
- [Apollo Client Cache](https://www.apollographql.com/docs/react/caching/cache-configuration) – Cache responses to minimize network usage.
17+
18+
## Faust.js-Specific Notes
19+
20+
- You don’t need to create or configure the client object yourself; Faust handles that for you.
21+
- You can still customize the underlying Apollo Client via plugin filters if you need advanced configuration.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
export const metadata = {
2+
title: "Blocks FAQ",
3+
description: "Frequently asked questions about Blocks.",
4+
};
5+
6+
## _"What if the block is missing some attributes?"_
7+
8+
If the block does not have any attributes or has only a few of them declared in the `block.json` for that block (you can view the `block.json` file for the block at https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/), you can still try to extend the block API by declaring additional attributes for that block.
9+
10+
Follow the [filters reference guide](reference/plugin-filters) to create a block that uses the `additional_block_attributes` property. The attributes will then be available to query from that block.
11+
12+
```php
13+
class CoreCode extends WPGraphQL\ContentBlocks\Blocks\Block
14+
{
15+
protected ?array $additional_block_attributes = array(
16+
// Write your attributes here
17+
);
18+
}
19+
```
20+
21+
> [!NOTE]
22+
> If you include those extensions in a custom plugin, your Headless Website application is dependent on the inclusion of this plugin. You need to make sure you bundle them together; otherwise, the queries you perform in the application will fail.
23+
24+
## _"Can I style the block differently?"_"
25+
26+
Yes, you can style the block in many ways, choosing to ignore some of the attributes altogether. You can also use an external React Library to style the block, such as Material UI or ChakraUI.
27+
28+
Bear in mind that this will almost always result in a degraded user editing experience, as the styles in the WordPress block editor view won't match the styles of the rendered headless page.
29+
30+
## _"What if the block contains custom JavaScript assets?"_
31+
32+
Some Core blocks include JavaScript assets that are injected into the WordPress page so they can run in the front view. Many [dynamic blocks](https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks/) use this functionality to include user interactivity. Since React is not bundled as a dependency in the browser, the client-side code that WordPress ships to the frontend in traditional WordPress sites typically consists of plain JavaScript or jQuery.
33+
34+
To review and handle bundled JavaScript assets, consider these options:
35+
36+
- **Include them in your code**: This is not recommended, as React does not play well with plain JavaScript and jQuery, which may lead to compatibility issues.
37+
- **Rewrite them as React components**: You can attempt to rewrite the code in React. If the bundled code can be understood and rewritten with low effort, then this could be a viable approach.
38+
- **Use an equivalent React Component from a library**: A simpler alternative is to find a compatible React package and use it instead of replicating the block's interactivity. This can often free the developer from implementing the functionality from scratch.
39+
40+
Inevitably, this is a common challenge when using Blocks in a Headless Website setup, so it's up to you to weigh the pros and cons of each approach.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export const metadata = {
2+
title: "Deploying Your App",
3+
description:
4+
"Explains the various options for deploying your Faust.js App to production.",
5+
};
6+
7+
The following explains the various options for deploying your Faust.js App to production.
8+
9+
## Picking The Right Node.js Version
10+
11+
Faust.js supports supported versions of Node.js v16.0.0 or newer. The [latest LTS version](https://nodejs.org/en/about/previous-releases) of Node.js is recommended and anything [compatible with your Next.js](https://nextjs.org/docs/pages/getting-started/installation) version. Please make sure you are using a Node.js version that is compatible when deploying to avoid unexpected errors.
12+
13+
Faust.js uses the `package.json` [engines field](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#engines) that will produce warnings when your package is installed as a dependency under a non compatible NPM/Node version.
14+
15+
## Building Your App
16+
17+
Since Faust.js is built on top of Next.js, it shares the same build process. For details on how Next.js generates optimized production builds, refer to the [Next.js Build API](<(https://nextjs.org/docs/pages/building-your-application/deploying#nextjs-build-api)>) documentation. Additionally, you can explore the Headless Platform framework guide for Next.js apps [here](https://developers.wpengine.com/docs/atlas/framework-guides/next-js/next/).
18+
19+
## Deploying to WP Engine's Headless Platform
20+
21+
The Headless Platform is the most effortless way to deploy a Faust.js app. Connect your GitHub repo and Atlas will automatically build and deploy your Faust.js project on each push. Some of the benefits you get out of the box are:
22+
23+
- Automatic installation of required WordPress plugins (Faust, WPGraphQL, etc.)
24+
- Automatic setup of Faust.js environment variables
25+
- Automatic configuration of the Faust WordPress plugin’s settings
26+
- WordPress and your headless app live in the same place
27+
- Automatic rebuilds on code changes
28+
- Support for [custom domains](https://wpengine.com/support/add-domain-in-user-portal/)
29+
30+
Deploy your Faust.js app and try for the [Headless Platform](https://wpengine.com/headless-wordpress/#form) for free!
31+
32+
For further reference, please check out the Headless Platform framework guide docs on Deploying Next.js [here](https://developers.wpengine.com/docs/atlas/framework-guides/next-js/next/).
33+
34+
> [!NOTE]
35+
> If deploying from the WP Engine portal using your own repository (without beginning with a blueprint), you will need to set your environment variables manually. Learn how by taking a look at our [platform docs](https://developers.wpengine.com/docs/atlas/getting-started/deploy-from-existing-repo/#set-environment-variables-optional).
36+
37+
## Self Hosted
38+
39+
You can also self host Faust.js apps on any hosting provider that supports Node.js.
40+
41+
To self host your Faust.js app, you will need to first build the app, then start it. Make sure you have the `faust build` and `faust start` scripts specified in your `package.json` file:
42+
43+
```json title="package.json"
44+
{
45+
"scripts": {
46+
"build": "faust build",
47+
"start": "faust start"
48+
}
49+
}
50+
```
51+
52+
Then, from the Node.js server run `npm run build` to build the app and `npm run start` to start it.
53+
For reference, please visit the [Next.js self-hosted deployment](https://nextjs.org/docs/pages/building-your-application/deploying#self-hosting) docs.

docs/explanation/index.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const metadata = {
2+
title: "Explanation",
3+
description:
4+
"High-level conceptual guides that provide background information and understanding of Headless WordPress development.",
5+
};
6+
7+
I see you found the root of the Explanatory guides! Explanatory guides are a place where we step away from code and talk high-level concepts and import background information. If you are looking to grow your understanding of Headless WordPress, you are in the right place.
8+
9+
> [!note] Learn More
10+
> For more info on how we layout our documentation and the the role played by Explanatory Guides, please read about the [_Diátaxis_](https://diataxis.fr/explanation/) approach we use.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
export const metadata = {
2+
title: "Migrate From WPGraphQL Gutenberg",
3+
description:
4+
"Migrate from wp-graphql-gutenberg to wp-graphql-content-blocks. This guide covers differences between the two plugins, reasons for migration, and step-by-step instructions for updating your GraphQL queries and block structures to ensure compatibility with Faust.js and modern WPGraphQL best practices.",
5+
};
6+
7+
With [`wp-graphql-gutenberg`](https://github.com/pristas-peter/wp-graphql-gutenberg) being sunset you may find yourself needing to move to the improved [`wp-graphql-content-blocks`](https://github.com/wpengine/wp-graphql-content-blocks) plugin.
8+
9+
## What's the difference?
10+
11+
Both plugins extend WPGraphQL to add support for blocks (aka. Gutenberg) to the WPGraphQL schema.
12+
13+
However, there are some key differences that you should be aware of:
14+
15+
- WPGraphQL Gutenberg gets the blocks registry and sends it in a network request to the WordPress PHP application. So it needs to be synced from time to time.
16+
17+
- It also allows the blocks to be served as JSON using the `blocksJSON` field. If requesting data this way, the data is not typechecked and you may overfetch data as a side effect.
18+
19+
- Block attributes are using their own types, containing different type for deprecated versions. For example:
20+
21+
```gql
22+
...on CoreParagraphBlock {
23+
attributes {
24+
...on CoreParagraphBlockAttributes {
25+
content
26+
}
27+
...on CoreParagraphBlockDeprecatedV1Attributes {
28+
content
29+
}
30+
}
31+
}
32+
```
33+
34+
- It does not allow blocks to be returned as a flat list so you have to use deeply nested queries to get the list of innerBlocks (and this won’t nearly solve the issue 100%).
35+
36+
- wp-graphql-content-blocks does not save anything in the database (this is actually a good thing) compared to wp-graphql-gutenberg. Therefore it only supports previews when the **“preview”** button is hit in the editor.
37+
38+
## How do I migrate a block from wp-graphql-gutenberg?
39+
40+
To answer this question you will have check how you queried the blocks using `wp-graphql-gutenberg`. There are two different cases that you have to consider here:
41+
42+
### You used the `blocksJSON` property to get the blocks data
43+
44+
The `wp-graphql-content-blocks` plugin does not expose the `blocksJSON` fields, because it is problematic to do so. Getting the data as plain JSON directly from the database completely overrides the principles of GraphQL and ignores the type safety of the system. If one of the properties is altered, you have no guarantee that the GraphQL server will catch them. Plus, most of the times you will over fetch data leading to slower queries, especially if you have lots of content on the screen.
45+
46+
So, due to the lack of Introspection, unpredictability, and in order to promote best practices, `wp-graphql-content-blocks` do not expose the block data as plain JSON. Instead, it is recommended to use GraphQL types to retrieve associated block attributes and fields.The effort required to add block fragments is not high. If you follow the recommended approach of co-located fragments, you may add them as properties to each of your block expected attribute list and make sure that you include those into the page query string.
47+
48+
Take a look at the following example taken from [WebDevStudios nextjs-wordpress-starter](https://github.com/WebDevStudios/nextjs-wordpress-starter/blob/main/components/blocks/core/BlockCode/BlockCode.js). It shows an implementation of the `CoreCode` block using `wp-graphql-gutenberg` and getting the data using `blockJSON`.
49+
50+
With it, you would have to create a fragment like this:
51+
52+
```gql
53+
CoreCode.fragments = {
54+
key: `CoreCodeBlockFragment`,
55+
entry: gql`
56+
fragment CoreCodeBlockFragment on CoreCodeBlock {
57+
attributes {
58+
...on CoreCodeBlockAttributes {
59+
anchor
60+
backgroundColor
61+
content
62+
className
63+
gradient
64+
style
65+
textColor
66+
}
67+
}
68+
}
69+
`,
70+
};
71+
```
72+
73+
Based on the [creating a custom block](/docs/how-to/custom-blocks/) guide from the WordPress Core Blocks you just need to add the following fragment as a new property:
74+
75+
```gql CoreCode.fragments = {
76+
key: `CoreCodeBlockFragment`,
77+
entry: gql`
78+
fragment CoreCodeBlockFragment on CoreCode {
79+
attributes {
80+
anchor
81+
backgroundColor
82+
content
83+
className
84+
gradient
85+
style
86+
textColor
87+
}
88+
}
89+
`,
90+
};
91+
```
92+
93+
When the `WordPressBlocksViewer` renders the component, it passes the whole block data as a property of that block. If your block is designed to accept different properties for attributes and for `innerBlocks` you have to create a wrapper to forward the properties into the right slots:
94+
95+
```js title="CoreCode.js"
96+
export default function CoreCode({attributes, children}) {
97+
const BlockCode = dynamic(() => import('@/components/blocks/core/BlockCode'))
98+
return <BlockCode {...attributes} innerBlocks={children}>
99+
}
100+
```
101+
102+
### You used the block field with GraphQL types and fragments
103+
104+
If you were using the block field from the `wp-graphql-gutenberg` then most of the component fragment queries should be the same with the following exceptions.
105+
106+
You should be querying the block attributes without qualifying their type:
107+
108+
**Before:**
109+
110+
```gql
111+
...on CoreParagraphBlock {
112+
attributes {
113+
...on CoreParagraphBlockAttributes {
114+
content
115+
}
116+
}
117+
}
118+
```
119+
120+
**After:**
121+
122+
```gql
123+
...on CoreParagraphBlock {
124+
attributes {
125+
content
126+
}
127+
}
128+
```
129+
130+
There are no separate fields `previewBlocks` and `previewBlocksJSON`. If you want to preview posts or pages you should be setting the `asPreview` boolean to `true` for the post/page in your GraphQL request (this is how Faust.js previews work under the hood).
131+
132+
The base interface for each block contains different fields, so you need to make sure your queries use the valid ones from this list:
133+
134+
- `renderedHTML`: It’s the HTML of the block as rendered by the render_block function.
135+
136+
- `name`: The actual name of the block taken from its block.json spec.
137+
138+
- `__typename`: The type of block transformed from the name field in camel-case notation.
139+
140+
- `apiVersion`: The apiVersion of the block taken from its block.json spec.
141+
142+
- `innerBlocks`: The `innerblock` list of that block.
143+
144+
-`isDynamic`: Whether the block is dynamic or not, taken from its block.json spec.
145+
146+
- `clientId`, `parentClientId`: Unique identifiers for the block and the parent of the block.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const metadata = {
2+
title: "Migrating to TypeScript",
3+
description:
4+
"Guide for migrating existing Next.js pages to TypeScript in a Faust.js project with resources and references.",
5+
};
6+
7+
If you have existing Next.js pages that you want to migrate to TypeScript, you can follow the [official TypeScript Docs](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html) for general TypeScript migration tips.
8+
9+
For Faust, see the [TypeScript Reference Doc](/docs/reference/typescript).
10+
11+
## Further Reading
12+
13+
- [TypeScript Reference](/docs/reference/typescript)
14+
- [Typing GraphQL Queries with GraphQL Codegen](/docs/how-to/generate-types-with-graphql-codegen)
72.6 KB
Loading
99.7 KB
Loading
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
export const metadata = {
2+
title: "Telemetry",
3+
description:
4+
"Information about Faust's anonymous telemetry data collection, what data is collected, and how to opt out.",
5+
};
6+
7+
Faust collects completely anonymous telemetry data about general usage. Participation in this anonymous program is optional. For more information on how we handle this data, please read our [Privacy Policy](/privacy-policy).
8+
9+
## What data we collect
10+
11+
### WordPress Environment
12+
13+
- WordPress version
14+
- PHP version
15+
- Faust plugin version & settings (_`frontend_uri` is not collected_)
16+
- WordPress Multisite
17+
- If the site is hosted on WP Engine
18+
- Active plugins
19+
20+
### Node Environment
21+
22+
- `@faustwp/core` version
23+
- `@faustwp/cli` version
24+
- `@faustwp/blocks` version
25+
- `@faustwp/block-editor-utils` version
26+
- `@faustwp/experimental-app-router` version
27+
- `@apollo/client` version
28+
- Node version
29+
- Next.js version
30+
- If the Node environment is in **dev mode** (i.e., whether `npm run dev` was run)
31+
- The command that was run (e.g., `npm run dev`, `npm run build`)
32+
- The Operating System Platform name
33+
34+
> **_NOTE:_** We do not collect any personally identifiable information or sensitive information like environment variables, file paths, or any application URLs.
35+
36+
## Program Participation
37+
38+
If you'd like to join the program, you can enable telemetry by selecting yes on the prompt:
39+
40+
![Message displayed in WP Admin](./images/telemetry-image-1.png)
41+
42+
You can also go to the Faust Settings page and toggle your participation at anytime:
43+
44+
![Faust settings page showing checkbox for Telemetry](./images/telemetry-2.png)
82.4 KB
Loading

0 commit comments

Comments
 (0)