ra-data-hasura-graphql
ra-data-hasura-graphql copied to clipboard
Following the "load references" guide errors out
With
import { ApolloClient } from "apollo-boost";
import buildDataProvider from 'ra-data-hasura-graphql';
import { buildApolloArgs, buildArgs, buildFields, buildGqlQuery, buildMetaArgs } from 'ra-data-hasura-graphql/src/buildGqlQuery';
import { buildQueryFactory } from 'ra-data-hasura-graphql/src/buildQuery';
import buildVariables from 'ra-data-hasura-graphql/src/buildVariables';
import getResponseParser from 'ra-data-hasura-graphql/src/getResponseParser';
const buildFieldsCustom = (type) => {
let res = buildFields(type);
debugger;
return res;
};
const buildGqlQueryCustom = (iR) =>
buildGqlQuery(
iR,
buildFieldsCustom,
buildMetaArgs,
buildArgs,
buildApolloArgs
);
const buildQuery = buildQueryFactory(
buildVariables,
buildGqlQueryCustom,
getResponseParser
);
const client = new ApolloClient({
uri: 'https://api.test/v1/graphql',
headers: {
'x-hasura-admin-secret': 'xxxxxxxxxxxx',
// 'Authorization': `Bearer xxxx`,
}
});
export default buildDataProvider({ client, buildQuery });
You need to import all the methods name like this at the top code
import {
CREATE,
DELETE,
DELETE_MANY,
GET_LIST,
GET_MANY,
GET_MANY_REFERENCE,
GET_ONE,
UPDATE,
UPDATE_MANY,
} from 'react-admin';
after the export it like this:
export default buildDataProvider({
client,
buildQuery,
}).then((dataProviderHasura) => ({
getList: (resource, params) => dataProviderHasura(GET_LIST, resource, params),
getOne: (resource, params) => dataProviderHasura(GET_ONE, resource, params),
getMany: (resource, params) => dataProviderHasura(GET_MANY, resource, params),
getManyReference: (resource, params) =>
dataProviderHasura(GET_MANY_REFERENCE, resource, params),
update: (resource, params) => dataProviderHasura(UPDATE, resource, params),
updateMany: (resource, params) =>
dataProviderHasura(UPDATE_MANY, resource, params),
create: (resource, params) => dataProviderHasura(CREATE, resource, params),
delete: (resource, params) => dataProviderHasura(DELETE, resource, params),
deleteMany: (resource, params) =>
dataProviderHasura(DELETE_MANY, resource, params),
}));
The npm package should export all those functions, isn't? because this: ra-data-hasura-graphql/src/* won't work
@gengue is correct. Currently, there is no way to import these from npm package as src/* is part of .npmignore and isn't published to npm at all.
To remedy this, I ended up git cloning src/* to a local sub dir and import from there instead. This is far from ideal, but it works.