-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support
namingConvention
options
- Loading branch information
Showing
23 changed files
with
11,473 additions
and
14,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/@newmo/graphql-codegen-plugin-type-guards/src/config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { RawTypesConfig } from "@graphql-codegen/visitor-plugin-common"; | ||
|
||
export type RawPluginConfig = { | ||
/** | ||
* The path to the generated types file | ||
* @example | ||
* typeFile: "./graphql.ts" | ||
**/ | ||
typesFile: string; | ||
/** | ||
* Naming convention for the generated types | ||
* GraphQL Codegen Plugin Common Options | ||
**/ | ||
namingConvention?: RawTypesConfig["namingConvention"]; | ||
/** | ||
* Prefix for the generated types | ||
* GraphQL Codegen Plugin Common Options | ||
**/ | ||
typesPrefix?: RawTypesConfig["typesPrefix"]; | ||
/** | ||
* Suffix for the generated types | ||
* GraphQL Codegen Plugin Common Options | ||
**/ | ||
typesSuffix?: RawTypesConfig["typesSuffix"]; | ||
}; | ||
export type PluginConfig = Required<RawPluginConfig>; | ||
|
||
export function normalizeConfig(rawConfig: RawPluginConfig): PluginConfig { | ||
return { | ||
typesFile: rawConfig.typesFile, | ||
typesPrefix: rawConfig.typesPrefix ?? "", | ||
typesSuffix: rawConfig.typesSuffix ?? "", | ||
namingConvention: rawConfig.namingConvention ?? "" | ||
}; | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/@newmo/graphql-codegen-plugin-type-guards/src/convertName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { convertFactory } from "@graphql-codegen/visitor-plugin-common"; | ||
import type { ASTNode } from "graphql/index.js"; | ||
import type { PluginConfig } from "./config"; | ||
|
||
/** | ||
* Convert the name of the node to the generated type name | ||
* Client preset use this naming convention | ||
* https://www.npmjs.com/package/@graphql-codegen/client-preset | ||
* @param node | ||
* @param config | ||
*/ | ||
export function convertName(node: ASTNode | string, config: PluginConfig): string { | ||
const convert = config.namingConvention | ||
? convertFactory({ namingConvention: config.namingConvention }) | ||
: convertFactory({}); | ||
let convertedName = ""; | ||
convertedName += config.typesPrefix; | ||
convertedName += convert(node); | ||
convertedName += config.typesSuffix; | ||
return convertedName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.