File size: 837 Bytes
5fa7a59
 
2578d0f
 
 
 
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
import { createClient } from '@supabase/supabase-js'

// src/lib/runtimeEnv.js
import { SUPABASE_URL, SUPABASE_ANON_KEY } from './runtimeEnv';
if (!SUPABASE_URL || !SUPABASE_ANON_KEY) throw new Error('Missing Supabase env');
export const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);

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