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 10 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
25 changes: 25 additions & 0 deletions docs/docs/actions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: "Actions"
disableTableOfContents: true
jsdoc: ["gatsby/src/redux/actions/public.js", "gatsby/src/redux/actions/restricted.js"]
---

import APIReference, {APIContents} from "../../www/src/components/api-reference"


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 `boundActionCreators` 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
}
```

## Functions
<APIContents docs={props.mergedFuncs} />
tesseralis marked this conversation as resolved.
Show resolved Hide resolved

## Reference
<APIReference docs={props.mergedFuncs} />
17 changes: 17 additions & 0 deletions docs/docs/browser-apis.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: "Gatsby Browser APIs"
disableTableOfContents: true
jsdoc: ["gatsby/src/utils/api-browser-docs.js"]
apicalls: "BrowserAPI"
---

import APIReference, {APIContents} from "../../www/src/components/api-reference"

## Usage
Implement any of these APIs by exporting them from a file named `gatsby-browser.js` in the root of your project.

## APIs
<APIContents docs={props.mergedFuncs} />

## Reference
<APIReference docs={props.mergedFuncs} showTopLevelSignatures={true} />
36 changes: 36 additions & 0 deletions docs/docs/node-api-helpers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "Node API Helpers"
disableTableOfContents: true
jsdoc: ["gatsby/src/utils/api-node-helpers-docs.js"]
apicalls: "NodeAPIHelpers"
---

import APIReference, {APIContents} from "../../www/src/components/api-reference"

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.

## Shared helpers
<APIContents docs={props.mergedFuncs} />

## Reference
<APIReference docs={props.mergedFuncs} showTopLevelSignatures={true}/>
39 changes: 39 additions & 0 deletions docs/docs/node-apis.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: "Gatsby Node APIs"
disableTableOfContents: true
jsdoc: ["gatsby/src/utils/api-node-docs.js"]
apicalls: "NodeAPI"
---

import APIReference, {APIContents} from "../../www/src/components/api-reference"

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.

## APIs
<APIContents docs={props.mergedFuncs} />

## Reference
<APIReference docs={props.mergedFuncs} />
35 changes: 35 additions & 0 deletions docs/docs/node-model.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "Node Model"
disableTableOfContents: true
jsdoc: ["gatsby/src/schema/node-model.js"]
apicalls: "NodeModel"
---

import APIReference, {APIContents} from "../../www/src/components/api-reference"

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

## Example Usage
### gatsby-node.js
```javascript
createResolvers({
Query: {
mood: {
type: `String`,
resolve(source, args, context, info) {
const coffee = context.nodeModel.getAllNodes({ type: `Coffee` })
if (!coffee.length) {
return 😞
}
return 😊
},
},
},
})
```

## Methods
<APIContents docs={props.mergedFuncs} />

## Reference
<APIReference docs={props.mergedFuncs} />
17 changes: 17 additions & 0 deletions docs/docs/ssr-apis.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: "Gatsby Server Rendering APIs"
disableTableOfContents: true
jsdoc: ["gatsby/cache-dir/api-ssr-docs.js"]
apicalls: "SSRAPI"
---

import APIReference, {APIContents} from "../../www/src/components/api-reference"

## Usage
Implement any of these APIs by exporting them from a file named `gatsby-ssr.js` in the root of your project.

## APIs
<APIContents docs={props.mergedFuncs} />

## Reference
<APIReference docs={props.mergedFuncs} showTopLevelSignatures={true} />
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