Accessing the first, last, or middle item in my graphql query
See original GitHub issueI have a graphql query grabbing every image inside a folder in my project. I am currently grabbing all images at once and it works.
const data = useStaticQuery(graphql `
query {
allFile(filter:{extension:{regex:"/(jpeg|jpg|gif|png)/"}, sourceInstanceName:{eq:"images"}}) {
edges {
node {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`)
{this.props.data.allFile.edges.map(({ node }) => (
<Img fluid={node.childImageSharp.fluid}/>
))}
Is there a way to grab the first, last, or middle image out of that query?
Something like this.props.data.allFile.edges.node[0].childImageSharp.Fluid
? I know that isn’t correct syntax, but is there something that can achieve this?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
3. Execute your first query - Apollo GraphQL Docs
Click this button to add the query to the middle "operations" panel: ... This is probably the easiest way to add fields to...
Read more >Understanding Queries in GraphQL - DigitalOcean
In this tutorial, we'll take an in-depth look at queries in GraphQL so that you better understand how to retrieve data from a...
Read more >GraphQL Tutorial: how to use fields, fragments, and more
GraphQL allows you to go beyond this simple operation with complex queries that navigate nested objects or modify fetched data using object ......
Read more >GraphQL API - The Graph Docs
When querying a collection, the first parameter can be used to paginate from the beginning of the collection. It is worth noting that...
Read more >Queries and Mutations - GraphQL
In that case, you can make a sub-selection of fields for that object. GraphQL queries can traverse related objects and their fields, letting...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@brandontb12 i’ve picked up on your issue and i’m going to detail the steps taken to triage it.
random-images
gatsby-config.js
plugins to look up for the folder where my images are, turning it into:src\pages\index.js
to the following:gatsby develop
for a development build, or create a production build and serve it, emulating a production server withgatsby build && gatsby serve
will display the items accordingly.I’ve created a GitHub repo with the code, so that you can go about it at your own pace.
Feel free to provide feedback so that we can close this issue or continue to work on it until we find a suitable solution
Thanks for jumping in @jonniebigodes ! ❤️