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

@vitramir/ra-data-prisma

v0.1.13

Published

A Prisma data provider for react-admin

Downloads

2

Readme

ra-data-prisma

A react-admin data provider for Prisma. This project is currently under active development. Beta releases will be published regularily. Feedback about your applications/use cases is very welcome!

Installation

Install with:

npm install --save graphql ra-data-prisma

or

yarn add graphql ra-data-prisma

Usage

Create your react-admin app and bootstrap the data provider like so:

import { PostList, PostEdit, PostCreate } from './post';
import buildPrismaProvider from 'ra-data-prisma';

class App extends Component {
    constructor() {
        super();
        this.state = { dataProvider: null };
    }
    componentDidMount() {
        buildPrismaProvider({ client })
            .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} />
            </Admin>
        );
    }
}

This assumes your have a resource of the type Post, which will be automatically recognized if you provided the CRUD logic for the type in the usual prisma conventions, i.e. you schema should look something like:

type Query {
  
  posts(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Post]!
  post(where: PostWhereUniqueInput!): Post
  postsConnection(where: PostWhereInput, orderBy: PostOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): PostConnection!

}

type Mutation {
  createPost(data: PostCreateInput!): Post!
  updatePost(data: PostUpdateInput!, where: PostWhereUniqueInput!): Post
  deletePost(where: PostWhereUniqueInput!): Post
}

type Post {
  id: ID!
  text: String!
}

This means you can either hook up your data provider directly to your prisma database or import the types from prisma generated code in your schema and override/customize the resolvers or simply forward them to your database unsing resolver-forwarding. Let the Prisma magic happen :)

I will publish one of our projects using this library as a complete/working sample project.

Options

Customize the Apollo client

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

buildPrismaProvider({ clientOptions: { uri: 'https://your-prisma-endpoint', ...otherApolloOptions } });

Or supply your client directly with:

buildPrismaProvider({ client: myClient });

Contribute

To include your local fork into a test project, add the library locally to your projects package.json

"dependencies": {
  "ra-data-prisma": "file:../path/to/your/fork/ra-data-prisma",
  ... your other dependencies
}

and run npm i. For me, hot reloading works with my react-admin test app.

To have your changes in the source directory reflect in the lib, remember to build!

yarn build

Remember to always make persistent changes in the ./src/ directory and rebuild. Your dirty work can be done directly in the ./lib/ folder, but will be overriden the next time you build.

For testing, run

jest

The test suite is currently rather thin. If you would like to contribute tests for nested types that would be great :)

Glad about feedback & contributions!

More

There is another work in progress ongoing: https://github.com/Weakky/ra-data-prisma

Thanks for the feedback @Weakky!