1 | |
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 |
|