Middle
Do you have experience working with WebSocket? With GraphQL?
sobes.tech AI
Answer from AI
Yes, I have experience working with WebSocket and GraphQL.
I used WebSocket for implementing real-time features in applications, such as chat or data updates without page reloads. I utilized the standard WebSocket API in the browser and server-side libraries to support the connection.
Example of a simple WebSocket connection:
const socket = new WebSocket('wss://example.com/socket');
socket.onmessage = (event) => {
console.log('Received message:', event.data);
};
socket.onopen = () => {
socket.send('Hello server!');
};
With GraphQL, I worked on building APIs where the client could request only the needed data. I used Apollo Client on the frontend, which made managing requests and caching convenient.
Example of a GraphQL query with Apollo:
import { gql, useQuery } from '@apollo/client';
const GET_USER = gql`
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
}
}
`;
function User({ userId }) {
const { loading, error, data } = useQuery(GET_USER, { variables: { id: userId } });
if (loading) return 'Loading...';
if (error) return `Error: ${error.message}`;
return <div>{data.user.name} - {data.user.email}</div>;
}