async function fetchDeal(id: string) {
const response = await fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
query: `
query GetDeal($id: ID!) {
deal(id: $id) {
id
status
}
}
`,
variables: { id }
})
});
const result = await response.json();
if (result.errors) {
// Handle errors
result.errors.forEach(error => {
console.error('GraphQL Error:', error.message);
if (error.extensions?.code === 'UNAUTHENTICATED') {
// Handle authentication error
redirectToLogin();
} else if (error.extensions?.code === 'NOT_FOUND') {
// Handle not found error
showNotFoundMessage();
}
});
return null;
}
return result.data.deal;
}