[LC-334] tRPC v11
Overview
๐ Relevant Jira Issues
[LC-334] Fix Request URL Length
๐ What is the context and goal of this PR?
We are getting ourselves into trouble because sometimes a single tRPC request can generate a URL that is longer than 2,048 characters. To combat this, we can upgrade to tRPC v11 and override the HTTP method used for tRPC to POST requests and move that query out of the URL and into the request body!
๐ฅด TL; RL:
Goes through pain to make the above happen!
๐ก Feature Breakdown (screenshots & videos encouraged!)
There's a lot to break down here, but basically it just boils down to the fact that migrating to v11
was not super straightforward. I had to bring in a PR for a fork of trpc-openapi just to be able
to keep the API server alive, and I had to pull some trickery with the build step for the server code.
This has resulted in better built types though, as the old process was leaving in path aliases that
TS would just not understand!
๐ Important tradeoffs made:
trpc-openapi is unfortunately not very well maintained, and so the community is currently scrambling
to rally around an alternative for tRPC v11. For our specific usecase, I was able to take advantage
of one of those community efforts, but it's definitely not well suited for the future, and I almost
wonder if we should instead just consider forking trpc-openapi ourselves and maintaining it,
considering how crucial it is to our whole process here!
๐ Types of Changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Chore (refactor, documentation update, etc)
๐ณ Does This Create Any New Technical Debt? ( If yes, please describe and add JIRA TODOs )
- [ ] No
- [x] Yes
We will need to keep an eye on that better-trpc-openapi package and update it as progress happens.
Also, we'll want to watch tRPC for when v11 officially releases, and then move off of the current RC
that we are on
Testing
๐ฌ How Can Someone QA This?
Oh boy there's a lot to this one. So first, just pnpm i and build everything with pnpm exec nx build cli --skip-nx-cache
Then link @learncard/init in the LCA repo under apps/learn-card-app, packages/learn-card-base, services/lca-api, and packages/plugins/lca-api-plugin
Then, spin up a Neo4j instance with Docker: docker run --env=NEO4J_AUTH=none -p 7474:7474 -p 7687:7687 neo4j
Then, spin up a Mongo instance with Docker: docker run -p 27017:27017 mongo
Then, add the following to a .env file in services/learn-card-network/brain-service
SEED=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
NEO4J_URI=neo4j://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=asdfasdfasdfasdfasdfasdfasdfasdfasdf
Then, add the following to a .env file in services/learn-card-network/learn-cloud-service
LEARN_CLOUD_SEED=a
LEARN_CLOUD_MONGO_URI=mongodb://localhost:27017
LEARN_CLOUD_MONGO_DB_NAME=nicelol
Then, spin up the brain service on port 4000 by cding into services/learn-card-network/brain-service and running pnpm start-p-4000
Then, spin up the cloud service on port 5000 by cding into services/learn-card-network/learn-cloud-service and running pnpm start-p-5000
Then, in learn-card-base, go to walletHelpers.ts and in getBespokeLearnCard hardcode network to http://localhost:4000/trpc and cloudUrl to http://localhost:5000/trpc
If all goes right, you should be able to now spin up LCA and go to it locally and check your network tab to see POST requests getting sent to those tRPC servers!
You should also check that the api routes still work by going to http://localhost:4000/api/health-check and http://localhost:5000/api/health-check directly in your browser!
๐ฑ ๐ฅ Which devices would you like help testing on?
๐งช Code Coverage
This isn't really a test kind of PR =( Though the test suite still passes!
Documentation
๐ Gitbook
๐ Storybook
โ PR Checklist
- [x] Related to a Jira issue (create one if not)
- [x] My code follows style guidelines (eslint / prettier)
- [x] I have manually tested common end-2-end cases
- [x] I have reviewed my code
- [x] I have commented my code, particularly where ambiguous
- [x] New and existing unit tests pass locally with my changes
- [ ] I have made corresponding changes to gitbook documentation
๐ Ready to squash-and-merge?:
- [x] Code is backwards compatible
- [x] There is not a "Do Not Merge" label on this PR
- [x] I have thoughtfully considered the security implications of this change.
- [x] This change does not expose new public facing endpoints that do not have authentication
๐ฆ Changeset detected
Latest commit: 3d844b01c845e0c0a1e988cd4e480105a4756029
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 13 packages
| Name | Type |
|---|---|
| @learncard/learn-cloud-service | Minor |
| @learncard/network-brain-service | Minor |
| @learncard/network-brain-client | Minor |
| @learncard/learn-cloud-client | Minor |
| @learncard/learn-cloud-plugin | Patch |
| @learncard/network-plugin | Patch |
| @learncard/init | Patch |
| @learncard/cli | Patch |
| @learncard/chapi-example | Patch |
| @learncard/create-http-bridge | Patch |
| @learncard/react | Patch |
| learn-card-discord-bot | Patch |
| @learncard/snap-chapi-example | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Deploy Preview for learncarddocs canceled.
| Name | Link |
|---|---|
| Latest commit | 3d844b01c845e0c0a1e988cd4e480105a4756029 |
| Latest deploy log | https://app.netlify.com/sites/learncarddocs/deploys/66ea78336254430008f76feb |
Deploy Preview for learn-card-chapi-example failed. Why did it fail? โ
| Name | Link |
|---|---|
| Latest commit | 3d844b01c845e0c0a1e988cd4e480105a4756029 |
| Latest deploy log | https://app.netlify.com/sites/learn-card-chapi-example/deploys/66ea7833aac37d00081f8cf0 |
@TaylorBeeston - if we get the docker PR merged in, then I can test this one by spinning up the compose file, yeah? Might wait to do that, if so
@Custard7 Yes! There's going to be some conflicts between these two anyways, so it would probably be best to wait until then! I'm just holding up the Docker PR right now as I find weird issues with doing the full docker compose including LCA API and hook it up to locally running LCA!
@TaylorBeeston - okay, after looking into the openapi validation errors more, it's like 99% likely that it's because of the old 1.2.0 version of trpc-to-openapi we are using. So, I think it might be worth prioritizing getting this guy back up to date, in sync with main, and merged in. Seems like we might want to bump from the release candidate of trpc 11 as well. I can help re-review when this is updated! ๐ช
Superseded by #682