# HG changeset patch # User Frank Bessou <frank.bessou@logilab.fr> # Date 1613985414 -3600 # Mon Feb 22 10:16:54 2021 +0100 # Node ID 7bfc6143c1b7fc5f8e99aa0cd0a0d5ba270a6a22 # Parent 7e81ecb8d2f4b1114f4e45d9538de3c70081563d feat: make createDataProvider take an rqlClient as input The rqlClient is used so often that we can expect it to be available when creating the data provider. diff --git a/packages/demo/src/App.tsx b/packages/demo/src/App.tsx --- a/packages/demo/src/App.tsx +++ b/packages/demo/src/App.tsx @@ -18,6 +18,7 @@ SimpleShowLayout, DataProvider, } from "react-admin"; +import { client } from "@logilab/cwclientlibjs"; import { createDataProvider } from "ra-cubicweb/dist"; import { schema } from "./schema"; @@ -81,7 +82,10 @@ </Show> ); -const dataProvider = createDataProvider("http://localhost:8080", schema); +const httpClient = new client.CwSimpleHttpClient("http://localhost:8080", true); +const rqlClient = new client.CwRqlClient(httpClient); + +const dataProvider = createDataProvider(rqlClient, schema); dataProvider.getList("toto", { pagination: { page: 1, perPage: 10 }, sort: { field: "id", order: "ASC" }, diff --git a/packages/ra-cubicweb/src/index.ts b/packages/ra-cubicweb/src/index.ts --- a/packages/ra-cubicweb/src/index.ts +++ b/packages/ra-cubicweb/src/index.ts @@ -16,11 +16,9 @@ }; export function createDataProvider<S extends Schema>( - endpoint: string, + rqlClient: client.CwRqlClient, schema: S ): DataProvider { - const httpClient = new client.CwSimpleHttpClient(endpoint, true); - const rqlClient = new client.CwRqlClient(httpClient); return { getList: async (resource: ETypesNames<S>, { pagination, sort }) => { const sortAttribute = sort.field === "id" ? "eid" : sort.field;