Help us understand the problem. What is going on with this article?

Gatsby 1つのページで複数のクエリを実行する方法

1つのページでお知らせやブログなど複数のコンテンツを表示したい場合はクエリを複数作成することができる。

サイドバー用のカテゴリ一覧など複数ページで共通のデータを使う場合はstaticQueryを使ってコンポーネントごとにクエリを実行する。

複数クエリを1つのページで実行する

複数クエリの実行は頭に名前をつけるだけ。名前は自由。

post: allMarkdownRemark(){}
import React from "react"
import { graphql } from "gatsby"

const MultipleQuery = ({ data }) => {
  const post = data.post
  const portfolio = data.portfolio
  const siteTitle = data.siteMetaData.siteMetadata.title

  console.log(data)

  return (
    <h1>test</h1>
  )
}

export default MultipleQuery

export const query = graphql`
  query {
    post: allMarkdownRemark(
      limit: 3
      sort: { order: DESC, fields: [frontmatter___date] }
      filter: { frontmatter: { type: { eq: "blog" } } }
    ) {
      edges {
        node {
          frontmatter {
            title
            path
          }
        }
      }
    }
    portfolio: allMarkdownRemark(
      sort: { order: DESC, fields: [frontmatter___date] }
      filter: { frontmatter: { type: { eq: "portfolio" } } }
    ) {
      edges {
        node {
          frontmatter {
            title
            path
          }
        }
      }
    }
    siteMetaData: site {
      siteMetadata {
        title
      }
    }
  }
`;
takeshi_du
フリーランスのフロントエンドエンジニア&デザイナー。EC-CUBE4向けプラグイン「UICube」開発者。WooCommerceやEC-CUBE、BASE、ShopifyなどのECサイト構築・デザインが得意。
https://homupedia.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした