-
-
Save eclectic-coding/03834fbfaee8981bf1a6077394d8e1ca to your computer and use it in GitHub Desktop.
Dynamic GraphQL queries with String interpolation
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
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