Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/basehub-ai/basehub
SDK for BaseHub—Fast, Collaborative, AI-Native Content Management.
https://github.com/basehub-ai/basehub
basehub cms content graphql javascript typescript
Last synced: 4 days ago
JSON representation
SDK for BaseHub—Fast, Collaborative, AI-Native Content Management.
- Host: GitHub
- URL: https://github.com/basehub-ai/basehub
- Owner: basehub-ai
- License: mit
- Created: 2023-08-16T23:32:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-29T20:58:27.000Z (14 days ago)
- Last Synced: 2024-10-29T22:53:29.074Z (14 days ago)
- Topics: basehub, cms, content, graphql, javascript, typescript
- Language: TypeScript
- Homepage: https://basehub.com
- Size: 1.47 MB
- Stars: 146
- Watchers: 2
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `basehub` 🪄
JavaScript / TypeScript SDK for [BaseHub](https://basehub.com/), a very fast headless cms.
**Features:**
- ✨ Infers types from your BaseHub repository... _meaning IDE autocompletion works great._
- 🏎️ No dependency on graphql... _meaning your bundle is more lightweight._
- 🌐 Works everywhere `fetch` is supported... _meaning you can use it anywhere._## Install
```zsh
npm i basehub
```## Quickstart
#### 1. Set required environment variable:
```zsh
# .envBASEHUB_URL="https://basehub.com///graphql?token="
# or disambiguated
BASEHUB_TEAM=""
BASEHUB_REPO=""
BASEHUB_TOKEN=""
```💡 Get your read token from the Connect panel: `https://basehub.com///connect`
#### 2. Generate client:
```zsh
npx run basehub
```**❗️ Important:** make sure you run the generator before your app's build step. A common pattern is to run it in your [postinstall script](https://docs.npmjs.com/cli/v9/using-npm/scripts).
#### 3. Use in your app:
This example uses [Next.js](https://nextjs.org/), but you can use any JavaScript framework.
```tsx
// app/page.tsximport { basehub } from "basehub";
const Page = async () => {
const firstQuery = await basehub().query({
__typename: true,
});return
{JSON.stringify(firstQuery, null, 2)};
};export default Page;
```## Choosing another output directory with `--output`
By default, `basehub` will generate the SDK inside `node_modules/basehub/dist/generated-client`. While this is a good default as it allows you to quickly get started, this approach modifies `node_modules` which, depending on your setup, might result in IDE or build pipeline issues. If this happens, please report the issue!
Additionally, you might want to connect to more than one BaseHub Repository.
To solve this, `basehub` supports an `--output` argument that specifies the directory in which the SDK will be generated. You then can use this directory to import generated stuff. For example: running `basehub --output .basehub` will generate the SDK in a new `.basehub` directory in the root of your project. You can then `import { basehub } from '..//.basehub'` and use the SDK normally.
We recommend including the new `--output` directory to `.gitignore`, as these generated files are not precisely relevant to Git, but that's up to you and shouldn't affect the SDK's behavior.
## About the SDK
The `basehub` sdk is generated with [GenQL](https://genql.dev/) (read their [docs](https://genql.dev/docs)). Thank you [Morse](https://github.com/remorses) for creating such a great package.