Last active
January 6, 2020 17:03
-
-
Save lovenick/edc6c7c99c529e1e1e6368d02bf3dbae to your computer and use it in GitHub Desktop.
Import FaunaDB Graphql Schema
This file contains hidden or 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
require('dotenv').config(); | |
const fs = require('fs'); | |
const request = require('request-promise-native'); | |
const yargs = require('yargs'); | |
const ora = require('ora'); | |
const FAUNA_ENDPOINT = 'https://graphql.fauna.com/import'; | |
const options = yargs | |
.option('file', { | |
alias: 'f', | |
describe: 'Path to .graphql file to upload', | |
}) | |
.option('mode', { | |
alias: 'm', | |
default: 'merge', | |
choices: ['merge', 'override'], | |
describe: | |
'FaunaDB mode - merge: with the existing schema. override: delete and replace (warning, data loss)', | |
}) | |
.demandOption(['file'], 'Please provide file to upload.').argv; | |
(async ({ endpoint, file, mode }) => { | |
const spinner = ora('Uploading schema').start(); | |
try { | |
await request({ | |
url: `${FAUNA_ENDPOINT}?mode=${mode}`, | |
method: 'POST', | |
headers: { | |
Authorization: `Bearer ${process.env.FAUNA_SECRET}`, | |
}, | |
body: fs.readFileSync(file), | |
}); | |
spinner.succeed('Schema uploaded'); | |
spinner.stop(true); | |
} catch (err) { | |
console.error('Error uploading', err); | |
} | |
})(options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment