Skip to content

Binary protocol #432

@tinganho

Description

@tinganho

I'm wondering if there is any plans to add an alternative binary protocol to GraphQL? I think it is good if it is optional and if one can just opt-in to it.

An example:

We manually byte encode all fields:

type RootQuery {
  starship = 0
}

type Starship {
  id: ID! = 0
  name: String! = 1
  length(unit: LengthUnit = METER): Float = 2
}

Instead of sending this query:

query {
   startship {
      id
      name
      length
   }
}

We send this compact one instead:

0 { # query
   0 { # starhsip
      0 # id
      1 # name
      2 # length
   }
}

And instead of receiving JSON

{
  "data" : {
    "starship": {
      "id": "1",
      "name": "Albert Einstein",
      "length": "1",
    }
  }
}

We receive a byte encoded response:

0 { # starship
    0 "1" # id
    1 "Albert Einstein" # name
    2 "1" # length
  }
}

The binary protocol should not replace the textual one. I still think it is good with JSON. Though, I think there is a good use case to have both. I've seen many use-cases where one use gRPC for internal communication(microservice-to-microservice) and GraphQL for external API. And it would be practical if GraphQL just allowed one to use a binary protocol, so devs don't have to use both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions