dotansimha / dotansimha/graphql-code-generator

Using fragments results in blank object

Open
#8,271 1 comment 4 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

### Describe the bug

I am using
"@graphql-codegen/typescript-apollo-angular": "^3.5.3"
"apollo-angular": "^4.0.1"
"graphql": "^16.5.0"
with angular 14.1.2. I have a simple query that fetches an array of objects. If I inline all the attributes in the query object then everything works fine but if I extract some attributes out to a fragment and try to use that fragment, I receive the correct number of objects in the array but they are all empty. I am using the auto generated class to fetch the list. What's interesting is the fact that network call seems to have the correct response in devtools but when I get the data from .watch().valueChanges it strips the objects of any attributes. Simple changing the query to use attributes instead of fragment works fine. I ran the same query with fragment in the playground and it all works fine.

I have tried finding a way to create a minimal stackblitz with client side .graphql file but can't find a good starting point.

### Your Example Website or App

Local Angular app

### Steps to Reproduce the Bug or Issue

1. Create a local .graphql file with a query that returns an array of objects.
2. extract out the object attributes into a fragment and use that fragment inside the query
3. Use .watch().valueChanges to retrieve data
4. The objects are all blank.

### Expected behavior

The returned objects have all the attributes of the fragment.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: v16.15.1
- `graphql` version: 16.5.0
- `@graphql-codegen/*` 2.11.6
- `Angular 14.1.2`

### Codegen Config File

overwrite: true
schema: http://localhost:3000/graphql
documents: './graphql/**/*.graphql'
generates:
./src/app/admin/graphql/generated/graphql.ts:
plugins:
- typescript
- typescript-operations
- typescript-apollo-angular

### 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.