#✅ - Client could not be generated

3 messages · Page 1 of 1 (latest)

frail mango
#

I've been trying to debug an issue that arose when I added Custom API calls to my Amplify backend. I'm trying to generate a client so I can run queries against my API lambda functions. I've boiled the issue down to the data backend client. Here is some simple code to show where my error is occuring:

`import type { Schema } from "../amplify/data/resource";
import { Amplify } from 'aws-amplify';
import outputs from '../amplify_outputs.json';

import { generateClient } from "aws-amplify/data";

await Amplify.configure(outputs);
const client = generateClient<Schema>();

const fetchUsers = async () => {
const {data, errors} = await client.queries.listUsers();
if(errors) {
console.log('!errors occured! - ' + JSON.stringify(errors));
}
return data;
}
console.log(JSON.stringify(await fetchUsers()));`

This fails with the following error:
Uncaught Error: Client could not be generated. This is likely due to Amplify.configure() not being called prior to generateClient() or because the configuration passed to Amplify.configure() is missing GraphQL provider configuration. at Object.get (aws-amplify_data.js?v=1e467bca:11065:11) at fetchUsers (main.tsx:28:47) at main.tsx:34:34

frail mango
#

For anyone suffering from this same error...I found the cause. I had neglected to add the "data" resource definition to the backend. So the code all looked fine in the IDE but was failing with this obscure error when deployed.

clear trenchBOT
#

✅ - Client could not be generated