gatsby-plugin-react-i18next icon indicating copy to clipboard operation
gatsby-plugin-react-i18next copied to clipboard

Alternative for query in every page

Open mfcoxo opened this issue 3 years ago • 4 comments

Is there a way to migrate from 0.2.x to 1.x without having to add the same query to every single page just to get the same behaviour as before? Would be great not to have this code repeated dozens of times in the codebase.

mfcoxo avatar Mar 11 '21 22:03 mfcoxo

This is something we all need I guess. 🙌

yurist38 avatar Mar 16 '21 09:03 yurist38

+1, this made migrating to the new plugin much more of a pain and makes the queries on many of our sub pages much less clean.

stevepepple avatar Mar 30 '21 22:03 stevepepple

+1, and I get that error and I don't know why:

Screen Shot 2021-04-09 at 11 05 48 PM

ufukomer avatar Apr 09 '21 20:04 ufukomer

👋 Bit of a time has passed but I found using a graphql fragment made this a bit cleaner:

Include this in a js file somewhere in the src/ directory (like /src/fragments/locales.js):

import { graphql } from "gatsby"

// This should be your allLocale query that you want to include everywhere
export const query = graphql`
  fragment Locales on Query {
    locales: allLocale {
      edges {
        node {
          ns
          data
          language
        }
      }
    }
  }
`

and then on your page queries you can do:

query {
    ...Locales
}

Pjaerr avatar Apr 20 '23 14:04 Pjaerr