Created
October 22, 2020 17:31
-
-
Save kkemple/f880ccc61d8e4c5c0d80060400ace000 to your computer and use it in GitHub Desktop.
gatsby source plugin for Oribt
This file contains hidden or 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
// constants for your GraphQL Post and Author types | |
const fetch = require("isomorphic-fetch") | |
const MEMBER_NODE_TYPE = `OrbitMember` | |
const ORBIT_API_KEY = `<YOUR_KEY_HERE>` | |
exports.sourceNodes = async ({ | |
actions, | |
createContentDigest, | |
createNodeId, | |
}) => { | |
const { createNode } = actions | |
const response = await fetch( | |
`https://app.orbit.love/gatsby-source-demo-workspace/members.json?api_key=${ORBIT_API_KEY}` | |
) | |
const { data } = await response.json() | |
// loop through data and create Gatsby nodes | |
data.forEach(member => | |
createNode({ | |
...member.attributes, | |
id: createNodeId(`${MEMBER_NODE_TYPE}-${member.id}`), | |
parent: null, | |
children: [], | |
internal: { | |
type: MEMBER_NODE_TYPE, | |
content: JSON.stringify(member), | |
contentDigest: createContentDigest(member), | |
}, | |
}) | |
) | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment