MrHertal/react-admin-amplify

undefined error on first query

Closed this issue ยท 3 comments

I've followed AWS's Amplify tutorial as well as your and react-admin tutorials.

Here is my App.js

import { Amplify } from "@aws-amplify/core";
import React from "react";
import { Resource, ListGuesser, Admin } from "react-admin";
import { buildDataProvider } from "react-admin-amplify";
import awsExports from "./aws-exports";
import * as mutations from "./graphql/mutations";
import * as queries from "./graphql/queries";

Amplify.configure(awsExports); // Configure Amplify the usual way

function App() {
    return (
        <Admin // Replace the Admin component of react-admin
            dataProvider={buildDataProvider({ queries, mutations })}
        >
            <Resource name="todos" list={ListGuesser} />
        </Admin>
    );
}

export default App;

In my models I have

type Todo @model {
  id: ID!
  name: String!
  description: String
}

However, upon running the application http://localhost:3000/#/todos I get no results, the loader spinner keeps spinning and there is a following message on console:

Screen Shot 2021-01-06 at 19 14 34

Hi,

Your code looks fine.

Did you add the Auth category on your Amplify backend?

You may need to change the authMode option.
It is set to AMAZON_COGNITO_USER_POOLS by default but it looks like your API is public.

You may try API_KEY instead.

Ah, that was it. Thank you!

This works:

<Admin
            dataProvider={buildDataProvider({queries, mutations}, {authMode: "API_KEY"})}
        >

I'm wondering where that error message is coming from? react-admin? Why would it show up us just undefined

Great :)

You are right, the error is not explicit.

You made me realize that the data provider does not handle errors correctly. It should throw errors like explained here.

I will try to make a PR ASAP