Comments (15)
@jan-wagenaar if you are dealing with a large dataset, that is indeed not a solid solution... This needs to be addressed to the core-team, imo...
from plugins.
Seems that this is due to the fact that the nodes are wrapped in a data object. So the node that includes the slug is returned, which is in fact everything. But.... Correct me if I'm wrong.
from plugins.
@jan-wagenaar These queries are made in the graphql playground from gatsby.
So that's how the queries need to be build...I guess?
There is no other way to get those slug/title/description...
from plugins.
@jan-wagenaar These queries are made in the graphql playground from gatsby. So that's how the queries need to be build...I guess? There is no other way to get those slug/title/description...
I also encounter this problem and don't know how to solve itπ
from plugins.
@gzhanghui actually happy to see I'm not the only one :)
from plugins.
@jan-wagenaar These queries are made in the graphql playground from gatsby. So that's how the queries need to be build...I guess? There is no other way to get those slug/title/description...
Yeah I do not know an workaround either. RIght now I'm retrieving everything and use an array.filter() to get the right item. But definitely feels too hacky.
from plugins.
Is your query for a page?
In that case, one thing you should try if it's possible to use the Gatsby Node API to filter the data on build time. Then pass a custom object to your screen.
edit: see gatsby docs: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/
from plugins.
It's for a page, off course, but gatsby node api needs the same query as far as I know...
from plugins.
That right, but in the gatsby-node.js code you may be able to implement custom logic.
I will try it for myself. Ofcourse, this is a temporary workaround....
from plugins.
That could work yes...
create a clone of the nodes[0].data array
and the custom logic would be to find the current node again in the cloned array, use that data to pas it to the template an remove that from the cloned array again; so that on the next cycle of the foreach, it will find it's data faster and faster.
but not a solid solution yet no :)
from plugins.
Nice I was able to use this as an workaround. My code:
const { data } = await graphql(`
query {
allStrapiWorks {
nodes {
data {
id
attributes {
slug
name
description
}
}
}
}
}
`)
data.allStrapiWorks.nodes[0].data.forEach(node => {
const slug = node.attributes.slug
actions.createPage({
path: `/work/${slug}`,
component: require.resolve(`./src/templates/work-detail.js`),
context: {
workItem: node.attributes
},
})
})
}
In your component use pageContext to get the passed object:
function Product({ pageContext }) {
const { workItem} = pageContext
return (
<div>
Name: {workItem.name}
Description: {workItem.description}
</div>
)
}
from plugins.
Thank you so much! I was stuck on this issue for the last two weeks... This solved all my query issues!
from plugins.
I'm currently faced this issue, and figured out a way to get single data in the gatsby-graphql with new node like this:
graphQL
query Articles {
strapiArticle(data: {id: {eq: 3}}) {
data {
id
attributes {
publishDate
}
}
id
}
strapiArticles {
data {
attributes {
publishDate
}
id
}
id
}
}
data
{
"data": {
"strapiArticle": {
"data": {
"id": 3,
"attributes": {
"publishDate": "2022-02-10"
}
},
"id": "21e77627-27c5-5f52-b0c4-62aa23ccfcf9"
},
"strapiArticles": {
"data": [
{
"attributes": {
"publishDate": "2022-01-30"
},
"id": 1
},
{
"attributes": {
"publishDate": "2022-02-01"
},
"id": 2
},
{
"attributes": {
"publishDate": "2022-02-10"
},
"id": 3
}
],
"id": "Articles_undefined"
}
},
"extensions": {}
}
strapiArticles is the original node which the gatsby-source-strapi made for us.
strapiArticle is the one created with gatsby-node.js, and we can get single data with query variable $id
.
The workaround here is to get out the data (inside the array), and then generate a new node with Gatsby node API createNode
.
gatsby-node.js
module.exports.onCreateNode = async ({ node, actions, createNodeId, createContentDigest }) => {
const { createNode } = actions;
if(node.internal.type === "StrapiArticles") {
node.data.forEach(d => {
const newNode = {
data: d,
id: createNodeId(`StrapiArticle-${d.id}`),
parent: node.id,
children: [],
internal: {
type: "StrapiArticle",
contentDigest: createContentDigest(d)
},
};
createNode(newNode);
})
}
};
References
Gatsby Node APIs
onCreateNode
Gatsby Actions
createNode
Node Interface
contentDigest
Node API Helper
createContentDigest
createNodeId
from plugins.
This is very annoying to be honest. Could you please let me know when we can expect a fix.
Actually if it matches on two elements it is returning two sets of results.
from plugins.
I am assuming this is Strapi 4 data fetched (because of the .data.attributes
blocks) by version 1 of gatsby-source-strapi
which only supports Strapi 3. Please create a new issue with new info if you think otherwise.
from plugins.
Related Issues (20)
- bug(gatsby-source-strapi): Request failed with status code 500 HOT 4
- bug(gatsby-source-strapi): fetching content twice (via relationships) fails to transform to Markdown HOT 2
- feat(gatsby-source-strapi): Transform markdown images in-place HOT 1
- bug(gatsby-source-strapi): queryLimit breaks incremental build HOT 4
- bug(gatsby-strapi-source): With external and Strapi images in Markdown, some Strapi images are missing/blended HOT 1
- bug(gatsby-source-strapi): The plugin "gatsby-source-strapi" created a node of a type "File" owned by "gatsby-source-filesystem". HOT 36
- bug(<gatsby-source-strapi>): <"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle> HOT 1
- bug(gatsby-source-strapi): updating a JSON fields gets lost HOT 1
- feat(gatsby-source-strapi): Generated Types HOT 7
- bug(gatsby-plugin-fastify): `assetPrefix` Not Working HOT 3
- feat(gatsby-source-strapi): timeout setting for queries HOT 2
- bug(gatsby source strapi): Components within Dynamic Zones are not "getting through" HOT 4
- bug(gatsby-source-airtable): Duplicate Dot in File Extension HOT 4
- bug(gatsby-plugin-fastify): Error fetching page data for /using-ssr when pagePrefix is set HOT 5
- bug(gatsby-plugin-fastify): Doesn't work as expected for SSR pages HOT 6
- bug(gatsby-plugin-fastify): Server function throws 'stream.on is not a function' after being called. HOT 4
- bug(gatsby-plugin-fastify): SSR pages don't work at all on Gatsby-Wordpress site HOT 1
- feat(gatsby-source-strapi): support for Strapi 5
- bug(gatsby-source-strapi): GraphQL fragment queries only work if all possible components of a dynamic zone are actually used in the current content HOT 2
- bug(gatsby-source-strapi): can't get strapi component data HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plugins.