Skip to content

Commit 89a4288

Browse files
authored
Merge branch 'master' into typescript-resolvers-refactor-union-types
2 parents 1de10ba + 14ea7ff commit 89a4288

File tree

11 files changed

+67
-11
lines changed

11 files changed

+67
-11
lines changed

.changeset/quick-carpets-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/visitor-plugin-common': patch
3+
---
4+
5+
Preserve .js extension when importDocumentNodeExternallyFrom and emitLegacyCommonJSImports is false

examples/react/apollo-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"typescript": "4.9.5",
2020
"serve": "14.2.0",
2121
"cypress": "12.6.0",
22-
"start-server-and-test": "1.15.4"
22+
"start-server-and-test": "2.0.0"
2323
},
2424
"scripts": {
2525
"dev": "react-scripts start",

examples/react/graphql-request/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"typescript": "4.9.5",
1919
"serve": "14.2.0",
2020
"cypress": "12.6.0",
21-
"start-server-and-test": "1.15.4"
21+
"start-server-and-test": "2.0.0"
2222
},
2323
"scripts": {
2424
"dev": "react-scripts start",

examples/react/tanstack-react-query/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"typescript": "4.9.5",
2020
"serve": "14.2.0",
2121
"cypress": "12.6.0",
22-
"start-server-and-test": "1.15.4"
22+
"start-server-and-test": "2.0.0"
2323
},
2424
"scripts": {
2525
"dev": "react-scripts start",

examples/react/urql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"typescript": "4.9.5",
1919
"serve": "14.2.0",
2020
"cypress": "12.6.0",
21-
"start-server-and-test": "1.15.4"
21+
"start-server-and-test": "2.0.0"
2222
},
2323
"scripts": {
2424
"dev": "react-scripts start",

examples/vue/apollo-composable/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"vue-tsc": "^1.0.24",
2626
"serve": "14.2.0",
2727
"cypress": "12.6.0",
28-
"start-server-and-test": "1.15.4"
28+
"start-server-and-test": "2.0.0"
2929
}
3030
}

examples/vue/urql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"vue-tsc": "^1.0.24",
2525
"serve": "14.2.0",
2626
"cypress": "12.6.0",
27-
"start-server-and-test": "1.15.4"
27+
"start-server-and-test": "2.0.0"
2828
}
2929
}

examples/vue/villus/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"vue-tsc": "^1.0.24",
2525
"serve": "14.2.0",
2626
"cypress": "12.6.0",
27-
"start-server-and-test": "1.15.4"
27+
"start-server-and-test": "2.0.0"
2828
}
2929
}

packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ export class ClientSideBaseVisitor<
542542
private clearExtension(path: string): string {
543543
const extension = extname(path);
544544

545+
if (!this.config.emitLegacyCommonJSImports && extension === '.js') {
546+
return path;
547+
}
548+
545549
if (EXTENSIONS_TO_REMOVE.includes(extension)) {
546550
return path.replace(/\.[^/.]+$/, '');
547551
}

packages/plugins/other/visitor-plugin-common/tests/client-side-base-visitor.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,51 @@ describe('getImports', () => {
8282
});
8383
});
8484
});
85+
86+
describe('when documentMode "external", importDocumentNodeExternallyFrom is relative path', () => {
87+
const schema = buildSchema(/* GraphQL */ `
88+
type Query {
89+
a: A
90+
}
91+
92+
type A {
93+
foo: String
94+
bar: String
95+
}
96+
`);
97+
98+
describe('when emitLegacyCommonJSImports is false', () => {
99+
it('preserves `.js` on Operations import path', () => {
100+
const fileName = 'fooBarQuery';
101+
const importPath = `./src/queries/${fileName}.js`;
102+
103+
const document = parse(
104+
`query fooBarQuery {
105+
a {
106+
foo
107+
bar
108+
}
109+
}
110+
`
111+
);
112+
113+
const visitor = new ClientSideBaseVisitor(
114+
schema,
115+
[],
116+
{
117+
emitLegacyCommonJSImports: false,
118+
importDocumentNodeExternallyFrom: importPath,
119+
documentMode: DocumentMode.external,
120+
},
121+
{},
122+
[{ document, location: importPath }]
123+
);
124+
125+
visitor.OperationDefinition(document.definitions[0] as OperationDefinitionNode);
126+
127+
const imports = visitor.getImports();
128+
expect(imports[0]).toBe(`import * as Operations from '${importPath}';`);
129+
});
130+
});
131+
});
85132
});

0 commit comments

Comments
 (0)