how to integrate grpc service with graphql? - graphql

I have a grpc service that contains several apis(getName, getInfo, etc), and a grpc endpoint, something like this,
configuration-dev-grpc.kmc-default.us-west-2**.com:443
I create a graphql project, how can I connect the graplql with grpc service through that endpoint, or I need to do it in another way?

gRPC and GraphQL are often considered alternatives but, if we consider gRPC as just procedure calls, there's no reason why a GraphQL server could not be implemented against a gRPC client to serve GraphQL clients.
At least one group has a solution:
https://github.com/ysugimoto/grpc-graphql-gateway
If you control the gRPC server, it would possibly be preferable to implement the GraphQL server alongside it, i.e. directly against whatever API it provides. Doing this would avoid the networking between gRPC client and server and the Protobuf (un)marshaling.

Related

Disambiguating and controlling access to public, internal and hybrid gRPC APIs

I currently have a mobile application talks to a GraphQL API service which terminates SSL and then proxies requests to gRPC services. The gRPC services only talk to each other via gRPC.
This system works okay but writing all of the boilerplate to plumb the gRPC APIs through the GraphQL layer to the client is tedious and can be error prone.
I’ve started exploring the idea of talking directly to the backend via gRPC as the tooling has improved substantially over the last few years.
One issue I’m still wondering about, though, is the best way to disambiguate APIs only meant to be called internally by other services from those callable publicly by the native client.
There is also a third category, “hybrid” APIs where it can be called either internally or externally.
Examples —-
Internal: Sending an SMS via Twilio
Public: Log in to account
Hybrid: Update whether an inbox item is read (both from the app when opening a conversation and on the backend when a message is sent)
One option I thought of was an interceptor that passes along a context to indicate if the request is internal or public and use this in the code to return an error or perform additional validation on public requests.
Another option is creating an API service which is still gRPC but fulfills the same purpose as the GraphQL API service.
A third option is disambiguating public and internal services at an organizational level which might require duplicating some APIs that exist for both.
Are there other options I’m unaware of? How have you tackled this issue?

Service to intercept client-server websocket communication for purposes of API-untangling

I'm writing a custom client for an existing framework but in a different language than the supported client. Now I would like to intercept the traffic of the existing client-server connection to get a better grasp of the API intrinsics, which is always quite tedious if you have to extract it from the code alone. I had a look at postman but it doesn't seem to allow interception of websocket messages (https appears to be possible thorugh postman interceptor. Is there a similar tool for websockets?
Basically what I'm looking for is just a relay that forwards every request as-is to the server and vice-versa for the response.

how to run grpc client in python and server in cpp?

I am trying to work with client.py , server.cpp and a make file. I am not understanding how to run the files and work on grpc with these files. Is it possible for anyone to help me understand this concept and work with the client, server and protobuf?
The whole idea of gRPC is to enable protocol based communication between cross platform services. Means your CPP server can communicate with python client. Ref: Official gRPC Documentation
First step is to write a .proto file which is an agreement between server and client on what attributes should a request / response for a particular RPC method should contain.
Now one can implement server, client in any language of their choice. As long as server & client agree on single proto file, underlying process is abstracted by gRPC framework and it just works!!!
For fastest hands-on, Refer to quick start guides of gRPC for c++, python to implement cross platform server, client.

multiple gRPC servers and a unified API

Suppose we have multiple gRPC servers that provides different services. We would like to have one unified API in the client side that acts like a proxy (i.e a translator) that calls appropriate function based on the given request. What do you suggest for implementing of such idea? Should I have a gRPC proxy server (in the client side) that acts as a gRPC server and a client at the same time?

Will each Graphql Subscription from same browser create one websocket connection?

I know what is graphql subscription.
My question is if each subscription will create one websocket connection?
Or all the subscription from each browser is combined to one websocket connection?
I couldn't find answer anywhere in document.
GraphQL itself purposefully does not specify a transport layer in the specification. Therfore the answer depends on the implementation that you are using but for the implementations it makes sense to have only one connection. In Apollo you can use apollo-link-ws to connect to the server. This link then creates (an keeps alive) a single socket to the server using subscriptions-transport-ws. It can also handle all GraphQL methods (not only subscriptions) using the web socket.

Resources