docs icon indicating copy to clipboard operation
docs copied to clipboard

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

Open hangoocn opened this issue 1 year ago • 0 comments

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

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.

hangoocn avatar May 26 '24 06:05 hangoocn