Adding chimp 3 to an existing Application
Note: We will base our work on this repository: https://github.com/xolvio/chimp-gql-tiny-example/tree/data-sources and the selected branch (data-sources)
First, we will initialize chimp:
We need to manually configure jest.config.js
I'm removing these two dependencies from the package.json because they will be used as build-time, not run-time.
Add the tsconfig-paths to the start script
Now we are ready to install dependencies:
Prepare context (./src/context.ts):
Remove the example module.
Move Library to modules
Change dataSources.ts Library path
modules/Library/Library.graphql
Generate files with chimp:
Optional: to make Webstorm happy mark top schema.graphql and generated/graphql/schema.ts as plaintext.
Move resolvers:
BookLibrary
LibraryBooks
There will be an error in the return type of LibraryBooks - add @computed to Author.graphql book->Author
resolvers.ts - use chimpResolvers
schema.ts - use ./schema.graphql
Check example query
The existing test is passing.
The new ones are as well, although they are not implemented.
The one lines are probably not worth testing (types are doing their job)
BookLibrary has some logic so let's test that one.
We also want to see it fail. - change === to !== in BookLibrary.ts resolver -
Once we see it fail we know that the test is doing its job.
Move Author to ./src/modules/
Change dataSources
yarn chimp
Looks like I'm missing one resolver, let's add that one.
to src/modules/Library.graphql
remove resolvers and schema
and finally in index.ts:
Let me know if you have any questions or thoughts in the comments below.
This article is based on my notes from adding chimp to an existing app, I'd recommend watching it there as I discuss the steps and reason for some design decisions in Chimp in depth. But if you want to be able to copy/paste some of the code, or if you want to be able to easier find this article with Google in the future, I'm leaving the notes here. :) The final diff is available here, but it's highly recommended watching the video or try the steps manually to get a "feel" of the chimp workflow. The diff tells only half of the story.