Skip to content

Commit

Permalink
feat: updated docs, moved the fix-generation logic into chimp so the …
Browse files Browse the repository at this point in the history
…projects are cleaner. Allow for running fix-generation both in the project and through chimp defaults
  • Loading branch information
lgandecki committed Aug 21, 2023
1 parent bf785e6 commit 5b2434f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
15 changes: 0 additions & 15 deletions documentation/docs/Advanced/using-enums.md

This file was deleted.

17 changes: 5 additions & 12 deletions documentation/docs/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check warning on line 23 in src/commands/generate.ts

View workflow job for this annotation

GitHub Actions / test

Do not use "__dirname"
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') => {
Expand Down
7 changes: 7 additions & 0 deletions src/generate/runtime-config-helpers/fix-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);

0 comments on commit 5b2434f

Please sign in to comment.