apollographql / apollographql/apollo-tooling

codegen:generate Global typings error in Angular workspace

Open
#1,310 0 comments 1 reaction 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:**

With Angular we can end up with multiple interconnected projects in one workspace. What I would expect is, that even if libraries depend on one another, autogenerated code would not break once built in the `dist` and consumed by the application.

**Actual outcome:**

When we build the libraries, there is no error, however once we try to consume them with application, the error appears, because the paths in autogenerated code are obviously wrong, since they relatively point to root `__generated__` folder from their source origin, while currently located in the `dist` folder.

**How to reproduce the issue:**

- Clone the following repo: https://github.com/klemenoslaj/apollo-codegen-globaltypings-problem
- Install dependencies
- Execute `yarn codegen` (_apollo codegen:generate_)
- Execute `yarn ng build library` (_builds library1_)
- Execute `yarn ng serve`(_serves the application_)
- Following error appears: `ERROR in dist/library1/lib/__generated__/ExampleFragment.d.ts(1,29): error TS2307: Cannot find module './../../../../../__generated__/globalTypes.d'.`

Question: Maybe importing the file with a path relative to the project root instead would do the trick?

**Versions**

apollo/2.12.5 darwin-x64 node-v10.16.0

Contributor guide

Open the contributing guide

Research direction

Clone the linked reproduction repository, install dependencies, and run `yarn codegen`, `yarn ng build library`, then `yarn ng serve`. Start from the `apollo codegen:generate` entry point and inspect the generated declaration path shown in the TS2307 error. Done means the built library can be consumed by the application without the missing `globalTypes.d` error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, graphql, typescript
Domain
build-system, frontend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.