Import GraphQL schema ( faunadb)
One script reply has been approved by the moderators Verified

Created by daltonmcdxxix 291 days ago Viewed 54 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"

/**
 * Learn more at 
 * https://docs.fauna.com/fauna/current/api/graphql/endpoints#import
 */
export async function main(
  auth: Resource<'faunadb'>,
  schema: string,
  mode: 'merge' | 'replace' | 'override' = 'merge'
) {
  const region = ['us', 'eu'].includes(auth.region) ? auth.region : '';
  const response = await fetch(`https://graphql.${region}.fauna.com/import?mode=${mode}`, {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + auth.secret
    },
    body: schema
  });
  return await response.text();
}

Submitted by adam186 92 days ago

Edited 24 days ago

No comments yet

Login to be able to comment