Skip to content

Commit b913dd6

Browse files
authored
Merge pull request #250 from nikodevv/bugfix-add-node-missing-imports
bugfix: Added fetch and websockets imports for node environments.
2 parents 73326fe + b9e8ed5 commit b913dd6

File tree

6 files changed

+13
-1
lines changed

6 files changed

+13
-1
lines changed

src/TreeToTS/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
graphqlErrorTypeScript,
1111
typescriptFunctions,
1212
} from './templates/typescript';
13+
import { commonImports, envSpecificImports } from './templates/typescript/indexImports';
1314

1415
export interface OperationName {
1516
name: string;
@@ -124,7 +125,7 @@ export class TreeToTS {
124125
}) {
125126
const operations = bodyTypeScript(env, TreeToTS.resolveOperations(tree));
126127
return {
127-
indexImports: `import { AllTypesProps, ReturnTypes } from './const${esModule ? '.js' : ''}';`,
128+
indexImports: commonImports(esModule).concat(envSpecificImports(env)),
128129
const: TreeToTS.resolveBasisCode(tree),
129130
index: TreeToTS.resolveBasisTypes(tree)
130131
.concat(graphqlErrorTypeScript.concat('\n').concat(constantTypesTypescript).concat('\n\n'))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default ``;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default ``;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const commonImports = (esModule?: boolean): string =>
2+
`import { AllTypesProps, ReturnTypes } from './const${esModule ? '.js' : ''}';`;
3+
4+
export const envSpecificImports = (env: string) => `
5+
${require(`./${env}/fetchImport`).default}
6+
${require(`./${env}/websocketsImport`).default}
7+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default `import fetch from 'node-fetch';`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default `import WebSocket from 'ws';`;

0 commit comments

Comments
 (0)