Execute GraphQL Query ( faunadb)
One script reply has been approved by the moderators Verified

Created by danielkelbelle11 291 days ago Viewed 61 times 0 Points

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import { Resource } from "https://deno.land/x/windmill@v1.70.1/mod.ts"

export async function main(
  auth: Resource<'faunadb'>,
  query: string,
  variables?: Record<string, any>,
  operationName?: string
) {
  const region = ['us', 'eu'].includes(auth.region) ? auth.region : '';
  const response = await fetch(`https://graphql.${region}.fauna.com/graphql`, {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + auth.secret
    },
    body: JSON.stringify({
      query,
      variables: variables || {},
      operationName: operationName || null
    })
  });
  return await response.json();
}

Submitted by adam186 92 days ago

Edited 24 days ago

No comments yet

Login to be able to comment