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

graphql does not generate TypedDocumentNodes that can be inferred by TS 4.5 #621

Open
swist opened this issue Feb 24, 2022 · 0 comments
Open

Comments

@swist
Copy link

swist commented Feb 24, 2022

Hey, I'm setting up a toy project with next and graphql let. I'm unable to get the correct types to go through using TypedDocumentNode unless I do:

My setup is as follows:

#graphql-let.yml
schema: '**/*.graphqls'
documents: '**/*.graphql'
plugins:
  - typescript-operations
  - typed-document-node
cacheDir: .cache
config:
  withHooks: false
useQuery<MyQuery>(MyDocument)
#codegen.yml
schema: lib/type-defs.graphqls
documents: lib/**/*.graphql
generates:
  ./typed-document-nodes.ts:
    plugins:
      - typescript
      - typescript-operations
      - typed-document-node

Generated document from graphql-let

export declare const ViewerDocument: DocumentNode<ViewerQuery, Types.Exact<{
  [key: string]: never;
}>>;
export declare const UpdateNameDocument: DocumentNode<UpdateNameMutation, Types.Exact<{
  name: Types.Scalars['String'];
}>>;

Generated document type from graphql-codegen

export const ViewerDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Viewer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"viewer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"Partial"}},{"kind":"Field","name":{"kind":"Name","value":"status"}}]}}]}},...PartialFragmentDoc.definitions]} as unknown as DocumentNode<ViewerQuery, ViewerQueryVariables>;
export const UpdateNameDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateName"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"name"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateName"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"name"},"value":{"kind":"Variable","name":{"kind":"Name","value":"name"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"status"}}]}}]}}]} as unknown as DocumentNode<UpdateNameMutation, UpdateNameMutationVariables>;

My deps are:

{
  "private": true,
  "scripts": {
    "codegen": "graphql-let",
    "dev": "yarn codegen && next",
    "build": "yarn codegen && next build",
    "test": "yarn codegen && jest",
    "start": "next start",
    "lint": "next lint",
    "lint:fix": "next lint --fix",
    "mock": "graphql-faker ./lib/type-defs.graphqls"
  },
  "dependencies": {
    "@apollo/client": "^3.5.9",
    "@apollo/react-hooks": "^4.0.0",
    "@emotion/react": "^11.8.1",
    "@emotion/styled": "^11.8.1",
    "@graphql-tools/load-files": "6.0.18",
    "@graphql-tools/merge": "6.0.18",
    "@graphql-tools/schema": "6.0.18",
    "@mui/material": "^5.4.3",
    "@mui/x-data-grid": "^5.5.1",
    "apollo-server-micro": "^2.16.1",
    "graphql": "15.3.0",
    "next": "latest",
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "^2.6.2",
    "@graphql-codegen/import-types-preset": "^2.1.6",
    "@graphql-codegen/plugin-helpers": "^2.2.0",
    "@graphql-codegen/typed-document-node": "^2.2.5",
    "@graphql-codegen/typescript": "^2.4.5",
    "@graphql-codegen/typescript-operations": "^2.3.2",
    "@graphql-typed-document-node/core": "^3.1.1",
    "@types/jest": "^27.0.2",
    "@types/mocha": "^9.0.0",
    "@types/react": "^16.9.46",
    "@types/react-dom": "^16.9.8",
    "@types/react-test-renderer": "^17.0.1",
    "@typescript-eslint/eslint-plugin": "^5.12.1",
    "@typescript-eslint/parser": "^5.12.1",
    "babel-jest": "27.2.5",
    "eslint": "^8.9.0",
    "eslint-config-next": "12.1.0",
    "eslint-config-prettier": "^8.4.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.28.0",
    "graphql-faker": "^2.0.0-rc.25",
    "graphql-let": "^0.18.6",
    "graphql-tag": "2.11.0",
    "jest": "^27.2.5",
    "prettier": "^2.5.1",
    "react-test-renderer": "^17.0.1",
    "typescript": "^4.4.4",
    "yaml-loader": "0.6.0"
  }
}

I think it should be enough for a repro?

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

No branches or pull requests

1 participant