Source plugin for pulling documents into Gatsby 2 from a Strapi API.
npm install --save gatsby-source-strapi-localized
// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-source-strapi`,
options: {
apiURL: `http://localhost:1337`,
contentTypes: [`article`, `user`],
availableLngs: ['en', 'de'],
// Possibility to login with a strapi user, when content types are not publically available (optional).
loginData: {
identifier: '',
password: '',
},
},
},
]
You need create fields like title__en
and title__de
You can query Document nodes created from your Strapi API like the following:
{
allStrapiArticles {
edges {
node {
id
locales {
title
content
lng
}
}
}
}
}
and the response will be like:
...
{
"id": "Strapi__Articles__5bb61765593d462a14cabeb4",
"locales": [
{
"title": "...",
"content": "...",
"lng": "en"
},
{
"title": "...",
"content": "...",
"lng": "de"
}
]
}
...