panter/ra-data-prisma

Adding headers

Closed this issue · 2 comments

Isn't it possible to add headers (e.g., authorization) at this point?

I found a similar issue here in the related project but it seems the workaround is not available here.

you can use the exact same method:

import buildGraphQLProvider from "@ra-data-prisma/dataprovider";

const client = // init your apollo client with context link
 buildGraphQLProvider({client})

Thank you for your suggestion. I tried the method but it didn't work.
It seems that the built provider does not have the correct CRUD operation but where did I make something wrong?

// App.tsx
function App() {
  const cache = new InMemoryCache();
  const client = new ApolloClient({
    uri:
      process.env.NODE_ENV === "development"
        ? process.env.REACT_APP_DATABASE_URL_DEV
        : process.env.REACT_APP_DATABASE_URL,
    cache,
  });

  const dataProvider = useDataProvider(client);
  
  // use dataProvider as the provider
}

// useDataProvider.ts
export const useDataProvider = (
  client: ApolloClient<NormalizedCacheObject>
) => {
  const [dataProvider, setDataProvider] = useState<any>(null);

  useEffect(() => {
    buildGraphQLProvider({ client }).then((result: any) => {
      setDataProvider({ result });
      console.log(result.toString());
    });
  }, []);

  return dataProvider;
};

The error shown when I access some list page:

Uncaught (in promise) Error: Unknown dataProvider function: getList
    at Proxy.<anonymous> (useDataProvider.js:130)
    at useQueryWithStore.js:182
    at new Promise (<anonymous>)
    at useQueryWithStore.js:181
    at invokePassiveEffectCreate (react-dom.development.js:23487)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at flushPassiveEffectsImpl (react-dom.development.js:23574)
    at unstable_runWithPriority (scheduler.development.js:468)
    at runWithPriority$1 (react-dom.development.js:11276)
    at flushPassiveEffects (react-dom.development.js:23447)
    at performSyncWorkOnRoot (react-dom.development.js:22269)
    at react-dom.development.js:11327
    at unstable_runWithPriority (scheduler.development.js:468)
    at runWithPriority$1 (react-dom.development.js:11276)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322)
    at flushSyncCallbackQueue (react-dom.development.js:11309)
    at scheduleUpdateOnFiber (react-dom.development.js:21893)
    at Object.enqueueSetState (react-dom.development.js:12467)
    at Router.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:365)
    at Router.js:34
    at listener (history.js:155)
    at history.js:173
    at Array.forEach (<anonymous>)
    at Object.notifyListeners (history.js:172)
    at setState (history.js:561)
    at history.js:598
    at Object.confirmTransitionTo (history.js:145)
    at handlePop (history.js:596)
    at handleHashChange (history.js:586)