marmelab / ra-supabase

Supabase adapter for react-admin, the frontend framework for building admin applications on top of REST/GraphQL services.
MIT License
150 stars 27 forks source link

Error: TypeError: primaryKeys is undefined #37

Closed Revarh closed 1 year ago

Revarh commented 1 year ago

Hi everyone,

I am facing an issue using React Admin with ra-supabase. The following message appears in the logs and I can't find why:

TypeError: primaryKeys is undefined

Here are my codes:

supabase.js

import { createClient } from '@supabase/supabase-js';

export const supabaseClient = createClient(
  process.env.REACT_APP_SUPABASE_URL,
  process.env.REACT_APP_SUPABASE_ANON_KEY
)

baseDataProvider.js

import { supabaseDataProvider } from 'ra-supabase';
import { supabaseClient } from './supabase';

const baseDataProvider = supabaseDataProvider({
    instanceUrl: process.env.REACT_APP_SUPABASE_URL,
    apiKey: process.env.REACT_APP_SUPABASE_ANON_KEY,
    supabaseClient
});

export default baseDataProvider;

dataProvider.js

import baseDataProvider from './baseDataProvider';
import {supabaseClient} from './supabase';

const dataProvider = {
  ...baseDataProvider,
  getList: async (resource, params) => {
    let result = null
    result = await baseDataProvider.getList(resource, params)
    return result
  },
}

App.js

import { Admin, CustomRoutes, ListGuesser } from 'react-admin';
import { LoginPage, SetPasswordPage, ForgotPasswordPage } from 'ra-supabase';
import { BrowserRouter, Route } from 'react-router-dom'
import { Resource } from '@react-admin/ra-rbac';

import dataProvider from './Database/dataProvider';

export const App = () => {
  const classes = CustomStyles();

  return (
    <BrowserRouter>
      <Admin
        dataProvider={dataProvider}
      >
        <CustomRoutes noLayout>
            <Route
                path={SetPasswordPage.path}
                element={<SetPasswordPage />}
            />
            <Route
                path={ForgotPasswordPage.path}
                element={<ForgotPasswordPage />}
            />
        </CustomRoutes>

        <Resource name="test" list={ListGuesser} />
      </Admin>
    </BrowserRouter>
  )
}

Finally, in supabase:

create table
  public.test (
    id bigint generated by default as identity,
    created_at timestamp with time zone not null default now(),
    first_name text null,
    last_name text null,
    constraint test_pkey primary key (id)
  ) tablespace pg_default;

Thank you in advance for your answers !

Best, R.

djhi commented 1 year ago

Thanks for reporting this. Please provide a sample application showing the issue.

Revarh commented 1 year ago

Hi, Here is a test repo with the error: https://github.com/Revarh/test-ra-error Thank you

slax57 commented 1 year ago

Hi, Thank you for the repo. However, to run the project and reproduce the error, we are missing an access to your supabase instance, or instructions on how to setup our own instance with the database schema and data.

Also, could you please provide the full stacktrace of the error (with source file names and line numbers)? It would at least indicate from which file the error originated.

Lastly, I see that you are using a custom dataProvider on top of the supabase dataProvider. Can you check if you still have the error without it? (which would tend to indicate the error actually comes from this custom implementation or from the Proxy)

Thanks.

Revarh commented 1 year ago

Hi, In the meantime, trying to eliminate leads, I managed to find the issue: one package was either corrupted, or too new. Let me explain:

The project I am working on is a copy of one of a colleague, which totally works using the same code. Basically, I understood that supabaseAuthProvider() gives basic methods GetList, GetOne, etc... But it was not working with me. Either I had to create my own methods, or something was wrong. So I was misleaded for a while.

Finally I updated my packages to match those of my colleague, and only ONE was different: "@raphiniert/ra-data-postgrest" which I had in version "^2.0.0-alpha.3", and my colleague "^1.20".

Now everything is working properly.

I hope this will help if anyone gets the same error.

Best, R.

slax57 commented 1 year ago

Alright. Glad you managed to solve your issue then, and thank you for your feedback :slightly_smiling_face: