-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
213 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
e2e-tests/development-runtime/plugins/gatsby-source-fs-route-mutations/gatsby-node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { GatsbyNode } from "gatsby" | ||
|
||
let createdNodes = new Set<string>() | ||
|
||
export const sourceNodes: GatsbyNode["sourceNodes"] = ({ | ||
actions, | ||
webhookBody, | ||
getNode, | ||
createContentDigest, | ||
reporter, | ||
}) => { | ||
const handledNodes = new Set(createdNodes) | ||
function addNode(data: { id: string; slug: string; content: string }): void { | ||
const node = { | ||
...data, | ||
parent: null, | ||
children: [], | ||
internal: { | ||
type: `FilesystemRoutesMutation`, | ||
contentDigest: createContentDigest(data), | ||
}, | ||
} | ||
|
||
createdNodes.add(node.id) | ||
handledNodes.delete(node.id) | ||
|
||
actions.createNode(node) | ||
|
||
const childNode = { | ||
...data, | ||
id: `${node.id} << childNode`, | ||
parent: node.id, | ||
internal: { | ||
type: `FilesystemRoutesMutationChild`, | ||
contentDigest: node.internal.contentDigest, | ||
}, | ||
} | ||
actions.createNode(childNode) | ||
const parent = getNode(node.id) | ||
|
||
if (!parent) { | ||
throw new Error(`Could not find parent node`) | ||
} | ||
|
||
actions.createParentChildLink({ | ||
parent: parent, | ||
child: childNode, | ||
}) | ||
} | ||
|
||
if (webhookBody?.setup === `create`) { | ||
reporter.verbose(`[gatsby-source-fs-route-mutation] create a new node`) | ||
addNode({ | ||
id: `fs-route-mutation-test`, | ||
slug: `new-node`, | ||
content: `This is node that was just created`, | ||
}) | ||
} else if (webhookBody?.setup === `update`) { | ||
reporter.verbose(`[gatsby-source-fs-route-mutation] update a node`) | ||
addNode({ | ||
id: `fs-route-mutation-test`, | ||
slug: `updated-node`, | ||
content: `This is node that had slug and content updated`, | ||
}) | ||
} else if (webhookBody?.setup === `delete`) { | ||
reporter.verbose(`[gatsby-source-fs-route-mutation] delete a node`) | ||
} else { | ||
reporter.verbose(`[gatsby-source-fs-route-mutation] initial setup`) | ||
} | ||
|
||
addNode({ | ||
id: `fs-route-mutation-stable`, | ||
slug: `stable`, | ||
content: `This is stable node`, | ||
}) | ||
|
||
for (const nodeIdToDelete of handledNodes) { | ||
const nodeToDelete = getNode(nodeIdToDelete) | ||
if (nodeToDelete) { | ||
createdNodes.delete(nodeIdToDelete) | ||
actions.deleteNode(nodeToDelete) | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
e2e-tests/development-runtime/plugins/gatsby-source-fs-route-mutations/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// noop |
1 change: 1 addition & 0 deletions
1
e2e-tests/development-runtime/plugins/gatsby-source-fs-route-mutations/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
18 changes: 18 additions & 0 deletions
18
...time/src/pages/collection-routing/mutations/child-{FilesystemRoutesMutationChild.slug}.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default function FSRoutesMutationTemplate({ data }) { | ||
return ( | ||
<> | ||
<pre>{JSON.stringify(data, null, 2)}</pre> | ||
</> | ||
) | ||
} | ||
|
||
export const query = graphql` | ||
query($id: String!) { | ||
filesystemRoutesMutationChild(id: { eq: $id }) { | ||
content | ||
} | ||
} | ||
` |
18 changes: 18 additions & 0 deletions
18
...lopment-runtime/src/pages/collection-routing/mutations/{FilesystemRoutesMutation.slug}.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default function FSRoutesMutationTemplate({ data }) { | ||
return ( | ||
<> | ||
<pre>{JSON.stringify(data, null, 2)}</pre> | ||
</> | ||
) | ||
} | ||
|
||
export const query = graphql` | ||
query($id: String!) { | ||
filesystemRoutesMutation(id: { eq: $id }) { | ||
content | ||
} | ||
} | ||
` |