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

Remove *.gql/*.graphql types #881

Merged
merged 1 commit into from
Jul 27, 2020
Merged

Remove *.gql/*.graphql types #881

merged 1 commit into from
Jul 27, 2020

Conversation

jthomaschewski
Copy link

The *.graphql module declaration conflicts with similar declarations in many projects. And in my opinion it's out of the scope of this library. I will try to explain my reasoning:

Unfortunately TypeScript doesn't have an option to exclude types from NPM packages. So these these types are loaded without a way to opt-out.
But many projects might have different needs for *.graphql typings. e.g:

  • Add specific modules for every *.graphql file
    The populare tool "Graphql Code Generator" can autogenerate imports for graphql-files, example here: https://graphql-code-generator.com/docs/plugins/typescript-graphql-files-modules#example

  • Allow named imports from *.graphql-files (e.g Queries & Mutations) using graphql-tag/loader:
    e.g import { SomeQuery, AnotherQuery } from 'somefile.graphql'.
    One way to allow this is by a simple any declaration:
    declare module '*.graphql';

  • Not every typescript project has some loader configured to load *.graphql-files.
    So having these types by default makes incorrect assumptions.

These kind of custom declarations are not possible when using vue-apollo 3.x due to this fixed type which is bundled with vue-apollo.

I propose to just remove the type file again and add docs which explain the situation.

Failing example

import {SomeQuery} from 'somefile.graphql'

export default {
  apollo: {
    someQuery: {query: SomeQuery},
  },
}

Error:

ERROR in MyModule.vue(14,3):
 14:3 Module '"*.graphql"' has no exported member 'SomeQuery'. Did you mean to use 'import SomeQuery from "*.graphql"' instead?
  > 14 |   SomeQuery,
          |   ^
      15 | } from './somefile.graphql';
      16 |

Workaround

Downgrade and pin 3.0.0-rc.7. Packge json:

"vue-apollo": "=3.0.0-rc.7",

these types conflict with similar declarations in many projects
@jthomaschewski
Copy link
Author

I know it's been a while, but I still think this is an issue and should be fixed - maybe in the 4.x version, as this might be considered a breaking change.

@Kocal
Copy link
Contributor

Kocal commented Jun 22, 2020

Hi,

As a temporary workaround (I hope), I added the following lines in my package.json:

{
  "scripts": {
    "postinstall": "rm -f node_modules/vue-apollo/types/gql.d.ts"
  }
}

The file vue-apollo/types/gql.d.ts will be deleted when installing the dependencies.

@Akryum Akryum merged commit f2366ce into vuejs:dev Jul 27, 2020
@ferm10n
Copy link

ferm10n commented Aug 12, 2020

I lost about a couple of hours today trying to hunt down why type defs couldn't be resolved for any .gql files because of this. It's all sorted out now, but it was quite frustrating finding the one commit that had automatically updated vue-apollo from 3.0.3 to 3.0.4 and broke our build.

I would have preferred this was included in 4.x as @JBBr suggested. I'm hoping greater care will be taken in future releases. That said, I appreciate the awesome work you guys are doing. Many thanks.

@jthomaschewski jthomaschewski deleted the patch-1 branch March 11, 2021 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants