Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(www): Convert API pages to MDX #20763

Merged
merged 24 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c8bee9f
Progress snapshot with working frontmatter for jsdoc and apicalls. Po…
Nov 6, 2019
ab30c11
Converted remaining api doc pages to MDX. The API MDX temple now inje…
Nov 7, 2019
45dbec1
Hide all document for `typedef`. Added @private annotation to `delete…
Nov 7, 2019
c92c038
The adjustments to api-node-helpers-docs.js put what should be docume…
Nov 9, 2019
14e0878
The jsdoc parameter now takes a list of strings referencing specific …
Nov 9, 2019
31d7aec
Added apicalls values for stub documents that should have github link…
Nov 9, 2019
dcf4a43
Changed headings over api document lists to their actual text from th…
Nov 9, 2019
4ece2c1
Found more docs with `showTopLevelSignatures={true}`
Nov 10, 2019
5259461
Removed unnecessary commented code and a debugging `console.log`
Nov 16, 2019
a3662fc
Merge branch 'master' into api-reference-mdx
tesseralis Jan 21, 2020
437a1a4
update mdx pages
tesseralis Jan 22, 2020
2ffd74b
simplify everything!
tesseralis Jan 22, 2020
f8d4d39
whoops
tesseralis Jan 22, 2020
b558843
move utility file to the same page
tesseralis Jan 22, 2020
b43f20f
Merge branch 'master' into api-reference-mdx
tesseralis Jan 23, 2020
5f7a598
Merge branch 'master' into api-reference-mdx
tesseralis Jan 31, 2020
756f845
Merge branch 'master' into api-reference-mdx
tesseralis Feb 9, 2020
0b1af74
Update www/gatsby-node.js
tesseralis Feb 10, 2020
93e8e39
Update docs/docs/node-api-helpers.md
tesseralis Feb 10, 2020
a21d40a
Update docs/docs/actions.md
tesseralis Feb 10, 2020
68c4013
Merge branch 'master' into api-reference-mdx
tesseralis Feb 10, 2020
f922498
use javascript:title
tesseralis Feb 10, 2020
84d7786
Merge branch 'api-reference-mdx' of https://github.com/tesseralis/gat…
tesseralis Feb 10, 2020
bd559af
add custom descriptions
tesseralis Feb 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/docs/actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Actions
description: Documentation on actions and how they help you manipulate state within Gatsby
jsdoc:
- "gatsby/src/redux/actions/public.js"
- "gatsby/src/redux/actions/restricted.js"
contentsHeading: Functions
---

Gatsby uses [Redux](http://redux.js.org) internally to manage state. When you implement a Gatsby API, you are passed a collection of actions (equivalent to actions bound with [bindActionCreators](https://redux.js.org/api/bindactioncreators/) in Redux) which you can use to manipulate state on your site.

The object `actions` contains the functions and these can be individually extracted by using ES6 object destructuring.

```javascript
// For function createNodeField
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
}
```
11 changes: 11 additions & 0 deletions docs/docs/browser-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Gatsby Browser APIs
description: Documentation about leveraging standard browser APIs within Gatsby
jsdoc: ["gatsby/src/utils/api-browser-docs.js"]
apiCalls: BrowserAPI
showTopLevelSignatures: true
---

## Usage

Implement any of these APIs by exporting them from a file named `gatsby-browser.js` in the root of your project.
31 changes: 31 additions & 0 deletions docs/docs/node-api-helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Node API Helpers
description: Documentation on API helpers for creating nodes within Gatsby's GraphQL data layer
jsdoc: ["gatsby/src/utils/api-node-helpers-docs.js"]
apiCalls: NodeAPIHelpers
contentsHeading: Shared helpers
showTopLevelSignatures: true
---

The first argument passed to each of [Gatsby’s Node APIs](/docs/node-apis/) is an object containing a set of helpers. Helpers shared by all Gatsby’s Node APIs are documented in [Shared helpers](#shared-helpers) section.

```javascript
// in gatsby-node.js
exports.createPages = gatsbyNodeHelpers => {
const { actions, reporter } = gatsbyNodeHelpers
// use helpers
}
```

Common convention is to destructure helpers right in argument list:

```javascript
// in gatsby-node.js
exports.createPages = ({ actions, reporter }) => {
// use helpers
}
```

## Note

Some APIs provide additional helpers. For example `createPages` provides `graphql` function. Check documentation of specific APIs in [Gatsby Node APIs](/docs/node-apis/) for details.
33 changes: 33 additions & 0 deletions docs/docs/node-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Gatsby Node APIs
description: Documentation on Node APIs used in Gatsby build process for common uses like creating pages
jsdoc: ["gatsby/src/utils/api-node-docs.js"]
apiCalls: NodeAPI
---

Gatsby gives plugins and site builders many APIs for controlling your site's data in the GraphQL data layer.

## Async plugins

If your plugin performs async operations (disk I/O, database access, calling remote APIs, etc.) you must either return a promise or use the callback passed to the 3rd argument. Gatsby needs to know when plugins are finished as some APIs, to work correctly, require previous APIs to be complete first. See [Debugging Async Lifecycles](/docs/debugging-async-lifecycles/) for more info.

```javascript
// Promise API
exports.createPages = () => {
return new Promise((resolve, reject) => {
// do async work
})
}

// Callback API
exports.createPages = (_, pluginOptions, cb) => {
// do Async work
cb()
}
```

If your plugin does not do async work, you can just return directly.

## Usage

Implement any of these APIs by exporting them from a file named `gatsby-node.js` in the root of your project.
28 changes: 28 additions & 0 deletions docs/docs/node-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Node Model
description: Documentation explaining the model of nodes in Gatsby's GraphQL data layer
jsdoc: ["gatsby/src/schema/node-model.js"]
apiCalls: NodeModel
contentsHeading: Methods
---

Gatsby exposes its internal data store and query capabilities to GraphQL field resolvers on `context.nodeModel`.

## Example Usage

```javascript:title=gatsby-node.js
createResolvers({
Query: {
mood: {
type: `String`,
resolve(source, args, context, info) {
const coffee = context.nodeModel.getAllNodes({ type: `Coffee` })
if (!coffee.length) {
return 😞
}
return 😊
},
},
},
})
```
11 changes: 11 additions & 0 deletions docs/docs/ssr-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Gatsby Server Rendering APIs
description: Documentation on APIs related to server side rendering during Gatsby's build process
jsdoc: ["gatsby/cache-dir/api-ssr-docs.js"]
apiCalls: SSRAPI
showTopLevelSignatures: true
---

## Usage

Implement any of these APIs by exporting them from a file named `gatsby-ssr.js` in the root of your project.
5 changes: 5 additions & 0 deletions packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,10 @@ actions.deleteNode = (options: any, plugin: Plugin, args: any) => {
}
}

// Marked private here because it was supressed in documentation pages.
/**
* Batch delete nodes
* @private
* @param {Array} nodes an array of node ids
* @example
* deleteNodes([`node1`, `node2`])
Expand Down Expand Up @@ -582,8 +584,11 @@ actions.deleteNodes = (nodes: any[], plugin: Plugin) => {
let NODE_COUNTER = 0

const typeOwners = {}

// memberof notation is added so this code can be referenced instead of the wrapper.
/**
* Create a new node.
* @memberof actions
* @param {Object} node a node object
* @param {string} node.id The node's ID. Must be globally unique.
* @param {string} node.parent The ID of the parent's node. If the node is
Expand Down
Loading