wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
12.76k stars 1.14k forks source link

Replace `superjson` with a generated serialization layer #2027

Open sodic opened 1 month ago

sodic commented 1 month ago

Wasp has used superjson for serializing RPC payloads since #1090.

Superjson is great, but it makes the JSON payloads less user-friendly (which isn't a big deal most of the time but becomes pretty annoying when you start writing API tests).

For example, instead of:

{
  "dob": "2024-05-10T09:44:35.883Z",
  "name": "King Koopa"
}

The payload becomes:

{
  "json": {
    "dob": "2024-05-10T09:44:35.883Z",
    "name": "King Koopa"
  },
  "meta": {
    "values": {
      "dob": [
        "Date"
      ]
    }
  }
}

The included metadata is necessary for the client to properly (de)serialize the payload (which was the whole point of including superjson :)).

However, since Wasp generates the code for both the client and the server, there's no need to transfer the metadata over the wire - we can generate the serialization layer on both the server and the client (e.g., with Zod).

This will simplify our payloads, thus making the API easier to test using different HTTP clients (curl, Postman, etc.).

When designing the new serialization layer, consider the points outlined in https://github.com/wasp-lang/wasp/issues/143#issuecomment-1409301893 and #1070.