aws-amplify / aws-amplify/docs

[Gen2] Rest API setup will cause error "Subscribe only available for AWS AppSync endpoint"

Open
#7,665 0 comments 0 reactions 0 assignees View on GitHub
amplify/backend p2
Dominant language
MDX
Stars
506
Forks
1.1k
Avg merge
3h 14m
Merged PRs (30d)
1

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:
1. Create an amplify gen2 react-vite app following the quickstart: https://docs.amplify.aws/react/start/quickstart/
2. 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
3. Then we get error "client.models.Todo.observeQuery().subscribe" when calling "client.models.Todo.observeQuery().subscribe"

**Expected behavior**
No error

**Screenshots**
![image](https://github.com/aws-amplify/docs/assets/14363128/cb83ba6b-551b-432f-bbb5-f4d25b6e4429)

**Desktop (please complete the following information):**
- OS: Windows
- Browser Chrome

**Additional context**
- Bug is also reported here: https://github.com/aws-amplify/amplify-js/issues/12986 by multiple developers, but I think it is also a doc issue need to be updated for Rest API setup.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.