dotansimha / dotansimha/graphql-code-generator

Fragments do not contain source body

Open
#6,289 1 comment 3 reactions 0 assignees View on GitHub
core stage/0-issue-prerequisites
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

Given a simple fragment,
```graphql
fragment Fragment on Something {
value
}
```
the following query uses it via the generated code:
```js
import { FragmentFragmentDoc } from 'generated'

const Query = gql`
query Query {
something {
...Fragment
}
}
${FragmentFragmentDoc}`
```
However, this throws an error `arg.loc` not defined in the `gql` method.

Indeed, in `gql` the following code https://github.com/apollographql/graphql-tag/blob/2b99a7c31a52a8e4927cc01c47bdc11e0539085f/src/index.ts#L125-L126 tries to access `FragmentFragmentDoc.loc.source.body` to append the fragment body to the query. However, the generated code is of the form
```
export const FragmentFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"Fragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Something"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Article"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"abstract"}},{"kind":"Field","name":{"kind":"Name","value":"author"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Person"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Organization"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"journal"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]} as unknown as DocumentNode;
```
and doesn't contain `loc`.

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.