apollographql / apollographql/apollo-tooling

Generating flowtypes with a graphql input puts generated type in every generated file

Open
#988 5 comments 6 reactions 0 assignees View on GitHub
🤖 component - codegen
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

**Intended outcome:**

I'm trying to generate flow types for a mutation. I have the following mutation:

```graphql
input PlaceOrderMutationInput {
# ... some fields
}
mutation {
placeOrder(input: PlaceOrderMutationInput!)
}
```

When I define a graphql mutation client-side like this:

```js
const PLACE_ORDER_MUTATION = gql`
mutation PlaceOrder($input: PlaceOrderMutationInput!) {
placeOrder(input: $input) {
# some fields, not relevant
}
}
`
```
I expect that types for `PlaceOrderMutationInput` will **only** be generated in the `PlaceOrder.js`file.

**Actual outcome:**
Every single other file generated by apollo codegen in my project also contains the `PlaceOrderMutationInput` type. This seems incorrect, and is annoying as it adds a huge amount of noise to git diffs etc.

**How to reproduce the issue:**

The command I'm running is:
```
apollo client:codegen --addTypename --includes='src/**/*.js' --target=flow --localSchemaFile='src/js/gql/schema.json' types
```
**Versions**
`apollo@2.4.4`

Thanks very much!

Contributor guide

Open the contributing guide

Research direction

Start with the `apollo client:codegen` command shown in the issue and trace the Flow target's handling of the `PlaceOrderMutationInput` input type. Compare the generated files for the reproduction and identify the relevant code-generation tests, if present. Done means the input type appears only in `PlaceOrder.js` while other generated files remain free of it.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.