File size: 1,017 Bytes
28a6599
5fa7a59
28a6599
 
 
7ad8f09
 
 
 
 
 
 
 
28a6599
5fa7a59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { createClient } from '@supabase/supabase-js';

const url  = import.meta.env.VITE_SUPABASE_URL;
const anon = import.meta.env.VITE_SUPABASE_ANON_KEY;

if (!url || !anon) {
  // Helpful logs if something’s still off
  console.error('Env seen by app:', {
    VITE_SUPABASE_URL: url,
    VITE_SUPABASE_ANON_KEY: anon ? '(set)' : '(missing)'
  })
  throw new Error('Missing VITE_SUPABASE_URL or VITE_SUPABASE_ANON_KEY');
}
export const supabase = createClient(url, anon);

// 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
}