-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/c sharp member name casing (#806)
* added test for namingConvention=pascalCase * added support for choosing the field naming convention (camel case or pascal case) for a class' properties * Renamed fieldNamingConvention to memberNamingConvention to reflect that it actually applies to all members, not only fields * added a test for camelCase naming class properties * the casing of record member names can be controlled too * control the casing of input type class properties * the casing of interface member names can be controlled too * typo * removed unused import * added changeset
- Loading branch information
1 parent
f29802b
commit d1d6d6e
Showing
5 changed files
with
203 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@graphql-codegen/c-sharp': Minor | ||
--- | ||
|
||
Added `memberNameConvention` which allows you to customize the naming convention for | ||
interface/class/record members. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { camelCase, pascalCase } from 'change-case-all'; | ||
import { NameNode } from 'graphql'; | ||
import { CSharpResolversPluginRawConfig } from './config'; | ||
|
||
type MemberNamingFunctionInput = string | NameNode; | ||
|
||
export type MemberNamingFn = (nameOrNameNode: MemberNamingFunctionInput) => string; | ||
|
||
export function getMemberNamingFunction(rawConfig: CSharpResolversPluginRawConfig): MemberNamingFn { | ||
switch (rawConfig.memberNameConvention) { | ||
case 'camelCase': | ||
return (input: MemberNamingFunctionInput) => | ||
camelCase(typeof input === 'string' ? input : input.value); | ||
case 'pascalCase': | ||
return (input: MemberNamingFunctionInput) => | ||
pascalCase(typeof input === 'string' ? input : input.value); | ||
default: | ||
return (input: MemberNamingFunctionInput) => | ||
camelCase(typeof input === 'string' ? input : input.value); | ||
} | ||
} |
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