-
Notifications
You must be signed in to change notification settings - Fork 64
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
Subscriptions? #5
Comments
turns out it is really simple 😄 /* @flow */
import {withData} from 'next-apollo';
import {HttpLink} from 'apollo-link-http';
import {WebSocketLink} from 'apollo-link-ws';
import {split} from 'apollo-client-preset';
import {getMainDefinition} from 'apollo-utilities';
import {port} from '../constants';
export default withData(headers => {
const httpLink = new HttpLink({
uri: `http://localhost:${port}/graphql`,
// this goes here directly (there's actually no "opts" config)
credentials: 'same-origin',
// resend the headers on the server side, to be truly isomorphic (makes authentication possible)
headers
});
return {
link: process.browser
? split(
({query}) => {
const {kind, operation} = getMainDefinition(query);
return 'OperationDefinition' === kind && 'subscription' === operation;
},
// that's all you need to make subscriptions work :)
new WebSocketLink({
uri: `ws://localhost:${port}/subscriptions`,
options: {reconnect: true}
}),
httpLink
)
: httpLink
};
}); |
Closed
awesome! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about websocket subscriptions?
The text was updated successfully, but these errors were encountered: