I'm currently working with two GraphQL sources - one for fluid images and the other for characters stored in a MongoDB database. My main task involves mapping these characters onto a page, using their names as filters to retrieve the corresponding image (based on the "originalName" field). Here is what my query looks like:
query MyQuery {
allMongodbMobileLegendsdevChamps {
nodes {
name
}
}
allImageSharp(filter: {fluid: {originalName: {eq: "characterName.jpg"}}}) {
nodes {
fluid {
...allImageSharpFluid
}
}
}
}
const Index = ({ data }) => {
const {
allMongodbMobileLegendsdevChamps: { nodes: champs },
allImageSharp: { nodes: fluid },
} = data
return (
<section className={grid}>
{champs.map(champ => {
return (
<Link to={`/champ/${champ.name}`}>
<Image fluid={fluid.fluid} />
<h3>{champ.name}</h3>
</Link>
)
})}
</section>
)
}
If I were not using GraphQL, I would simply set the src attribute of the image to `"champ.name"` like this:
<Image src = `/path/to/img/${champ.name}.jpg` />
How can I filter my image query with the champ.name? Would utilizing Apollo be beneficial for this scenario?