Почему я получаю ошибку дублирующихся определений в GraphQL, когда использую только один запрос изображения? - PullRequest
0 голосов
/ 04 июня 2019

Первый раз пишу здесь, но я не могу понять это.Я создаю одностраничное приложение с Gatsby и использую GraphQL с gatsby-image и gatsby-background-image.Это работало нормально, но теперь я получаю ошибку GraphQL, в которой говорится, что у меня есть повторяющиеся запросы с тем же именем.

Я пытался развернуть сайт на страницах GitHub, чтобы показать клиента, и пытался устранить это, когда столкнулся с этой ошибкой.Я даже не уверен, где искать дубликаты.

Мои запросы в pages / index.js:

export const query = graphql`
  query{
    headerGlasses: file(relativePath: { regex: "/header-glasses/" }) {
      childImageSharp {
        fluid(maxWidth: 1000) {
          ...GatsbyImageSharpFluid
        }
      }
    }
    eyeGlasses: file(relativePath: { regex: "/eyeglasses/" }) {
      childImageSharp {
        fluid(maxWidth: 1000) {
          ...GatsbyImageSharpFluid
        }
      }
    }
    headerSunglasses: file(relativePath: { regex: "/header-sunglasses/" }) {
      childImageSharp {
        fluid(maxWidth: 1000) {
          ...GatsbyImageSharpFluid
        }
      }
    }
    skiGoggles: file(relativePath: { regex: "/ski-goggles/" }) {
      childImageSharp {
        fluid(maxWidth: 1000) {
          ...GatsbyImageSharpFluid
        }
      }
    }
    showRoom: file(relativePath: { regex: "/show1/" }) {
      childImageSharp {
        fluid(maxWidth: 1000) {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }
`

gatsby-config.js

module.exports = {
  siteMetadata: {
    title: `Diamond Opticians`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `Brendan McCaughey`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`, // This path is relative to the root of the site.
      },
    },
    `gatsby-plugin-styled-components`
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
  pathPrefix: "/diamond-opticians",
}

package.json

{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "babel-plugin-styled-components": "^1.10.0",
    "gatsby": "^2.3.15",
    "gatsby-background-image": "^0.6.2",
    "gatsby-image": "^2.0.37",
    "gatsby-plugin-manifest": "^2.0.27",
    "gatsby-plugin-offline": "^2.0.25",
    "gatsby-plugin-react-helmet": "^3.0.12",
    "gatsby-plugin-sharp": "^2.0.32",
    "gatsby-plugin-styled-components": "^3.0.7",
    "gatsby-source-filesystem": "^2.0.29",
    "gatsby-transformer-sharp": "^2.1.17",
    "google-map-react": "^1.1.4",
    "intersection-observer": "^0.7.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-helmet": "^5.2.0",
    "smooth-scroll": "^16.0.3",
    "styled-components": "^4.2.0"
  },
  "devDependencies": {
    "gh-pages": "^2.0.1",
    "prettier": "^1.16.4"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write src/**/*.{js,jsx}",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\"",
    "deploy": "gatsby build --prefix-paths && gh-pages -d public"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

layout.js

  <StaticQuery
    query={graphql`
      query SiteTitleQuery {
        site {
          siteMetadata {
            title
          }
        }
    }
    `}
    render={data => (
      <>
        <Header siteTitle={data.site.siteMetadata.title} />
        <div
          style={{
            margin: `0 auto`,
            maxWidth: `100vw`,
            paddingTop: 0,
          }}
        >
          <main>{children}</main>
          <Footer>
            © {new Date().getFullYear()} Diamond Opticians
          </Footer>
        </div>
      </>
    )}
  />
)

Страница загружалась нормально раньше.Теперь, внезапно, я получаю эту ошибку:

GraphQL Error There was an error while compiling your site's GraphQL queries.
  Error: RelayParser: Encountered duplicate defintitions for one or more documents: each document must have a unique name. Duplicated documents:
- cUsersBrendCodingProjectsDiamondOpticiansSrcPagesIndexJs3730803733

Я также сталкиваюсь с этой ошибкой, которая, кажется, происходит от пары моих узловых модулей:

Uncaught TypeError: Невозможно прочитать свойство headerGlasses с неопределенным значением

Я предположил, что это было результатом того, что запрос не был выполнен из-за вышеуказанной проблемы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...