Edits history of script submission #22362 for ' Import GraphQL schema (faunadb)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Learn more at
     * https://docs.fauna.com/fauna/current/api/graphql/endpoints#import
     */
    type Faunadb = {
      region: string;
      secret: string;
    };
    export async function main(
      auth: 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 hugo989 6 days ago