denostack / superserial

A comprehensive Serializer/Deserializer that can handle any data type.
MIT License
35 stars 3 forks source link

GraphQL support #5

Open wan2land opened 1 year ago

wan2land commented 1 year ago

GraphQL is composed of several depths, and superserial is advantageous for reducing the size of data in these types.

JSON

Content-Type: application/json
{
  articles: [
    { __typename: "Article", id: 1, user: { __typename: "User", id: 1, name: "alice" } },
    { __typename: "Article", id: 2, user: { __typename: "User", id: 2, name: "bob" } },
    { __typename: "Article", id: 3, user: { __typename: "User", id: 2, name: "bob" } },
    { __typename: "Article", id: 4, user: { __typename: "User", id: 1, name: "alice" } },
    { __typename: "Article", id: 5, user: { __typename: "User", id: 1, name: "alice" } },
    { __typename: "Article", id: 6, user: { __typename: "User", id: 2, name: "bob" } },
    { __typename: "Article", id: 7, user: { __typename: "User", id: 1, name: "alice" } },
  ]
}

superserial! 🤩

Content-Type: text/x-superserial
{
  articles: [
    Article{ id: 1, user: $1 },
    Article{ id: 2, user: $2 },
    Article{ id: 3, user: $2 },
    Article{ id: 4, user: $1 },
    Article{ id: 5, user: $1 },
    Article{ id: 6, user: $2 },
    Article{ id: 7, user: $1 },
  ]
}
;User{ id: 1, name: "alice" }
;User{ id: 2, name: "bob" }

similar libraries: