A lib with some helper functions to make uploading a schema to FaunaDB easier.
It allows you to combine multiple SDL strings and use extend type.
const { importSchema } = require('faunadb-graphql-schema-loader')
const secret = process.env.FAUNADB_ADMIN_KEY
const schema = `
type Budget {
name: String!
owner: User! @relation
}
type User {
budget: Budget! @relation
name: String!
}
`
importSchema(secret, schema).then((res) => console.log(res))importSchema = (
faunadbKey: string,
schema: string,
mode: 'replace' | 'merge' | 'override' = 'replace',
endpoint: string = 'https://graphql.fauna.com'
) => Promise<string>Takes a schema string and uploads that to the database with the provided Admin Key.
Parameters
faunadbKeyAn Admin key for your databaseschemaAn SDL schema stringmodeImport mode. Defaults tomerge.
Returns a Promise for the response.body from the http request.
See basic example
makeSchema = (typeDefs: string[]) => stringTakes a list of SDL schema strings and combines them. This allows for using extends in your type definitions.
Parameters
typeDefsArray of SDL schema strings
Returns A single SDL schema string.
NOTE: Since
0.2.0, theextendkeyword is not necessary for theQuerytype when used in multiple schemas. Normally, multiple types would cause an error. However,makeSchemawill automatically addextendif multiple instances oftype Queryare found. This is useful for creating reusable schema chunks without having to worry about which schema usestype Querywhile all others areextend type Query.
Any feedback is appreciated, and if folks see ways to make this into a useful and viable package, I will work to make it so! Please fill out a Github Issue if you see anything.
Thanks!
The MIT License (MIT)