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

ra-data-postgraphile

v0.7.1

Published

Postgraphile data provider for react-admin

Downloads

109

Readme

ra-data-postgraphile

Build Status

Postgraphile data provider for react-admin

This data provider heavily extends https://github.com/BowlingX/ra-postgraphile with a more generic approach.

Install

$ yarn add ra-data-postgraphile / npm install ra-data-postgraphile --save

Usage

The ra-data-postgraphile data provider accepts these arguments:

  • client - The ApolloClient instance to use.

  • cache - optional apollo cache default: return new InMemoryCache({dataIdFromObject: (object: any) => object.nodeId || null})

  • config - optional configuration

    pgDataProvider({client, [cache], [config]})

The following examples shows the basic usage:

import React, { useEffect, useState } from 'react'
import { Admin, Resource, Loading } from 'react-admin'
import pgDataProvider from 'ra-data-postgraphile'
import { CompanyList, CompanyEdit, CompanyCreate } from './posts'

const App = () => {
  const [dataProvider, setDataProvider] = useState(null)

  useEffect(() => {
    ;(async () => {
      const dataProvider = await pgDataProvider({
        uri: '/graphql',
        options: {
          resources: {
            Company: {
              pluralizedName: 'Companies',
            }
          }
        }
      })
      setDataProvider(dataProvider)
    })()
  }, [])

  if (!dataProvider) {
    return <Loading />
  }
  return (
    <Admin dataProvider={dataProvider}>
      <Resource
        name="Company"
        list={CompanyList}
        edit={CompanyEdit}
        create={CompanyCreate}
      />
    </Admin>
  )
}

export default App

Features

Filter Operations

It is possible to use different filter operations for the list filters. The operation can be provided in the filter name:

name = <propertyName> <operation>

The possible operations depend on the field type of the propertyName.

Example:

Filter field refId is null: refId null

See [src/filters.ts] for the integrated filters:

Compound Primary Keys

Because react admin expect that a record has a single id field ra-data-postgraphile detects compound primary keys and switch to use nodeId as the internal id for the record.

The internal representation of a record is different for compound keys. The original id field is copied to __rawId and nodeId is copied into the id field. This makes sure react admin receives a unique id value.

When your project contains compound primary keys it is also necessary to change the apollo cache to not use the id field. Use this code to create an apollo instance which uses the nodeId as primary key:

  const cache = new InMemoryCache({
    dataIdFromObject: object => object.nodeId || null
  })
  const client = new ApolloClient({
    uri: '/graphql',
    cache,
  })

Limitations

ra-data-postgraphile expects these plugins to be installed on the postgraphile server:

const PgSimplifyInflectorPlugin = require('@graphile-contrib/pg-simplify-inflector')
const PgConnectionFilterPlugin = require('postgraphile-plugin-connection-filter')

TODO

  • implement DELETE_MANY

Release

To release the package:

  • update changes (version should match the one you chose in the next step)

  • git add CHANGELOG.md to make sure changelog update is added to the next commit done by yarn version

  • update the version: yarn version [--major|minor|patch]

  • push changes: git push && git push --tags

  • publish to npmjs.com by running yarn release (might require to run yarn login beforehand)

License

ra-data-postgraphile is licensed under the Apache 2.0, sponsored and supported by Lovely Systems.