npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mozartspa/react-mool-gqless-dataprovider

v0.6.0

Published

A GraphQL data provider for [react-mool](https://github.com/mozartspa/react-mool/) built with [GQless](https://gqless.com/).

Downloads

441

Readme

@mozartspa/react-mool-gqless-dataprovider

A GraphQL data provider for react-mool built with GQless.

Installation

NOTE: you should have already installed gqless and generated the gqless schema.

yarn add @mozartspa/react-mool-gqless-dataprovider

Usage

// import the generated gqless client and schema
import { client, generatedSchema } from "./gqless"
// import this lib
import { createGQlessDataProvider } from "@mozartspa/react-mool-gqless-dataprovider"

export const dataProvider = createGQlessDataProvider({
  gqlessClient: client,
  gqlessSchema: generatedSchema,
})

If the default settings don't suit you, you can customize the behavior:

  • per operation (getOne, getList, create, update and delete)
  • per resource
  • or completely override one of the methods
export const dataProvider = createGQlessDataProvider({
  gqlessClient: client,
  gqlessSchema: generatedSchema,

  // Customize how to extract the ID from the record
  getRecordId: (resource, record) => record.id,

  /*
    Per each operation, you can define:
    - name: which query/mutation should be called
    - input: how to convert the input params to suit your query/mutation expected inputs
    - output: how to extract the data from the result returned by your query/mutation
  */
  operations: {
    // Here we define the behavior of `getOne` operation.
    // If you don't specify one of `name`, `input` or `output`, the default will be used.
    getOne: {
      name: (resource) => `${resource}`,
      input: (resource, params) => {
        return {
          id: Number(params.id),
        }
      },
      output: (resource, result) => {
        return selectFields(result, "*", 2)
      },
    },

    // It's not required to define every operation, just do it for the operation you want
    getList: {
      /* ... */
    },
    create: {
      /* ... */
    },
    update: {
      /* ... */
    },
    delete: {
      /* ... */
    },
  },

  /*
   Customize the behavior per resource
  */
  exceptions: {
    // `article` is the name of our sample resource
    article: {
      /*
       Define the operations you want to override
      */
      operations: {
        getList: {
          name: () => "articles",
          input: (resource, params) => {
            return {
              ...params,
              where: params.filter,
            }
          },
          output: (resource, result) => {
            return {
              items: selectFields(result?.articles, "*", 2) || [],
              total: result?.count || 0,
            }
          },
        },
      },

      /*
       Or you can only customize which fields should be outputted.
       In this case we want `otherField` to be outputted with a depth level of 3.
      */
      recordOutput: (record) => {
        return {
          ...selectFields(record, "*", 2),
          otherField: selectFields(record?.otherField, "*", 3),
        }
      },

      /*
       If you want to completely override a method for this resource
       and implement it yourself then do it in `overrideMethods`.
      */
      overrideMethods: {
        /* override single methods of resource `article` */
      },
    },
  },

  /*
   If you want to completely override a method for all the resources
   and implement it yourself then do it in `overrideMethods`.
  */
  overrideMethods: {
    getOne: /* ... */,
    getList: /* ... */,
    create: /* ... */,
    update: /* ... */,
    delete: /* ... */,
  },

  /*
    The depth value used in the `selectFields` method
  */
  selectFieldsDepth: 2, // default: 1

  /*
    If `true`, the input data passed to the gqless client is checked against the gqless schema provided:
    - unexpected fields are removed.
    - wrong scalar value types are converted accordingly (string -> number and viceversa).
  */
  autofixInputData: false, // default: true

  /*
    How many milliseconds to wait to group queries.
    If `0` or less then batching is disabled.
  */
  queryBatchTimeMS: 80, // default: 50

  /*
   Which error should be thrown in case of failure.
   `defaultHandler` can be called to handle the error in the default way.
  */
  handleError: (error, defaultHandler) => {
    if (error instanceof GQlessError) {
      /* ... */
    } else {
      return defaultHandler()
    }
  },
})