Open
Description
Describe the bug
The code below will cause "Subscribe only available for AWS AppSync endpoint" when calling "client.models.Todo.observeQuery().subscribe" in react code.
import { Amplify } from 'aws-amplify';
import outputs from '../amplify_outputs.json';
Amplify.configure(outputs);
const existingConfig = Amplify.getConfig();
Amplify.configure({
...existingConfig,
API: {
REST: outputs.custom.API,
},
});
It can be fixed by adding line ...existingConfig.API
:
import { Amplify } from 'aws-amplify';
import outputs from '../amplify_outputs.json';
Amplify.configure(outputs);
const existingConfig = Amplify.getConfig();
Amplify.configure({
...existingConfig,
API: {
...existingConfig.API,
REST: outputs.custom.API,
},
});
Also warning message "warning "GraphQLAPI resolveConfig - The API configuration is missing"
To Reproduce
Steps to reproduce the behavior:
- Create an amplify gen2 react-vite app following the quickstart: https://docs.amplify.aws/react/start/quickstart/
- Add reset api follow this guide: https://docs.amplify.aws/react/build-a-backend/add-aws-services/rest-api/set-up-rest-api/#initialize-amplify-api
- Then we get error "client.models.Todo.observeQuery().subscribe" when calling "client.models.Todo.observeQuery().subscribe"
Expected behavior
No error
Desktop (please complete the following information):
- OS: Windows
- Browser Chrome
Additional context
- Bug is also reported here: Amplify configuration issue inside micro front-end environnement amplify-js#12986 by multiple developers, but I think it is also a doc issue need to be updated for Rest API setup.