Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating duplicate types on fragments #33

Closed
xndyz opened this issue Feb 16, 2020 · 17 comments · Fixed by #38
Closed

Generating duplicate types on fragments #33

xndyz opened this issue Feb 16, 2020 · 17 comments · Fixed by #38
Assignees
Labels
bug Something isn't working

Comments

@xndyz
Copy link

xndyz commented Feb 16, 2020

Thank you for all the work on the v1 release! I'm experiencing duplicate types being generated when using this along with a plugin that has introspecting GraphQL like Contentful:

ERROR in /Users/fang/app/src/__generated__/gatsby-types.ts(10461,13):
10461:13 Duplicate identifier 'GatsbyContentfulSizes_withWebp_noBase64Fragment'.
    10459 | export type GatsbyContentfulSizes_withWebpFragment = Pick<ContentfulSizes, 'base64' | 'aspectRatio' | 'src' | 'srcSet' | 'srcWebp' | 'srcSetWebp' | 'sizes'>;
    10460 | 
  > 10461 | export type GatsbyContentfulSizes_withWebp_noBase64Fragment = Pick<ContentfulSizes, 'aspectRatio' | 'src' | 'srcSet' | 'srcWebp' | 'srcSetWebp' | 'sizes'>;
          |             ^
    10462 | 
    10463 | export type PagesQueryQueryVariables = {};
    10464 | 

failed Building development bundle - 50.337s

^ This is just one example, it's happening for all fragments. Is there a current workaround for this or will there need to be a fix? @cometkim

@cometkim
Copy link
Owner

Hey @Fandy , thank you for reporting this!

Can you provide some example or starter project I can test on?

@cometkim cometkim self-assigned this Feb 16, 2020
@cometkim cometkim added the bug Something isn't working label Feb 16, 2020
@xndyz
Copy link
Author

xndyz commented Feb 16, 2020

Yes if you clone https://github.com/gatsbyjs/gatsby/tree/master/examples/using-contentful and add the typegen plugin, it should error

@cometkim
Copy link
Owner

cometkim commented Feb 16, 2020

I just tested on gatsby-contentful-starter with no errors (just fixed up #35), let me try that example too.

@cometkim
Copy link
Owner

cometkim commented Feb 16, 2020

Ref apollographql/graphql-tag#278

my bad. It does not depend on apollo's graphql-tag at all

@cometkim cometkim added upstream Issue by upstream and removed upstream Issue by upstream labels Feb 16, 2020
@cometkim
Copy link
Owner

cometkim commented Feb 16, 2020

No duplicate identifiers appear in emitted plugin documents that are actually loaded.

This is likely a bug in graphql-codegen. Hey @dotansimha, Can you help me solve this problem?

config:

    {
      resolve: 'gatsby-plugin-typegen',
      options: {
        emitPluginDocuments: {
          'src/__generated__/gatsby-plugin-documents.graphql': true,
        },
      },
    },

output:

fragment GatsbyContentfulFixed on ContentfulFixed {
  base64
  width
  height
  src
  srcSet
}

fragment GatsbyContentfulFixed_tracedSVG on ContentfulFixed {
  tracedSVG
  width
  height
  src
  srcSet
}

fragment GatsbyContentfulFixed_noBase64 on ContentfulFixed {
  width
  height
  src
  srcSet
}

fragment GatsbyContentfulFixed_withWebp on ContentfulFixed {
  base64
  width
  height
  src
  srcSet
  srcWebp
  srcSetWebp
}

fragment GatsbyContentfulFixed_withWebp_noBase64 on ContentfulFixed {
  width
  height
  src
  srcSet
  srcWebp
  srcSetWebp
}

fragment GatsbyContentfulFluid on ContentfulFluid {
  base64
  aspectRatio
  src
  srcSet
  sizes
}

fragment GatsbyContentfulFluid_tracedSVG on ContentfulFluid {
  tracedSVG
  aspectRatio
  src
  srcSet
  sizes
}

fragment GatsbyContentfulFluid_noBase64 on ContentfulFluid {
  aspectRatio
  src
  srcSet
  sizes
}

fragment GatsbyContentfulFluid_withWebp on ContentfulFluid {
  base64
  aspectRatio
  src
  srcSet
  srcWebp
  srcSetWebp
  sizes
}

fragment GatsbyContentfulFluid_withWebp_noBase64 on ContentfulFluid {
  aspectRatio
  src
  srcSet
  srcWebp
  srcSetWebp
  sizes
}

fragment GatsbyContentfulResolutions on ContentfulResolutions {
  base64
  width
  height
  src
  srcSet
}

fragment GatsbyContentfulResolutions_tracedSVG on ContentfulResolutions {
  tracedSVG
  width
  height
  src
  srcSet
}

fragment GatsbyContentfulResolutions_noBase64 on ContentfulResolutions {
  width
  height
  src
  srcSet
}

fragment GatsbyContentfulResolutions_withWebp on ContentfulResolutions {
  base64
  width
  height
  src
  srcSet
  srcWebp
  srcSetWebp
}

fragment GatsbyContentfulResolutions_withWebp_noBase64 on ContentfulResolutions {
  width
  height
  src
  srcSet
  srcWebp
  srcSetWebp
}

fragment GatsbyContentfulSizes on ContentfulSizes {
  base64
  aspectRatio
  src
  srcSet
  sizes
}

fragment GatsbyContentfulSizes_tracedSVG on ContentfulSizes {
  tracedSVG
  aspectRatio
  src
  srcSet
  sizes
}

fragment GatsbyContentfulSizes_noBase64 on ContentfulSizes {
  aspectRatio
  src
  srcSet
  sizes
}

fragment GatsbyContentfulSizes_withWebp on ContentfulSizes {
  base64
  aspectRatio
  src
  srcSet
  srcWebp
  srcSetWebp
  sizes
}

fragment GatsbyContentfulSizes_withWebp_noBase64 on ContentfulSizes {
  aspectRatio
  src
  srcSet
  srcWebp
  srcSetWebp
  sizes
}


query PagesQuery {
  allSitePage(filter: { path: { ne: "/dev-404-page/" } }) {
    nodes {
      path
    }
  }
}

@cometkim
Copy link
Owner

cometkim commented Feb 16, 2020

Related with #36

@xndyz
Copy link
Author

xndyz commented Feb 16, 2020

FYI I'm not using gatsby-plugin-typography. Here is my gatsby-config if it helps.

const path = require('path')

require('dotenv').config()

module.exports = {
  plugins: [
    'gatsby-plugin-netlify-cache',
    'gatsby-plugin-sitemap',
    'gatsby-plugin-typescript',
    'gatsby-plugin-typescript-checker',
    {
      resolve: 'gatsby-plugin-sass',
      options: {
        sassRuleTest: /.^/, // match nothing
        sassRuleModulesTest: /\.s(a|c)ss$/,
      },
    },
    'gatsby-plugin-typegen',
    'gatsby-plugin-react-helmet',
    {
      resolve: 'gatsby-plugin-layout',
      options: {
        component: require.resolve('./src/pages/app.tsx'),
      },
    },
    {
      resolve: 'gatsby-plugin-alias-imports',
      options: {
        alias: {
          '@': './src/@',
          assets: './src/assets',
        },
        extensions: [],
      },
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        name: 'images',
        path: `${__dirname}/src/assets/images`,
      },
    },
    'gatsby-transformer-sharp',
    {
      resolve: 'gatsby-plugin-sharp',
      options: {
        defaultQuality: 95,
      },
    },
    'gatsby-plugin-manifest',
    'gatsby-plugin-offline',
    'gatsby-plugin-remove-trailing-slashes',
    {
      resolve: 'gatsby-source-contentful',
      options: {
        spaceId: process.env.CONTENTFUL_SPACE_ID,
        // Learn about environment variables: https://gatsby.dev/env-vars
        accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
        downloadLocal: true,
        // Need forceFullSync to keep the embedded block nodes in rich text up to date
        // See: https://github.com/gatsbyjs/gatsby/issues/10592#issuecomment-542919638
        forceFullSync: true,
      },
    },
    {
      resolve: 'gatsby-plugin-google-analytics',
      options: {
        // The property ID; the tracking code won't be generated without it
        trackingId: 'UA-150834735-1',
        // Defines where to place the tracking script - `true` in the head and `false` in the body
        head: false,
        // Avoids sending pageview hits from custom paths
        exclude: [],
      },
    },
  ],
}

I wonder if generating outside src will fix it?

@cometkim
Copy link
Owner

cometkim commented Feb 17, 2020

I wonder if generating outside src will fix it?

@Fandy Yes... It seems to be a bug associated with gatsby file-parser, but I'm not sure why. let me take a look more.

@cometkim
Copy link
Owner

Sorry. a few more several tests, even if I created a file outside of src, the same issue occurs when a document changed.

@cometkim
Copy link
Owner

cometkim commented Feb 18, 2020

There are some behaviors in the file parser that I cannot control. Calling the file parser externally was not a good idea. I will check again if it can be solved with graphql-toolkit.

@cometkim
Copy link
Owner

Hey @Fandy, can you test it again on v1.1.0? please try and let me know if the problem still happens

@xndyz
Copy link
Author

xndyz commented Feb 18, 2020

@cometkim duplicate types are still being generated in gatsby-types.ts :(

I've upgraded the plugin to the latest version.

@cometkim cometkim reopened this Feb 18, 2020
@cometkim
Copy link
Owner

duplicate types are still being generated in gatsby-types.ts :(

on using-contentful example?

@xndyz
Copy link
Author

xndyz commented Feb 18, 2020

duplicate types are still being generated in gatsby-types.ts :(

on using-contentful example?

No, it's in my repo but let me see if I can reproduce in the using-contentful example...

@xndyz
Copy link
Author

xndyz commented Feb 18, 2020

@cometkim yup, it's happening in the using-contentful example too. It's only duplicated on the Contentful fragment types.

@cometkim
Copy link
Owner

@Fandy just fixed some weird yarn 2 resolution problem, and confirmed v1.1.1 is working using-contentful example with no duplicated fragments, can you try one more?

@xndyz
Copy link
Author

xndyz commented Feb 18, 2020

Peeerfect, 1.1.1 is confirmed to be working. I tested on 1.0.1 which didn't work before. Thank you for fixing this 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants