diff --git a/documentation/docs/Advanced/using-enums.md b/documentation/docs/Advanced/using-enums.md deleted file mode 100644 index 1586b76..0000000 --- a/documentation/docs/Advanced/using-enums.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -id: using-enums -title: Using Enums ---- - -Currently, the graphql-code-generator when generating the Data types replaces all enums with strings. It makes sense from a factual point - the data in a JSON format (coming from a REST call or mongodb query or most other things) will contain a string, not enum. Nonetheless, that makes testing harder, and the code less strict. - -We have a terrible hack for it, and plan to fix it in a plugin at some point. - -For now - add lines like these to your top-level fix-generated.js . - -```javascript -shell.sed("-i", "currency: string", "currency: Currency", path); -shell.sed("-i", "status: string", "status: EntityStatus", path); -``` diff --git a/documentation/docs/structure.md b/documentation/docs/structure.md index 9cf4679..96fe527 100644 --- a/documentation/docs/structure.md +++ b/documentation/docs/structure.md @@ -7,17 +7,15 @@ A fresh project will consist of a following structure (* are optional): ``` ├── README.md -├── codegen.js * ├── fix-generated.js * ├── jest.config.js ├── jest.setup.js * -├── nodemon.run.json +├── nodemon.run.json * ├── package.json ├── tsconfig.json └── src     ├── context.ts     ├── createApp.ts -    ├── dataSources.ts     ├── index.ts     ├── root.ts     └── modules @@ -47,13 +45,12 @@ Read more here - [Understanding Types](understanding-types.md) ### fix-generated.js -fix-generated.js tweaks the field resolvers types, so we can unit test them. -If you use Enums you will likely use a similar pattern to tweak the types generated by the GraphQL Code Generator. -[Using Enums](Advanced/using-enums.md) +If you want to manually tweak the generated types, this will allow you to do so. +Please let us know why would you need to do so, most probably this is something we can automate in Chimp. ### jest.config.js -Standard Jest Configuration for the TypeScript Project. Additionaly we use `pathsToModuleNameMapper` to resolve the `@app/` and `@generated/` absolute paths +Standard Jest Configuration for the TypeScript Project. Additionally, we use `pathsToModuleNameMapper` to resolve the `@app/` and `@generated/` absolute paths ### jest.setup.js @@ -87,7 +84,7 @@ Important part to our generator is the part that setups the paths, so we can cle ### context.ts -Define your dynamic context here. It will be passed to your resolvers (with DataSources added). +Define your dynamic context here. It will be passed to your resolvers. By default, our context consists of three things: - headers coming from http request @@ -102,10 +99,6 @@ You will find there a basic cors configuration. Another important thing that happens here is the initialization of context with the passed root object. -### dataSources.ts - -Sets up Apollo-compatible Data Sources. - ### index.ts Starts up the server based on the app configured in createApp.ts diff --git a/src/commands/generate.ts b/src/commands/generate.ts index 2e3327b..b281d03 100644 --- a/src/commands/generate.ts +++ b/src/commands/generate.ts @@ -20,11 +20,14 @@ const runTypeGen = async (projectMainPath: string, appPrefix: string) => { }; const fixGenerated = async (projectMainPath: string) => { + const fixGeneratedPath = path.join(__dirname, '../generate/runtime-config-helpers/fix-generated.js'); + await execQuietly(`node ${fixGeneratedPath}`, {}); + const customFixGenerated = path.join(projectMainPath, 'fix-generated.js'); - const fixGeneratedPath = fs.existsSync(customFixGenerated) - ? customFixGenerated - : path.join(__dirname, '../generate/runtime-config-helpers/fix-generated.js'); - await execQuietly(`node ${fixGeneratedPath}`, { cwd: projectMainPath }); + const fixCustomGeneratedPath = fs.existsSync(customFixGenerated) ? customFixGenerated : null; + if (fixCustomGeneratedPath) { + await execQuietly(`node ${fixCustomGeneratedPath}`, { cwd: projectMainPath }); + } }; const prettifyGenerated = async (projectMainPath: string, modulesPath = 'src') => { diff --git a/src/generate/runtime-config-helpers/fix-generated.js b/src/generate/runtime-config-helpers/fix-generated.js index f3030af..9aca6c7 100644 --- a/src/generate/runtime-config-helpers/fix-generated.js +++ b/src/generate/runtime-config-helpers/fix-generated.js @@ -7,3 +7,10 @@ shell.sed( '', path.join(process.cwd(), './generated/graphql/types.ts'), ); + +shell.sed( + '-i', + /(import { ReadStream } from "fs-capacitor";)/, + '// @ts-ignore\n$1', + path.join(process.cwd(), './generated/graphql/types.ts'), +);