Skip to content

preset near-operation-file ignores typechecking #214

@klyve

Description

@klyve

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions