-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support RSocket as a transport #339
Comments
I mean RSocket payload's composite metadata contains |
What does the The GraphQL spec states:
I suspect that a graphql RSocket implementation would translate this as either including a metadata mimetype as Ex: query {
getTask(id: "0x3") {
id
title
completed
user {
username
name
}
}
} |
@viglucci we are referring here to the GraphQL HTTP spec: https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md#content-types
See also #108 |
@bclozel Thanks for the explanation. Right now RSocket-JS is sending GraphQL payloads as |
Now that RSocket is included, it's more obvious it's not just web. See gh-339
Those are specific to the GraphQL over WebSocket protocol. See gh-339
@linux-china the only thing I see metadata being useful for in this case is to pass a route that maps to the GraphQL handler on the server side. The mime types "application/graphql+json" or "application/json" are for the data payload that carry the GraphQL requests and responses. @viglucci awesome to hear this is progressing on the RSocket-JS side in parallel. Yes this should work but it would be great to try out. RSocket support is now available in Overall, yes it should work given that Spring's |
Routing key is still very important for multi GraphQL instances, for example
Above just my opinions. |
I'm not sure I follow what you're saying, why would the GraphQL request be in the metadata? |
To a GraphQL request, GraphQL json document is RSocket Payload's data, and RSocket Payload's composite metadata contains Routing Metadata and Metadata for data MIME Type . For Metadata Payload for data MIME Type, its value is Routing is useful for multi multi GraphQL instances, and |
Thanks for clarifying. I got it now. We don't support the per-stream mime type extension yet in spring-messaging but we'll consider it then. |
Closing this since the Spring GraphQL side is now in place, but will provide an update once the Boot starter catches up. |
@bclozel thanks for the headsup. I'll align the Apollo integration in rsocket-js with this as well and test against the latest Spring RC once they are available. |
@viglucci we're applying this change quite late in the cycle, next stop is 1.0 scheduled on May 17. |
@viglucci I made a demo to test Spring GraphQL over RSocket, and it works. import {ApolloClient, ApolloLink, gql, InMemoryCache} from "@apollo/client";
import {TcpClientTransport} from "rsocket-tcp-client";
import {makeRSocketLink} from 'rsocket-graphql-apollo-link'
import {RSocketConnector} from "rsocket-core";
async function rsocketApolloLink(): Promise<ApolloLink> {
let connector = new RSocketConnector({
transport: new TcpClientTransport({
connectionOptions: {
host: "127.0.0.1",
port: 42252,
},
}),
setup: {
dataMimeType: "application/json",
metadataMimeType: "message/x.rsocket.composite-metadata.v0"
}
});
const rsocketClient = await connector.connect();
// @ts-ignore
return makeRSocketLink({
rsocket: rsocketClient,
route: "graphql"
}) as ApolloLink
}
async function helloQuery() {
const rsocketLink = await rsocketApolloLink();
const client = new ApolloClient({
cache: new InMemoryCache(),
link: rsocketLink
});
return await client.query({
query: gql`query { bookById(id: "book-1") { id name} }`
});
}
helloQuery().then(result => console.log(result)); |
@linux-china awesome! I had done my own experiments recently as well (with similar results): |
@linux-china and @viglucci, thanks for the snippet and links, and @viglucci for making this possible on the RSocket-JS side! |
The RSocket protocol has all the semantics required to carry GraphQL requests. The
request-response
interaction maps to queries and mutations whilerequest-stream
maps to subscriptions. RSocket supports Reactive Streams signals on the wire to complete a stream from the server side or to cancel it from the client side. That means, GraphQL over RSocket does not require a spec other than agreeing on the format for serialized requests and response. For that we can follow the HTTP spec defined format"application/graphql+json"
.On the implementation, this should be very straight-forward, given the transport abstractions we have in place for client and server.
The text was updated successfully, but these errors were encountered: