2.0.1 • Published 3 years ago

coreql v2.0.1

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

CoreQL

Introduction

CoreQL is an JSON:API Query Builder, it's built on top of React Query for better React interoperability.

Features

  • JSON:API Compatible
  • TypeScript Ready
  • Suspense-Enabled by Default
  • Render as you Fetch Compatible
  • Simple API
  • Almost 100% Test Coverage
  • Battle Tested in Production
  • React Native Support
  • All React Query Features

Quick Start

import { useCollection } from 'coreql';

function Projects() {
  const { data: projects } = useCollection(
    'projects',
    {
      filter: { status: ['active', 'on-hold'] },
      included: ['owner'],
      sort: ['-ownerId', 'title', 'id'],
      fields: { projects: ['title'], users: ['fullName'] },
      format: "denormalized",
    },
  );

  return projects?.map(project => <Project {...project} key={project.id} />);
}

In this example, the React Hook useCollection accepts a resource, an options and a format. resource is the resource name in the API, typically in plural. The options are the query argument we will use against the resource. And the format is the way we want the hook to format the data received from the API.

useCollection returns an objet with the same shape as React Query, we set it to give us denormalized data, to get a formatted data we can later iterate on, without manually dealing with the JSON:API data structure.

Check more Examples for the best practices.

Usage

Install it together with React and React Query.

yarn add coreql react-query react
# npm i coreql react-query react

React Query and React are peer dependencies of CoreQL and should be provided by the project.

Documentation

Guides

Examples

Authors

License

The MIT License.

2.0.1

3 years ago

2.0.0

3 years ago