0

Import GraphQL schema

by
Published Jun 6, 2022
Script faunadb Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
/**
4
 * Learn more at
5
 * https://docs.fauna.com/fauna/current/api/graphql/endpoints#import
6
 */
7
type Faunadb = {
8
  region: string;
9
  secret: string;
10
};
11
export async function main(
12
  auth: Faunadb,
13
  schema: string,
14
  mode: "merge" | "replace" | "override" = "merge",
15
) {
16
  const region = ["us", "eu"].includes(auth.region) ? auth.region : "";
17
  const response = await fetch(
18
    `https://graphql.${region}.fauna.com/import?mode=${mode}`,
19
    {
20
      method: "POST",
21
      headers: {
22
        Authorization: "Bearer " + auth.secret,
23
      },
24
      body: schema,
25
    },
26
  );
27
  return await response.text();
28
}
29

Other submissions
  • Submitted by adam186 Deno
    Created 398 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