dotansimha / dotansimha/graphql-code-generator

Scalars generated as independent types

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

Description

### Is your feature request related to a problem? Please describe.

I'm using code generator to generate SDK for certain predefined queries for a very large graphql schema ( Gitlab ).

For that purpose I'm using `onlyOperationTypes: true` however even in this case it generates all enums and all types as it's described in #10232 .

So I solved my problem by use of [knip.dev ](https://knip.dev/) tool which is if run like `knip --fix --exports` removing exports from unused types and then in combination with bundler it makes a perfect result only bundling used types to d.ts file

However there is still a problem.

Gitlab is using many different scalars ( like logical separation for different uids ). Because gcg creates Scalars like this:

```
/** All built-in and custom scalars, mapped to their actual values */
type Scalars = {
ID: { input: string; output: string; }
String: { input: string; output: string; }
Boolean: { input: boolean; output: boolean; }
Int: { input: number; output: number; }
Float: { input: number; output: number; }
/**
* A `AbuseReportID` is a global ID. It is encoded as a string.
*
* An example `AbuseReportID` is: `"gid://gitlab/AbuseReport/1"`.
*/
AbuseReportID: { input: string; output: string; }
/**
* A `AchievementsAchievementID` is a global ID. It is encoded as a string.
*
* An example `AchievementsAchievementID` is: `"gid://gitlab/Achievements::Achievement/1"`.
*/
AchievementsAchievementID: { input: string; output: string; }
/**
* A `AchievementsUserAchievementID` is a global ID. It is encoded as a string.
*
* An example `AchievementsUserAchievementID` is: `"gid://gitlab/Achievements::UserAchievement/1"`.
*/
AchievementsUserAchievementID: { input: string; output: string; }
/**
* A `AiAgentID` is a global ID. It is encoded as a string.
*
* An example `AiAgentID` is: `"gid://gitlab/Ai::Agent/1"`.
*/
AiAgentID: { input: string; output: string; }
/**
* A `AiAgentVersionID` is a global ID. It is encoded as a string.
*
* An example `AiAgentVersionID` is: `"gid://gitlab/Ai::AgentVersion/1"`.
*
...
```

those types are exported as one single type and cannot be excluded separately.

Therefore I'd like to find the way how to export only those Scalar types which are required.

### Describe the solution you'd like

Possible solution is to introduce an option like `standaloneScalarTypes` which can be prefixed like Scalar_ or may be even wrapped into Scalars [namespace ](https://www.typescriptlang.org/docs/handbook/namespaces.html) instead.

This would allow us to exclude not used scalar types and only export what is in real use. The size of the bundle will reduce significantly.

What do you think of this idea?

### Describe alternatives you've considered

_No response_

### Any additional important details?

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