Skip to content

Commit

Permalink
the casing of interface member names can be controlled too
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusmuntean committed Aug 5, 2024
1 parent afa62bf commit 5e3b712
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/plugins/c-sharp/c-sharp/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ ${classMembers}

if (this.config.emitRecords) {
// record
fieldName = convertSafeName(pascalCase(this.convertName(arg.name)));
fieldName = convertSafeName(
this._parsedConfig.memberNamingFunction(this.convertName(arg.name)),
);
getterSetter = '{ get; }';
} else {
// ToDo: maybe just use pascalCase here, like the field names for records are created
// class
fieldName = convertSafeName(arg.name);
fieldName = convertSafeName(this._parsedConfig.memberNamingFunction(arg.name));
getterSetter = '{ get; set; }';
}

Expand Down
37 changes: 37 additions & 0 deletions packages/plugins/c-sharp/c-sharp/test/c-sharp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,43 @@ describe('C#', () => {
expect(result).toContain('public interface Node {');
});

it('Should generate C# interface with pascalCase properties', async () => {
const schema = buildSchema(/* GraphQL */ `
interface Node {
id: ID!
}
`);
const result = await plugin(
schema,
[],
{ memberNameConvention: 'pascalCase' },
{ outputFile: '' },
);

expect(result).toBeSimilarStringTo(`public interface Node {
[JsonProperty("id")]
string Id { get; set; }
}`);
});
it('Should generate C# interface with camelCase properties', async () => {
const schema = buildSchema(/* GraphQL */ `
interface Node {
id: ID!
}
`);
const result = await plugin(
schema,
[],
{ memberNameConvention: 'camelCase' },
{ outputFile: '' },
);

expect(result).toBeSimilarStringTo(`public interface Node {
[JsonProperty("id")]
string id { get; set; }
}`);
});

it('Should generate C# class that implements given interfaces', async () => {
const schema = buildSchema(/* GraphQL */ `
interface INode {
Expand Down

0 comments on commit 5e3b712

Please sign in to comment.