Subscriptions works in the playground and return expected fields but not in apollo graphql client, it doesn't return anything ! Here's the query being used in both the playground and client :
export const PARTY_SUBSCRIPTION = gql`
subscription onPartyUpdated($hostname: String!) {
party(hostname: $hostname) {
mutation
node {
id
users {
username
}
open
hostname
}
}
}
`;
And this is my apollo client config file :
const DEV_DB_ENDPOINT = "http://192.168.1.3:4000/";
const authLink = setContext(async (_, { headers }) => {
const token = await AsyncStorage.getItem("userToken");
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : ""
}
};
});
const wsLink = new WebSocketLink({
uri: "ws://localhost:5000/",
options: {
reconnect: true
}
});
const httpLink = new HttpLink({
uri: DEV_DB_ENDPOINT,
credentials: "same-origin"
});
const link = split(
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query);
console.log(query);
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
);
},
wsLink,
httpLink
);
const client = new ApolloClient({
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
}),
authLink,
link
]),
cache: new InMemoryCache()
});
export { client };
and this is my subscription component
<Subscription
subscription={PARTY_SUBSCRIPTION}
variables={{
hostname: "Amir004"
}}
onError={err => console.log(err)}
onCompleted={data => console.log(data)}
>
{() => {
return <Text>Current list of friends in your party : </Text>;
}}
</Subscription>
The component doesn't console.log any error or data!
Any help is really appreciated :)