Skip to content

Ts-codegen alpha version release Draft #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .azure-devops/graphitation-release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pr: none
trigger:
- main
- jvejr/ts-codegen-subtype-alpha-release
- alloy/relay-apollo-duct-tape

variables:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"lint": "lage lint --continue",
"lage": "lage",
"ci": "yarn lage build types test lint && yarn checkchange",
"beachball": "beachball -b origin/main",
"beachball": "beachball -b origin/jvejr/ts-codegen-subtype-alpha-release",
"change": "yarn beachball change",
"checkchange": "yarn beachball check",
"release": "yarn beachball publish -t latest",
"release": "yarn beachball publish -t alpha",
"postinstall": "patch-package"
},
"devDependencies": {
Expand Down
66 changes: 66 additions & 0 deletions packages/cli/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,72 @@
{
"name": "@graphitation/cli",
"entries": [
{
"date": "Tue, 15 Apr 2025 13:35:07 GMT",
"version": "2.1.0-alpha.2",
"tag": "@graphitation/cli_v2.1.0-alpha.2",
"comments": {
"none": [
{
"author": "beachball",
"package": "@graphitation/cli",
"comment": "Bump @graphitation/ts-codegen to v3.1.0-alpha.3",
"commit": "not available"
}
]
}
},
{
"date": "Mon, 17 Mar 2025 14:45:57 GMT",
"version": "2.1.0-alpha.2",
"tag": "@graphitation/cli_v2.1.0-alpha.2",
"comments": {
"prerelease": [
{
"author": "[email protected]",
"package": "@graphitation/cli",
"commit": "c9e29a0d662b1e728faf43ec341453dd54060a97",
"comment": "Return namespaced type"
}
]
}
},
{
"date": "Mon, 17 Mar 2025 13:09:38 GMT",
"version": "2.1.0-alpha.1",
"tag": "@graphitation/cli_v2.1.0-alpha.1",
"comments": {
"none": [
{
"author": "beachball",
"package": "@graphitation/cli",
"comment": "Bump @graphitation/ts-codegen to v3.1.0-alpha.2",
"commit": "not available"
}
]
}
},
{
"date": "Tue, 04 Mar 2025 14:17:11 GMT",
"version": "2.1.0-alpha.1",
"tag": "@graphitation/cli_v2.1.0-alpha.1",
"comments": {
"prerelease": [
{
"author": "[email protected]",
"package": "@graphitation/cli",
"commit": "fb824e93c1b429874ca72516590d566daa4a13f1",
"comment": "ts-codegen context subtype v2"
},
{
"author": "beachball",
"package": "@graphitation/cli",
"comment": "Bump @graphitation/ts-codegen to v3.1.0-alpha.1",
"commit": "not available"
}
]
}
},
{
"date": "Wed, 19 Feb 2025 14:18:14 GMT",
"version": "2.0.0",
Expand Down
19 changes: 18 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
# Change Log - @graphitation/cli

<!-- This log was last generated on Wed, 19 Feb 2025 14:18:14 GMT and should not be manually modified. -->
<!-- This log was last generated on Mon, 17 Mar 2025 14:45:57 GMT and should not be manually modified. -->

<!-- Start content -->

## 2.1.0-alpha.2

Mon, 17 Mar 2025 14:45:57 GMT

### Changes

- Return namespaced type ([email protected])

## 2.1.0-alpha.1

Tue, 04 Mar 2025 14:17:11 GMT

### Changes

- ts-codegen context subtype v2 ([email protected])
- Bump @graphitation/ts-codegen to v3.1.0-alpha.1

## 2.0.0

Wed, 19 Feb 2025 14:18:14 GMT
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@graphitation/cli",
"license": "MIT",
"version": "2.0.0",
"version": "2.1.0-alpha.2",
"bin": {
"supermassive": "./bin/supermassive.js"
},
Expand All @@ -24,7 +24,7 @@
},
"dependencies": {
"@graphitation/supermassive-extractors": "^2.2.5",
"@graphitation/ts-codegen": "^3.0.0",
"@graphitation/ts-codegen": "^3.1.0-alpha.3",
"commander": "^8.3.0",
"fast-glob": "^3.2.12",
"graphql": "^15.6.1"
Expand Down
56 changes: 8 additions & 48 deletions packages/cli/src/supermassive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ type GenerateInterfacesOptions = {
legacy?: boolean;
legacyModels?: boolean;
useStringUnionsInsteadOfEnums?: boolean;
enumMigrationJsonFile?: string;
enumMigrationExceptionsJsonFile?: string;
contextSubTypeMetadataFile?: string;
generateOnlyEnums?: boolean;
generateResolverMap?: boolean;
mandatoryResolverTypes?: boolean;
contextSubTypeNameTemplate?: string;
contextSubTypePathTemplate?: string;
defaultContextSubTypePath?: string;
defaultContextSubTypeName?: string;
scope?: string;
Expand Down Expand Up @@ -63,14 +60,6 @@ export function supermassive(): Command {
"-dcn, --default-context-sub-type-name [defaultContextSubTypeName]",
"Default context type which will extend context sub type",
)
.option(
"-cnt, --context-sub-type-name-template [contextSubTypeNameTemplate]",
"context resource name template. You need to specify ${resourceName} in the parameter eg. `${resourceName}Context`",
)
.option(
"-cpt, --context-sub-type-path-template [contextSubTypePathTemplate]",
"context resource path template. You need to specify ${resourceName} in the parameter eg. `@package/preffix-${resourceName}-suffix`",
)
.option("-ei, --enums-import [enumsImport]", "from where to import enums")
.option("-l, --legacy", "generate legacy types")
.option("--legacy-models", "do not use models for object types")
Expand All @@ -81,12 +70,8 @@ export function supermassive(): Command {
.option("--generate-only-enums", "Generate only enum file")
.option("--scope [scope]", "generate models only for scope")
.option(
"--enum-migration-json-file [enumMigrationJsonFile]",
"File containing array of enum names, which should be migrated to string unions",
)
.option(
"--enum-migration-exceptions-json-file [enumMigrationExceptionsJsonFile]",
"File containing array of enum names, which should remain typescript enums",
"--context-sub-type-metadata-file [contextSubTypeMetadataFile]",
"Subtype metadata file",
)
.option(
"--generate-resolver-map",
Expand Down Expand Up @@ -163,42 +148,20 @@ async function generateInterfaces(
path.dirname(fullPath),
options.outputDir ? options.outputDir : "__generated__",
);
let enumNamesToMigrate;
let enumNamesToKeep;
if (options.enumMigrationJsonFile) {
const content = JSON.parse(
await fs.readFile(
path.join(process.cwd(), options.enumMigrationJsonFile),
{
encoding: "utf-8",
},
),
);

if (!Array.isArray(content)) {
throw new Error("enumMigrationJsonFile doesn't contain an array");
}
let contextSubTypeMetadata: Record<string, any> | undefined;

enumNamesToMigrate = content as string[];
}

if (options.enumMigrationExceptionsJsonFile) {
if (options.contextSubTypeMetadataFile) {
const content = JSON.parse(
await fs.readFile(
path.join(process.cwd(), options.enumMigrationExceptionsJsonFile),
path.join(process.cwd(), options.contextSubTypeMetadataFile),
{
encoding: "utf-8",
},
),
);

if (!Array.isArray(content)) {
throw new Error(
"enumMigrationExceptionsJsonFile doesn't contain an array",
);
}

enumNamesToKeep = content as string[];
contextSubTypeMetadata = content;
}

const result = generateTS(document, {
Expand All @@ -207,8 +170,6 @@ async function generateInterfaces(
contextTypePath:
getContextPath(outputPath, options.contextTypePath) || null,
contextTypeName: options.contextTypeName,
contextSubTypeNameTemplate: options.contextSubTypeNameTemplate,
contextSubTypePathTemplate: options.contextSubTypePathTemplate,
defaultContextSubTypePath: getContextPath(
outputPath,
options.defaultContextSubTypePath,
Expand All @@ -221,8 +182,7 @@ async function generateInterfaces(
generateOnlyEnums: !!options.generateOnlyEnums,
generateResolverMap: !!options.generateResolverMap,
mandatoryResolverTypes: !!options.mandatoryResolverTypes,
enumNamesToMigrate,
enumNamesToKeep,
contextSubTypeMetadata,
modelScope: options.scope || null,
});

Expand Down
45 changes: 45 additions & 0 deletions packages/ts-codegen/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
{
"name": "@graphitation/ts-codegen",
"entries": [
{
"date": "Tue, 15 Apr 2025 13:35:07 GMT",
"version": "3.1.0-alpha.3",
"tag": "@graphitation/ts-codegen_v3.1.0-alpha.3",
"comments": {
"prerelease": [
{
"author": "[email protected]",
"package": "@graphitation/ts-codegen",
"commit": "7c44b873c4fe585465bcef72b08170c2940b5432",
"comment": "Metadata dump added"
}
]
}
},
{
"date": "Mon, 17 Mar 2025 13:09:38 GMT",
"version": "3.1.0-alpha.2",
"tag": "@graphitation/ts-codegen_v3.1.0-alpha.2",
"comments": {
"prerelease": [
{
"author": "[email protected]",
"package": "@graphitation/ts-codegen",
"commit": "f3a78cb45a5bc94c0309dd43a2c770e062344db4",
"comment": "Return namespaced type"
}
]
}
},
{
"date": "Tue, 04 Mar 2025 14:17:11 GMT",
"version": "3.1.0-alpha.1",
"tag": "@graphitation/ts-codegen_v3.1.0-alpha.1",
"comments": {
"prerelease": [
{
"author": "[email protected]",
"package": "@graphitation/ts-codegen",
"commit": "fb824e93c1b429874ca72516590d566daa4a13f1",
"comment": "ts-codegen context subtype v2"
}
]
}
},
{
"date": "Wed, 19 Feb 2025 11:31:28 GMT",
"version": "3.0.0",
Expand Down
26 changes: 25 additions & 1 deletion packages/ts-codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
# Change Log - @graphitation/ts-codegen

<!-- This log was last generated on Wed, 19 Feb 2025 11:31:28 GMT and should not be manually modified. -->
<!-- This log was last generated on Tue, 15 Apr 2025 13:35:07 GMT and should not be manually modified. -->

<!-- Start content -->

## 3.1.0-alpha.3

Tue, 15 Apr 2025 13:35:07 GMT

### Changes

- Metadata dump added ([email protected])

## 3.1.0-alpha.2

Mon, 17 Mar 2025 13:09:38 GMT

### Changes

- Return namespaced type ([email protected])

## 3.1.0-alpha.1

Tue, 04 Mar 2025 14:17:11 GMT

### Changes

- ts-codegen context subtype v2 ([email protected])

## 3.0.0

Wed, 19 Feb 2025 11:31:28 GMT
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@graphitation/ts-codegen",
"license": "MIT",
"version": "3.0.0",
"version": "3.1.0-alpha.3",
"main": "./src/index.ts",
"repository": {
"type": "git",
Expand Down
Loading