首页 > 解决方案 > 如何在使用 Gatsby.js 的 useStaticQuery 中使用内联片段?

问题描述

我想使用来自 gatsbyJs 和 Graphql 的 useStaticQuery 钩子来获取我的 github 中每个存储库的提交计数。收到此错误:Unknown type "Commit".对于此查询:


const {
    github: {
      viewer: {
        repositories: { edges },
      },
    },
  } = useStaticQuery(
    graphql`
      {
        github {
          viewer {
            repositories(first: 6, orderBy: { field: STARGAZERS, direction: DESC }) {
              edges {
                node {
                  stargazers {
                    totalCount
                  }
                  object(expression: "master") {
                    ... on Commit {
                      history(first: 1) {
                        edges {
                          node {
                            committedDate
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    `
  );

标签: javascriptgithubgraphqlgatsby

解决方案


推荐阅读