Thought experiment : A native integration between GraphQL and gRPC would be awesome, isn’t it? where gRPC serves transport and GraphQL serves schema.
Some context :
- gRPC already has .proto files which act similar to a schema.
- Discoverable schema and declarative (4th Gen like i.e. SQL like) query (beyond SQL projection) and Mutation constructs that importantly support nested elements are the key features of GraphQL.
Question is are the above 4 features already supported by gRPC.?
- Discoverable schema exists in gRPC however declarative and seemingly unlimited flexibility in querying are not available.
- gRPC is similar to Webservices in the sense that list of services are discoverable but their individual contracts are well established i.e. the composition of inputs (SQL where clause) and the outputs (SQL projection clause) are fully specified in the contract.
- Point to note is that GraphQL does bring flexibility to the where clause with its nested filters.
- Further GraphQL’s directives add another layer of flexibility, for example, its included and skip directives
To summarize GraphQL, as a language, acts like SQL for the frontend (a.k.a backend for the frontend) and is an excellent interface for enterprise systems. However, GraphQL doesn’t prescribe, mandate or come with any transport mechanisms and optimizations there of. This is where gRPC shines. In the future, if there is a deeper integration between the two, which seems theoretically possible from the above, that would be great.
One direction could be that gRPC expands proto to encompass GraphQL constructs. The other way round is harder, since GraphQL, is a spec more than an implementation.
Inspiration : This article on a use case where GraphQL and gRPC were used together.
This post was later published on LinkedIn here.