Skip to content

Commit

Permalink
Make types pascal cased (#467)
Browse files Browse the repository at this point in the history
* Make types pascal cased

* Update test spec to include union types
  • Loading branch information
arvind-chandrashekar-ck-zz authored and kamilkisiela committed Aug 7, 2018
1 parent caf3e98 commit 8f14052
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/templates/typescript/src/schema.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface {{ toPascalCase name }}{{ toPascalCase ../name }}Args {
{{/each}}
{{#each unions}}
{{ toComment description }}
export type {{ name }} = {{#each possibleTypes}}{{this}}{{#unless @last}} | {{/unless}}{{/each}};
export type {{ toPascalCase name }} = {{#each possibleTypes}}{{ toPascalCase this}}{{#unless @last}} | {{/unless}}{{/each}};

{{/each}}
{{#if @root.config.schemaNamespace ~}} } {{~/if}}
Expand Down
35 changes: 35 additions & 0 deletions packages/templates/typescript/tests/typescript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,41 @@ describe('TypeScript template', () => {
`);
});

it('should transform correctly name of union', async () => {
const { context } = compileAndBuildContext(`
type Query {
fieldTest: [CBText]
}
union CBText = ABText | BBText
scalar ABText
scalar BBText
`);

const compiled = await compileTemplate(
{
...config
} as GeneratorConfig,
context
);

const content = compiled[0].content;

expect(content).toBeSimilarStringTo(`
export type AbText = any;
`);
expect(content).toBeSimilarStringTo(`
export type BbText = any;
`);
expect(content).toBeSimilarStringTo(`
export interface Query {
fieldTest?: (CbText | null)[] | null;
}
`);
expect(content).toBeSimilarStringTo(`
export type CbText = AbText | BbText;
`);
});

it('should generate enums correctly', async () => {
const { context } = compileAndBuildContext(`
type Query {
Expand Down

0 comments on commit 8f14052

Please sign in to comment.