3

I'm new to aws amplify. I have setup an app using amplify and I have an API that is returning records using GraphQl. I have created a subscription that is supposed to be triggered when creating a new blog entry. The entries are being created. In the documentation https://aws-amplify.github.io/docs/js/api the code samples suggest that I can use the following to subscribe to a mutation. I keep getting an error stating that error TS2339: Property 'subscribe' does not exist on type '{}'. It's coming from the assignment of client. I'm not sure why its saying this and I was hoping that you would be able to help me with this error.

import { onCreateBlog } from './graphql/subscriptions';

//GraphQl subscription

export const onCreateBlog = `subscription OnCreateBlog {
  onCreateBlog {
    id
    name
    posts {
      items {
        id
        title
      }
      nextToken
    }
  }
}
`;

//ngInit function with an async method

   ngOnInit() {

    (async () => {
          let client  = Amplify.configure(awsmobile); // error from here

          let subscription = client.subscribe(graphqlOperation(subscriptions.onCreateBlog)).subscribe({
            next: data => {
              console.log(data);
            },
            error: error => {
              console.warn(error);
            }
          });
        })();

  }
Jimi
  • 1,867
  • 7
  • 31
  • 55
  • Solved by casting this as Observable like: API.graphql(graphqlOperation(subscriptions.onCreateBlog)) as Observable; The code is compiling now but the subscription is not working as yet. – Jimi Feb 26 '19 at 11:13
  • I wonder if this is a bug in the newer releases... I'm going to try rolling back to an older release. – RyPope Mar 06 '19 at 02:38

0 Answers0