Skip to content

oughtinc/ra-postgraphile-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Admin Potgraphile Data Provider

This is a data provider that connects postgraphile with react admin. It is build on top of ra-data-graphql. n.b. the docs for ra-data-graphql are out of date.

Under active development. Although I am using this library in production, it does not cover the full API of react admin. Please raise an issue if there is something in particular that you need.

API

buildGraphQLProvider(options)

Creates a data provider

Params

  1. Options object * apolloHttpLinkOptions: Options passed to apollo http link. docs here * buildQuery (optional): You can use this to extend ra-postgraphile-client

simple example

import buildPostgraphileProvider from 'ra-postgraphile-provider'

const raDataProvider = buildPostgraphileProvider()

Example with auth

import buildPostgraphileProvider from 'ra-postgraphile-provider'

const raDataProvider = buildPostgraphileProvider({
  apolloHttpLinkOptions: {
    uri: `my-custom-graphql-enpoint.io/graphwhat`
    fetch: (url, options) => {
      // You can add custom auth logic with a wrapper around fetch
      const token = localStorage.getItem('token')

      if (!token) {
        return ;
      } if (jwt.decode(token).exp < Date.now()) {
        localStorage.removeItem('token')
        return ;
      }

      const headers = {
        ...options.headers,
        authorization: `bearer ${token}`
      }
      return fetch(url, ({ ...options, headers }))
    }
  }
})

Authentication

You will need to implement an auth provider to handle log in and log out.

todo

  • Build out test suite
    • Build postgraphile server mocker
    • add test script
    • build out coverage
  • Write readme
  • Test on live project
  • publish
  • Cover all query types
    • GET_LIST
      • pagination
      • sort
      • order
      • filter
    • GET_ONE
      • id
    • UPDATE
      • id
      • data
    • UPDATE_MANY
      • ids
      • data
    • DELETE
      • id
    • DELETE_MANY
      • ids
    • GET_MANY
      • ids
    • GET_MANY_REFERENCE
      • target
      • id
      • pagination
      • perPage
      • sort
      • filter

About

Postgraphile data provider for react admin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%