How can I construct a grahpql publish payload that Apollo client expects? - go

I am building graphql server in AWS websocket apigateway + Lambda to support subscription. The lambda saves all subscribers' data in a database. When there is a need to publish data to subscribers, it need to construct a payload and send it to the websocket apigateway which will forward the payload to the Apollo client.
I have made the subscribe request work but the question I have is how to construct a payload the Apollo client expects when the server wants to publish data to subscribers.
I build all of this in go by using the library github.com/graph-gophers/graphql-go. Any library in go supports building the payload is great for me.

Related

AWS AppSync over websockets for query, mutation, and subscription (no REST)?

I've been successful with Apollo Server + graphql-ws for using a websocket as the entire network transport (all queries, mutations, and subscriptions). Is this possible to do with AWS AppSync? Or does AWS AppSync only allow use of the websocket for subscriptions and all queries/mutations go via REST requests?
Allowing queries and mutations to go over the websocket (which is already connected for subscriptions) opens up a lot of doors for very quick two way communication between web and mobile clients.

how to integrate grpc service with 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.

Apollo-Server GraphQL Subscription on External WebSocket Server

So I have a bit of a question since I'm having a hard time wrapping my head around it. Currently I have a GraphQL API Server created using Apollo-Server and persisted using a local sqlite database. I have the queries and mutations working correctly.
I also have an external WebSocket server that constantly has messages (that match my GraphQL/Database schema) produced to it at say ws://localhost:8000/websocket. Is it possible to have my GraphQL Server subscribe to that websocket address and constantly parse those messages and use the appropriate mutation to insert into the backend database?
I would then have a Vue frontend that would constantly display the results (via Vue Apollo Clients WS subscription maybe?)
to have my GraphQL Server subscribe to that websocket address and constantly parse those messages
Typically no, its the other way around - you can make ws server to call graphql server to do the mutations. That is if you want to use WS as the primary transport layer for everything - queries, mutations & subscriptions.
But usually architecture separates queries & mutations because they are more stateless and critical from subscriptions which are more stateful (persisted connection)
client -> queries & mutations -> graphql server --> redis pubsub -+
|
client <--> subscriptions <-- graphql subscription server <-------+
(in simpler cases when you don't need high load, you can combine both servers to use in-memory pubsub)
BUT, if you very much want to, ofc you can write custom code to connect graphql server -> listen ws server in the background. See https://github.com/enisdenjo/graphql-ws#node-client for example
The problem can appear if you have some user context. You would need to either have custom connection where changes of all users happen. Or have a dedicated connection for every user
Yes , it can be done quite easily , just write a service worker or a worker thread that constantly checks for new messages
Can be done using worker_threads in node js
And if you need to implement it realtime
Make sure your worker thread starts a socket connection and is constantly connected to the port where you are publishing your messages
You can do it using socket.io library

With GraphQL is it possible to replace the websocket used for subscription with a message-based approach (e.g. MQ)

Whereas the corporate environment I am working in accepts the use of http(s) based request response patterns, which is OK for GraphQL Query and Mutation, they have issues with the use of websockets as needed for GraphQL Subscription and would prefer that the subscription is routed via IBM MQ.
Does anyone have any experience with this? I am thinking of using Apollo Server to serve up the GraphQL interface. Perhaps there is a front-end subscription solution that can be plugged in using IBM MQ? The back end data sources are Oracle databases.
Message queues are usually used to communicate between services while web sockets are how browsers can communicate with the server over a constant socket. This allows the server to send data to the client when a new event of a subscription arrived (classically browsers only supported "pull" and could only receive data when they asked for it). Browsers don't implement the MQ protocols you would need to directly subscribe to the MQ itself. I am not an expert on MQs but what is usually done is there is a subscription server that connects to the client via web socket. The subscription service then itself subscribes to the message queue and notifies relevant clients about their subscribed events. You can easily scale the subscription servers horizontally when you need additional resources.

Best practice for sending messages to SignalR client and .NET core WebApi

I am looking at developing a client - server application whereby the client will send a message to the server via our API performing an action. The web api (.NET) will hand off this message to a processing queue (Amazon queue at this stage) which will perform operations on it. I would then like to send a message back to the client to indicate that the message has been processed etc.
The only way I can think of to do this is to have the processing queue which is not part of the web api send a HttpPost or HttpPut to the same API my SignalR hub is defined which will send send the messages out to the various clients.
However performance is an issue of this application so I'm hesitant to do another Http call from the backend server to the API just to then get a message sent. Is there any other way I could look at getting these messages sent?

Resources