All Projects → Weakky → Ra Data Opencrud

Weakky / Ra Data Opencrud

Licence: mit
A react-admin data provider for Prisma and GraphCMS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ra Data Opencrud

Shop
🛍🛒 Full-stack React/Prisma/TS/GraphQL E-Commerce Example
Stars: ✭ 359 (+152.82%)
Mutual labels:  graphql, prisma
Typegraphql Prisma
Prisma 2 generator to emit TypeGraphQL types and CRUD resolvers from your Prisma 2 schema
Stars: ✭ 137 (-3.52%)
Mutual labels:  graphql, prisma
Admin On Rest
A frontend framework for building admin SPAs on top of REST services, using React and Material Design.
Stars: ✭ 392 (+176.06%)
Mutual labels:  graphql, react-admin
Prisma Ecommerce
💰A graphql e-commerce real-world fullstack example (backoffice included)
Stars: ✭ 231 (+62.68%)
Mutual labels:  graphql, prisma
Howtographql
The Fullstack Tutorial for GraphQL
Stars: ✭ 7,999 (+5533.1%)
Mutual labels:  graphql, prisma
ra-data-prisma
Packages to connect react-admin with prisma version 2
Stars: ✭ 73 (-48.59%)
Mutual labels:  prisma, react-admin
Este
This repo is suspended.
Stars: ✭ 5,467 (+3750%)
Mutual labels:  graphql, prisma
Prisma Examples
🚀 Ready-to-run Prisma example projects
Stars: ✭ 3,017 (+2024.65%)
Mutual labels:  graphql, prisma
Nexus Plugin Prisma
A plugin for Nexus that integrates Prisma
Stars: ✭ 728 (+412.68%)
Mutual labels:  graphql, prisma
Graphql Prisma Typescript
🏡 GraphQL server reference implementation (Airbnb clone) in Typescript using Prisma & graphql-yoga
Stars: ✭ 723 (+409.15%)
Mutual labels:  graphql, prisma
Canner
⚡️[NOT MAINTAINED] Content Management Framework creates custom CMS fast and easy. Support data sources such as Firebase/Firestore, GraphQL and Restful APIs.
Stars: ✭ 2,472 (+1640.85%)
Mutual labels:  graphql, prisma
Production Ready Expressjs Server
Express.js server that implements production-ready error handling and logging following latest best practices.
Stars: ✭ 101 (-28.87%)
Mutual labels:  graphql, prisma
Modern Graphql Tutorial
📖 A simple and easy GraphQL tutorial to get started with GraphQL.
Stars: ✭ 219 (+54.23%)
Mutual labels:  graphql, prisma
Awesome Prisma
A collection of awesome things regarding Prisma ecosystem.
Stars: ✭ 310 (+118.31%)
Mutual labels:  graphql, prisma
Prisma Auth0 Example
Boilerplate Prisma Startup
Stars: ✭ 184 (+29.58%)
Mutual labels:  graphql, prisma
Pizzaql
🍕 Modern OSS Order Management System for Pizza Restaurants
Stars: ✭ 631 (+344.37%)
Mutual labels:  graphql, prisma
React Admin Low Code
react-admin (via ra-data-hasura-graphql provider) + hasura = :)
Stars: ✭ 161 (+13.38%)
Mutual labels:  graphql, react-admin
Product Boilerplate
Quickly ship your apps with the power of code generation.
Stars: ✭ 677 (+376.76%)
Mutual labels:  graphql, prisma
Prisma Kubernetes Deployment
Demo how to deploy a Prisma server to a Kubernetes cluster.
Stars: ✭ 89 (-37.32%)
Mutual labels:  graphql, prisma
Serverless Prisma
AWS Serverless Prisma Boilerplate
Stars: ✭ 126 (-11.27%)
Mutual labels:  graphql, prisma

ra-data-opencrud

Prisma on steroids: easily build backoffices with Prisma/GraphCMS plugged on react-admin!

Work in progress

If you wanna give it a try anyway, here's a quick preview on codesandbox. The API is hosted on Prisma's public servers, which means the API is limited to 10 API calls per seconds. Be aware that it might not be working because of that, or that performances may be poor.

Edit ra-data-prisma

Summary

What is react admin ? And what's ra-data-opencrud ?

Find out more about the benefits of using react-admin with Prisma here.

Installation

Install with:

npm install --save graphql ra-data-opencrud

or

yarn add graphql ra-data-opencrud

Usage

This example assumes a Post type is defined in your datamodel.

// in App.js
import React, { Component } from 'react';
import buildOpenCrudProvider from 'ra-data-opencrud';
import { Admin, Resource, Delete } from 'react-admin';

import { PostCreate, PostEdit, PostList } from './posts';

const client = new ApolloClient();

class App extends Component {
    constructor() {
        super();
        this.state = { dataProvider: null };
    }
    componentDidMount() {
        buildOpenCrudProvider({ clientOptions: { uri: 'your_prisma_or_graphcms_endpoint' }})
            .then(dataProvider => this.setState({ dataProvider }));
    }

    render() {
        const { dataProvider } = this.state;

        if (!dataProvider) {
            return <div>Loading</div>;
        }

        return (
            <Admin dataProvider={dataProvider}>
                <Resource name="Post" list={PostList} edit={PostEdit} create={PostCreate} remove={Delete} />
            </Admin>
        );
    }
}

export default App;

And that's it, buildOpenCrudProvider will create a default ApolloClient for you and run an introspection query on your Prisma/GraphCMS endpoint, listing all potential resources.

Options

Customize the Apollo client

You can either supply the client options by calling buildOpenCrudProvider like this:

buildOpenCrudProvider({ clientOptions: { uri: 'your_prisma_or_graphcms_endpoint', ...otherApolloOptions } });

Or supply your client directly with:

buildOpenCrudProvider({ client: myClient });

Overriding a specific query

The default behavior might not be optimized especially when dealing with references. You can override a specific query by decorating the buildQuery function:

With a whole query

// in src/dataProvider.js
import buildOpenCrudProvider, { buildQuery } from 'ra-data-opencrud';

const enhanceBuildQuery = introspection => (fetchType, resource, params) => {
    const builtQuery = buildQuery(introspection)(fetchType, resource, params);

    if (resource === 'Command' && fetchType === 'GET_ONE') {
        return {
            // Use the default query variables and parseResponse
            ...builtQuery,
            // Override the query
            query: gql`
                query Command($id: ID!) {
                    data: Command(id: $id) {
                        id
                        reference
                        customer {
                            id
                            firstName
                            lastName
                        }
                    }
                }`,
        };
    }

    return builtQuery;
}

export default buildOpenCrudProvider({ buildQuery: enhanceBuildQuery })

Or using fragments

You can also override a query using the same API graphql-binding offers.

buildQuery accept a fourth parameter which is a fragment that will be used as the final query.

// in src/dataProvider.js
import buildOpenCrudProvider, { buildQuery } from 'ra-data-opencrud';

const enhanceBuildQuery = introspection => (fetchType, resource, params) => {
    if (resource === 'Command' && fetchType === 'GET_ONE') {
        // If you need auto-completion from your IDE, you can also use gql and provide a valid fragment
        return buildQuery(introspection)(fetchType, resource, params, `{
            id
            reference
            customer { id firstName lastName }
        }`);
    }

    return buildQuery(introspection)(fetchType, resource, params);
}

export default buildOpenCrudProvider({ buildQuery: enhanceBuildQuery })

As this approach can become really cumbersome, you can find a more elegant way to pass fragments in the example under /examples/prisma-ecommerce

Customize the introspection

These are the default options for introspection:

const introspectionOptions = {
    include: [], // Either an array of types to include or a function which will be called for every type discovered through introspection
    exclude: [], // Either an array of types to exclude or a function which will be called for every type discovered through introspection
}

// Including types
const introspectionOptions = {
    include: ['Post', 'Comment'],
};

// Excluding types
const introspectionOptions = {
    exclude: ['CommandItem'],
};

// Including types with a function
const introspectionOptions = {
    include: type => ['Post', 'Comment'].includes(type.name),
};

// Including types with a function
const introspectionOptions = {
    exclude: type => !['Post', 'Comment'].includes(type.name),
};

Note: exclude and include are mutualy exclusives and include will take precendance.

Note: When using functions, the type argument will be a type returned by the introspection query. Refer to the introspection documentation for more information.

Pass the introspection options to the buildApolloProvider function:

buildApolloProvider({ introspection: introspectionOptions });

Tips and workflow

Performance issues

As react-admin was originally made for REST endpoints, it cannot always take full advantage of GraphQL's benefits.

Although react-admin already has a load of bult-in optimizations (Read more here and here), it is not yet well suited when fetching n-to-many relations (multiple requests will be sent).

To counter that limitation, as shown above, you can override queries to directly provide all the fields that you will need to display your view.

Suggested workflow

As overriding all queries can be cumbersome, this should be done progressively.

  • Start by using react-admin the way you're supposed to (using <ReferenceField /> and <ReferenceManyField /> when trying to access references)
  • Detect the hot-spots
  • Override the queries on those hot-spots by providing all the fields necessary (as shown above)
  • Replace the <ReferenceField /> by simple fields (such as <TextField />) by accessing the resource in the following way: <TextField source="product.name" />
  • Replace the <ReferenceManyField /> by <ArrayField /> using the same technique as above

Contributing

Use the example under examples/prisma-ecommerce as a playground for improving ra-data-opencrud.

To easily enhance ra-data-opencrud and get the changes reflected on examples/prisma-ecommerce, do the following:

  • cd ra-data-opencrud
  • yarn link
  • cd examples/prisma-ecommerce
  • yarn link ra-data-opencrud

Once this is done, the ra-data-opencrud dependency will be replaced by the one on the repository. One last thing, don't forget to transpile the library with babel by running the following command on the root folder

yarn watch

You should now be good to go ! Run the tests with this command:

jest
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].