Skip to content

Commit

Permalink
[urql] Respect omitOperationSuffix (#4405)
Browse files Browse the repository at this point in the history
Fixes #3968

Co-authored-by: Daniel K <daniel@lovemyvoice.app>
  • Loading branch information
FredyC and Daniel K committed Jul 21, 2020
1 parent 2141811 commit d52543d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/plugins/typescript/urql/src/visitor.ts
Expand Up @@ -84,7 +84,7 @@ export const ${componentName} = (props: Omit<Urql.${operationType}Props<${generi
operationVariablesTypes: string
): string {
const operationName: string = this.convertName(node.name.value, {
suffix: pascalCase(operationType),
suffix: this.config.omitOperationSuffix ? '' : pascalCase(operationType),
useTypesPrefix: false,
});

Expand Down
28 changes: 28 additions & 0 deletions packages/plugins/typescript/urql/tests/urql.spec.ts
Expand Up @@ -466,6 +466,20 @@ query MyFeed {
expect(content.content).not.toContain(`export class ITestComponent`);
});

it('should respect omitOperationSuffix for Component', async () => {
const docs = [{ location: '', document: basicDoc }];
const content = (await plugin(
schema,
docs,
{ omitOperationSuffix: true },
{
outputFile: 'graphql.tsx',
}
)) as Types.ComplexPluginOutput;

expect(content.content).not.toContain(`export class TestComponent`);
});

it('should add three generics if operation type is subscription', async () => {
const documents = parse(/* GraphQL */ `
subscription ListenToComments($name: String) {
Expand Down Expand Up @@ -601,5 +615,19 @@ export function useSubmitRepositoryMutation() {

expect(content.content).toContain(`export function useTestQuery`);
});

it('Should respect omitOperationSuffix for hooks', async () => {
const docs = [{ location: '', document: basicDoc }];
const content = (await plugin(
schema,
docs,
{ withHooks: true, omitOperationSuffix: true },
{
outputFile: 'graphql.tsx',
}
)) as Types.ComplexPluginOutput;

expect(content.content).toContain(`export function useTest(`);
});
});
});

0 comments on commit d52543d

Please sign in to comment.