0.1.8 • Published 2 years ago

bananas-sanity v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

bananas-sanity

Stable Release Documentation Blazing Fast gzip size license


Installation

npm i bananas-sanity
yarn add bananas-sanity # with yarn

Getting started

Basic query

import { SanityQuery } from 'bananas-sanity';

const query = new SanityQuery({
  query: `*[_type == "dog"]`,
});

const result = await query.fetch();

With parameters

const query = new SanityQuery({
  query: `*[_type == "dog" && breed == $breed]`,
});

const result = await query.fetch({
    params: {
        breed: 'golden retriever',
    },
});

Using mixins

Transform a query in a testable and predictable way.

import { sanityMixin, SanityQuery } from 'bananas-sanity';

const query = new SanityQuery({
  query: sanityMixin(({ filterDrafts }) => ({
    filterDrafts, // filters Sanity drafts
    /* you can add custom mixins or change order of built-in mixins */
  }))`*[_type == "giraffe"]`,
});

TypeScript support

type Apple = { /* ... */ }
const query = new SanityQuery<Apple, {
    color: "green" | "red",
}>({
  query: `*[_type == "apple" && color == $color]`,
});

{{>main-index}}

Authors


MIT License.

0.1.8

2 years ago

0.1.7

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago