import { createClient, cacheExchange, fetchExchange } from '@urql/svelte';

/**
 * Create a Wave client for server-side use with a provided access token.
 * Use this in +page.server.ts or +server.ts files with WAVE_ACCESS_TOKEN from private env.
 */
export function createWaveServerClient(accessToken: string) {
	return createClient({
		url: 'https://gql.waveapps.com/graphql/public',
		exchanges: [cacheExchange, fetchExchange],
		fetchOptions: () => ({
			headers: {
				Authorization: `Bearer ${accessToken}`
			}
		})
	});
}
