Skip to content

Instantly share code, notes, and snippets.

@eclectic-coding
Forked from sidharthachatterjee/gatsby-node.js
Created October 12, 2019 00:33
Show Gist options
  • Save eclectic-coding/03834fbfaee8981bf1a6077394d8e1ca to your computer and use it in GitHub Desktop.
Save eclectic-coding/03834fbfaee8981bf1a6077394d8e1ca to your computer and use it in GitHub Desktop.
Dynamic GraphQL queries with String interpolation
exports.createPages = ({ graphql, actions }) => {
return graphql(`
{
site {
siteMetadata {
githubOrgs
}
}
}
`).then(result => {
const { githubOrgs } = result.data.site.siteMetadata
const query = `
{
githubOrgs: github{
${githubOrgs
.map(
org => `
${org}: organization(login:"${org}"){
...orgFragments
}
`
)
.join(``)}
}
}
fragment orgFragments on GitHub_Organization{
id
url
}
`
console.log(query)
return graphql(query).then(result => {
console.log(result.data.githubOrgs)
// createPage etc
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment