https://github.com/ptpaterson/faunadb-graphql-schema-loader
A package for making GraphQL schemas easy to work with using FaunaDB.
https://github.com/ptpaterson/faunadb-graphql-schema-loader
faunadb graphql typescript
Last synced: 3 months ago
JSON representation
A package for making GraphQL schemas easy to work with using FaunaDB.
- Host: GitHub
- URL: https://github.com/ptpaterson/faunadb-graphql-schema-loader
- Owner: ptpaterson
- License: mit
- Created: 2020-06-30T19:15:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-12T12:19:08.000Z (about 2 years ago)
- Last Synced: 2024-11-29T16:46:34.713Z (3 months ago)
- Topics: faunadb, graphql, typescript
- Language: TypeScript
- Homepage:
- Size: 1.1 MB
- Stars: 14
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FaunaDB GraphQL Schema Loader
[](https://badge.fury.io/js/faunadb-graphql-schema-loader) [](https://lbesson.mit-license.org/)
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`.
# Basic Usage
```javascript
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))
```# API
## `importSchema`
```typescript
importSchema = (
faunadbKey: string,
schema: string,
mode: 'replace' | 'merge' | 'override' = 'replace',
endpoint: string = 'https://graphql.fauna.com'
) => Promise
```Takes a schema string and uploads that to the database with the provided Admin Key.
**Parameters**
- `faunadbKey` An Admin key for your database
- `schema` An SDL schema string
- `mode` Import mode. Defaults to `merge`.**Returns** a Promise for the `response.body` from the http request.
See [basic example](/examples/basic/setup.js)
## `makeSchema`
```typescript
makeSchema = (typeDefs: string[]) => string
```Takes a list of SDL schema strings and combines them. This allows for using `extends` in your type definitions.
**Parameters**
- `typeDefs` Array of SDL schema strings
**Returns** A single SDL schema string.
See [extended types example](/examples/extended-types/setup.js)
> NOTE: Since `0.2.0`, the `extend` keyword is not necessary for the `Query` type when used in multiple schemas. Normally, multiple types would cause an error. However, `makeSchema` will automatically add `extend` if multiple instances of `type Query` are found. This is useful for creating reusable schema chunks without having to worry about which schema uses `type Query` while all others are `extend type Query`.
# Using and Contributing
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!
# License
The MIT License (MIT)