import { GraphQLClient, CacheManager } from 'edge-utils';
export default {
async fetch(request) {
// Create cache manager
const cache = new CacheManager({
ttl: 300000, // 5 minutes
maxSize: 100
});
// GraphQL client with caching
const client = new GraphQLClient('https://api.example.com/graphql', {
cache
});
const data = await client.query(`
query GetUser($id: ID!) {
user(id: $id) {
name
email
}
}
`, { id: new URL(request.url).searchParams.get('id') });
return new Response(JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' }
});
}
};