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

preset near-operation-file ignores typechecking #214

Closed
klyve opened this issue Aug 11, 2022 · 1 comment
Closed

preset near-operation-file ignores typechecking #214

klyve opened this issue Aug 11, 2022 · 1 comment

Comments

@klyve
Copy link

klyve commented Aug 11, 2022

Describe the bug

When working with the preset near-operation-file there is no typechecking done for the validity of the queries.
Currently it will report errors if the query / mutation is not found, or if the fields selected are not found. It does not however typecheck for arguments or fragments and will happily generate wrong code with invalid fragments or arguments.

Your Example Website or App

https://github.com/klyve/graphql-codegen-preset-test

Steps to Reproduce the Bug or Issue

Given the following codegen yaml

generates:
  generated:
    documents: "*.graphql"
    preset: near-operation-file
    presetConfig:
      extension: .generated.ts
      baseTypesPath: ./types.ts
    plugins:
      - typescript-operations
      - typescript-react-apollo
    config:
      withHooks: true
    schema: ./schema.graphql

The schema

schema {
  mutation: Mutation
  query: Query
}

type User {
  id: ID!
  name: String!
}

input CreateUserInput {
  name: String!
}

type Query {
  user(id: ID!): User!
}

type Mutation {
  createUser(input: CreateUserInput!): User!
}

And the near-operation file:

mutation CreateUser($input: CreateUserInput!) {
  createUser(unknown: $unknown) {
    ...UNKNOWN_FRAGMENT
  }
}

Running this through codegen with the preset near-operation-file
results in no errors but the expected result is:

  • unknown is not an argument
  • UNKNOWN_FRAGMENT does not exist in the schema

As observed it skips the typechecking and generates code for the invalid file

Expected behavior

Expected behavior is for codegen to do typechecking for the near operation files and report errors if any of the queries have the wrong arguments or fields.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 16.16.0
  • @graphql-codegen/cli: 2.11.5
  • @graphql-codegen/introspection: 2.2.1
  • @graphql-codegen/near-operation-file-preset: 2.4.1
  • @graphql-codegen/typescript: 2.7.3
  • @graphql-codegen/typescript-operations: 2.5.3
  • @graphql-codegen/typescript-react-apollo: 3.3.3
  • graphql: 16.5.0

Codegen Config File

overwrite: true
generates:
tests/generated:
documents: "tests/*.graphql"
preset: near-operation-file
presetConfig:
extension: .schema.ts
baseTypesPath: ./graphqlTypes.ts
plugins:
- typescript-operations
- typescript-react-apollo
config:
withHooks: true
schema: ./schema.graphql

Additional context

No response

@dotansimha dotansimha transferred this issue from dotansimha/graphql-code-generator Feb 5, 2023
sachalifs pushed a commit to sachalifs/graphql-code-generator-community that referenced this issue Aug 8, 2023
@saihaj saihaj closed this as completed in 9a692da Sep 11, 2023
saihaj added a commit that referenced this issue Sep 25, 2023
…on config parameter. Closes #214 (#383)"

This reverts commit 9a692da.
saihaj added a commit that referenced this issue Sep 25, 2023
…on config parameter. Closes #214 (#383)"

This reverts commit 9a692da.
saihaj added a commit that referenced this issue Sep 25, 2023
…on config parameter. Closes #214 (#383)" (#413)

This reverts commit 9a692da.
saihaj added a commit that referenced this issue Sep 25, 2023
…Validation config parameter. Closes #214 (#383)" (#413)"

This reverts commit 5739a0e.
@saihaj saihaj reopened this Sep 25, 2023
@saihaj
Copy link
Collaborator

saihaj commented Sep 25, 2023

if someone wants to revive this one #414

@saihaj saihaj closed this as completed in 02d487c Sep 25, 2023
saihaj added a commit that referenced this issue Sep 25, 2023
* feat (msw) withSuffix param

* edit (msw) package version increasement

* add changeset

* Revert "chore(release): update monorepo packages versions (#349)" (#411)

This reverts commit dd930f7.

* Revert "fix(preset/near-operation-file): accept skipDocumentsValidation config parameter. Closes #214 (#383)" (#413)

This reverts commit 9a692da.

* chore(deps): update dependency jest-junit to v16 (#357)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency rimraf to v5 (#325)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* feat(typescript-rtk-query): add addTransformResponse to config (#267)

* feat: add addTransformResponse to config

* docs: add changeset

* fix: changeset from path to minor

* fix: move subscription block before generation

* fix: prettier issue

---------

Co-authored-by: Dominic <dominic@nomanini.com>

* changes to dev tests

* fix(preset/near-operation-file): accept skipDocumentsValidat (#414)

* Revert "Revert "fix(preset/near-operation-file): accept skipDocumentsValidation config parameter. Closes #214 (#383)" (#413)"

This reverts commit 5739a0e.

* fix(preset/near-operation-file): read skipDocumentsValidation from config (#409)

* fix(preset/near-operation-file): add skipDocumentsValidation presetConfig types

* Create brave-bulldogs-explode.md

* fix(preset/near-operation-file): read skipDocumentsValidation from config

* Update brave-bulldogs-explode.md

* Delete .changeset/brave-bulldogs-explode.md

---------

Co-authored-by: Herman Bilous <herman.belous@gmail.com>

* chore(deps): update dependency patch-package to v8 (#417)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update dependency @urql/introspection to v1.0.2 (#321)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(graphql-request): return errors in return type for rawRequest (#408)

* fix(graphql-request): return errors in return type when rawRequest is true

* add changeset

* generate examples

* chore(deps): update typescript-eslint monorepo to v5.62.0 (#288)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency @apollo/client to v3.8.4 (#292)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update babel monorepo (#299)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency @changesets/cli to v2.26.2 (#310)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency lint-staged to v14 (#416)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency @reduxjs/toolkit to v1.9.6 (#346)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update package.json

---------

Co-authored-by: Saihajpreet Singh <saihajpreet.singh@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dominic Gunther Bauer <46312751+DominicGBauer@users.noreply.github.com>
Co-authored-by: Dominic <dominic@nomanini.com>
Co-authored-by: Herman Bilous <herman.belous@gmail.com>
Co-authored-by: dseeto <dseeto@users.noreply.github.com>
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

2 participants