0
Import GraphQL schema
One script reply has been approved by the moderators Verified
Created by daltonmcdxxix 661 days ago Viewed 2330 times
0
Submitted by adam186 Deno
Verified 463 days ago
1
/**
2
 * Learn more at
3
 * https://docs.fauna.com/fauna/current/api/graphql/endpoints#import
4
 */
5
type Faunadb = {
6
  region: string;
7
  secret: string;
8
};
9
export async function main(
10
  auth: Faunadb,
11
  schema: string,
12
  mode: "merge" | "replace" | "override" = "merge",
13
) {
14
  const region = ["us", "eu"].includes(auth.region) ? auth.region : "";
15
  const response = await fetch(
16
    `https://graphql.${region}.fauna.com/import?mode=${mode}`,
17
    {
18
      method: "POST",
19
      headers: {
20
        Authorization: "Bearer " + auth.secret,
21
      },
22
      body: schema,
23
    },
24
  );
25
  return await response.text();
26
}
27