I am using nextJS for my frontend with apollo and a graphql. And I fetching my queries using the getStaticProps() function. To increase modularity and maintainability I break my queries into multiple queries.
I have a folder structure like:
src/queries getPost.js getMenu.js getProduct.js index.js
And their all queries are put and exported into index.js. The problem is because of multiple queries in the queries folder I am only able to fetch one query at a time.
import { getPost } from ‘../src/queries’;
This is how I am fetching query using :
export const getStaticProps = async () => { const { data } = await client.query({ query: getPost, }); return { props: { data: { post: data.post.edges } }, revalidate: 60, }; };
I want to fetch multiple queries like getPost and getProduct. Please help me to achieve this.
Advertisement
Answer
change that => data.posts.edges
export const getStaticProps = async () => { const { data } = await client.query({ query: getPost, }); return { props: { data: { post: data.posts.edges } }, revalidate: 60, }; };