-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40d10bd
commit e18006f
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export const getV10Client = async ({ url, secret }) => { | ||
const { Client } = (await import("fauna")).default; | ||
return new Client({ | ||
secret, | ||
endpoint: url, | ||
}); | ||
}; | ||
|
||
export const runV10Query = async ({ | ||
query, | ||
url = undefined, | ||
secret = undefined, | ||
client = undefined, | ||
options = { | ||
format: "simple", | ||
typecheck: false, | ||
}, | ||
}) => { | ||
let _client = client; | ||
|
||
if (!_client && url && secret) { | ||
_client = await getV10Client({ url, secret }); | ||
} else if (!_client) { | ||
throw new Error("No client provided and no url and secret provided"); | ||
} | ||
|
||
return _client.query(query, options).finally(() => { | ||
// Clean up the client if one was created internally. | ||
if (!client) _client.close(); | ||
}); | ||
}; |