Spaces:
Running
Running
| import { createClient } from '@supabase/supabase-js' | |
| const supabaseUrl = import.meta.env.VITE_SUPABASE_URL | |
| const anon = import.meta.env.VITE_SUPABASE_ANON_KEY | |
| const service = import.meta.env.VITE_SUPABASE_SERVICE_ROLE_KEY | |
| // For this visualization app, prefer service key if provided to bypass RLS for read-only endpoints | |
| const clientKey = service || anon | |
| export const supabase = createClient(supabaseUrl, clientKey, { | |
| auth: { persistSession: false } | |
| }) | |
| // Helper to run GraphQL queries for features not available in REST | |
| export async function graphql(query, variables) { | |
| const apiKey = service || anon | |
| const res = await fetch(`${supabaseUrl}/graphql/v1`, { | |
| method: 'POST', | |
| headers: { | |
| 'content-type': 'application/json', | |
| 'apikey': apiKey, | |
| 'authorization': `Bearer ${apiKey}` | |
| }, | |
| body: JSON.stringify({ query, variables }) | |
| }) | |
| const json = await res.json() | |
| if (json.errors) { | |
| console.error('GraphQL errors:', json.errors) | |
| } | |
| return json.data | |
| } | |