Add comprehensive messenger features and improvements
- Backend improvements: flexible user authentication, nullable fields - Frontend enhancements: new screens (NewMessage, UserInfo), improved UI/UX - Chat functionality: real-time messaging with polling, message actions - Visual upgrades: gradient backgrounds, better themes, modern design - Added project documentation (CLAUDE.md) and development guidelines 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import { ApolloClient, InMemoryCache, createHttpLink, ApolloLink } from '@apollo/client';
|
||||
import { ApolloClient, InMemoryCache, createHttpLink, ApolloLink, split } from '@apollo/client';
|
||||
import { setContext } from '@apollo/client/link/context';
|
||||
import { getMainDefinition } from '@apollo/client/utilities';
|
||||
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
|
||||
import { createClient } from 'graphql-ws';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { API_URL } from '../config/api';
|
||||
import { API_URL, DEV_SERVER_IP } from '../config/api';
|
||||
|
||||
const httpLink = createHttpLink({
|
||||
uri: API_URL,
|
||||
@ -17,6 +20,41 @@ const authLink = setContext(async (_, { headers }) => {
|
||||
};
|
||||
});
|
||||
|
||||
// WebSocket линк для подписок
|
||||
const wsLink = new GraphQLWsLink(createClient({
|
||||
url: API_URL.replace('http://', 'ws://'),
|
||||
connectionParams: () => {
|
||||
return new Promise(async (resolve) => {
|
||||
try {
|
||||
const token = await AsyncStorage.getItem('token');
|
||||
resolve({
|
||||
authorization: token ? `Bearer ${token}` : '',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error getting token for WebSocket:', error);
|
||||
resolve({
|
||||
authorization: '',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
retryAttempts: 5,
|
||||
retryWait: (attempt) => Math.min(1000 * Math.pow(2, attempt), 10000),
|
||||
}));
|
||||
|
||||
// Временно используем только HTTP линк, пока не настроим WebSocket
|
||||
// const splitLink = split(
|
||||
// ({ query }) => {
|
||||
// const definition = getMainDefinition(query);
|
||||
// return (
|
||||
// definition.kind === 'OperationDefinition' &&
|
||||
// definition.operation === 'subscription'
|
||||
// );
|
||||
// },
|
||||
// wsLink,
|
||||
// ApolloLink.from([authLink, httpLink])
|
||||
// );
|
||||
|
||||
export const apolloClient = new ApolloClient({
|
||||
link: ApolloLink.from([authLink, httpLink]),
|
||||
cache: new InMemoryCache(),
|
||||
|
Reference in New Issue
Block a user