I’m working on a ApolloServer implementation to support an accompanying terminating ApolloLink for the RSocket protocol, and am looking for some help to determine the best way to leverage existing apollo-server-core
APIs.
RSocket GraphQL Interop
RSocket is a streaming binary protocol that supports several interaction models, and these interaction models align well with the interaction models required for GraphQL:
- RSocket RequestResponse → GraphQL Query/Mutation
- RSocket RequestStream → GraphQL Subscription
ApolloServerBase & apollo-server-core APIs
While I have found that the ApolloServerBase
and apollo-server-core
APIS are sufficient for implementing basic support for Query/Mutation operations over RSocket, these APIs appear best suited for HTTP and as such are a bit awkward to use outside of an HTTP context.
For instance, the runHttpQuery
API appears to be the easiest way to process an incoming “request”, even when that request is not produced from a HTTP context.
In RSocket, we have the concept of a “payload” which represents an event that the server has received. Given a payload, we can construct the arguments required for the runHttpQuery
, but some of the inputs are entirely faked and are only provided to satisfy the runHttpQuery
API.
const { data } = payload;
const decoded = data.toString();
const deserialized = JSON.parse(decoded);
const { graphqlResponse } = await runHttpQuery([], {
method: "POST",
options: () => {
return this.createGraphQLServerOptions(payload);
},
query: deserialized,
request: new Request("/graphql", {
headers: new Headers(),
method: "POST",
}),
});
(Source)
For framework integrations which do not handle HTTP requests, is there a better API than runHttpQuery
for processing a GraphQL Query/Mutation operation?
Thanks