# I cannot fire the onConnected event

**URL:** <https://community.apollographql.com/t/i-cannot-fire-the-onconnected-event/7868>\
**Category:** Client SDKs\
**Tags:** client, mobile\
**Created:** [October 2, 2024, 3:20pm UTC](https://community.apollographql.com/t/i-cannot-fire-the-onconnected-event/7868 "2024-10-02T15:20:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cld](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@cld](https://community.apollographql.com/u/cld)\
**Post date:** [October 2, 2024, 3:20pm UTC](https://community.apollographql.com/t/i-cannot-fire-the-onconnected-event/7868/1 "2024-10-02T15:20:56Z")

</div>

Hi, I have an Aws AppSync service that I would like to establish a Websocket connection with my mobile app built in React Native

I am using the libraries @apollo/client/link/ws and @subscriptions-transport-ws

this is the code that makes the connection

```auto
const { endpointGraphQL: url, region } = awsConfig.API.GraphQL;
const auth: AuthOptions = {
  type: AUTH_TYPE.API_KEY,
  apiKey: 'xxxxxxx',
};

const httpLink = new HttpLink({
  uri: url,
});

let ack = false;

const wsClient = new SubscriptionClient(url, {
  reconnect: true,
  connectionCallback: () => {
    ack = true;
  }
});

wsClient.use([
	{
		applyMiddleware(options: OperationOptions, next: Function) {
			if (!ack) {
				throw new Error('not ready');
			}
			next();
		}
	}
]);
wsClient.onDisconnected(() => console.log('DISCONNECTED -'));
wsClient.onConnected(() => console.log('CONNECTED -'));

const retryLink = new RetryLink({
	delay: {
		initial: 300,
		max: 60000,
		jitter: true,
	},
	attempts: (count, operation, e) => {
		if (e && e.response && e.response.status === 401) {
			return false;
		}
		return count < 30;
	}
});

const wsLink = new WebSocketLink(wsClient);

const link = ApolloLink.from([
  createAuthLink({ url, region, auth }),
  createSubscriptionHandshakeLink({ url, region, auth }, httpLink),
  retryLink,
  wsLink,
]);

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link,
  connectToDevTools: true,
});

export const getApolloClient = () => {
  return client;
};

```

The onDisconnected event works, but I cannot fire the onConnected event. I can make the WebSocket connection work through Postman.

> Blockquote is there anything that I am missing here?

Thank you!
