dotansimha / dotansimha/graphql-code-generator

Error line number are mis-reported for non *.graphql files

Open
#8,840 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/typescript-operations

### Describe the bug

With the following `graphql` file
``` graphql
query GQLQuery {
company {
id
graphqlError
}
}
```

when running a generator with
- typescript
- typescript-operations

I expected an error on line `4`. I get the following error from `graphql-code-generator`
> [FAILED] Error 0: Cannot query field "graphqlError" on type "Company".
> [FAILED] at /src/query.graphql:4:5

When I have a similar query but in a `gql` tag within javascript or typescript
``` typescript
import gql from 'graphql-tag';

const query = gql`
query TSQuery {
company {
id
tsError
}
}
`;
```

I expected an error on line `7`. I get the following error from `graphql-code-generator`
> [FAILED] Error 0: Cannot query field "tsError" on type "Company".
> [FAILED] at /src/query.ts:5:7

`graphql-code-generator` is not identifying the correct line.

I suspect this is due to parsing the queries inside of `gql` tags outside the context of parent ts/js file.

### Your Example Website or App

NA

### Steps to Reproduce the Bug or Issue

1) write a query with a bad field in a ts/js file wrapped in `gql`.

2) confirm the line number reported by 'graphql-code-generator' is not the line number for the actual syntax error.

### Expected behavior

As a user, I expect `graphql-code-generator` to tell me where exactly in the file the error is.

### Screenshots or Videos

_No response_

### Platform

- OS: Linux/MacOS
- NodeJS: v14
- `graphql` version: 16.6.0
- `@graphql-codegen/*` version(s): 2.16.4

### Codegen Config File

_No response_

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.