Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify Mock AWSAppSyncRealTimeProvider Connection error #2935

Closed
riacoding opened this issue Dec 6, 2019 · 12 comments
Closed

Amplify Mock AWSAppSyncRealTimeProvider Connection error #2935

riacoding opened this issue Dec 6, 2019 · 12 comments
Labels
feature-request Request a new feature mock Issues tied to the mock functionality p3

Comments

@riacoding
Copy link

Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the
Amplify Console GitHub Issue Tracker

Describe the bug
Create a fresh react project and add amplify to it with an API. On running amplify mock api the graphql subscriptions are not working as expected with the AWSAppSyncRealTimeProvider having a connection failed exception after timeout.

Amplify CLI Version
Amplify/Cli@4.5.0

To Reproduce
Following demo from aws blog post by Nikhil Dabhade
https://aws.amazon.com/blogs/mobile/amplify-framework-local-mocking/

npx create-react-app myapp
amplify init
amplify add api
npm i aws-amplify

replace App.js with code below

import React, { useEffect, useReducer } from "react";
import Amplify from "@aws-amplify/core";
import { API, graphqlOperation } from "aws-amplify";
import { createTodo } from "./graphql/mutations";
import { listTodos } from "./graphql/queries";
import { onCreateTodo, onUpdateTodo } from "./graphql/subscriptions";

import config from "./aws-exports";
Amplify.configure(config); // Configure Amplify

const initialState = { todos: [] };
const reducer = (state, action) => {
  switch (action.type) {
    case "QUERY":
      return { ...state, todos: action.todos };
    case "SUBSCRIPTION":
      return { ...state, todos: [...state.todos, action.todo] };
    default:
      return state;
  }
};

async function createNewTodo() {
  const todo = { name: "Use AppSync", description: "Realtime and Offline" };
  await API.graphql(graphqlOperation(createTodo, { input: todo }));
}
function App() {
  const [state, dispatch] = useReducer(reducer, initialState);

  useEffect(() => {
    getData();
    const subscription = API.graphql(graphqlOperation(onCreateTodo)).subscribe({
      next: eventData => {
        const todo = eventData.value.data.onCreateTodo;
        dispatch({ type: "SUBSCRIPTION", todo });
      }
    });
    return () => {
      subscription.unsubscribe();
    };
  }, []);

  async function getData() {
    const todoData = await API.graphql(graphqlOperation(listTodos));
    dispatch({ type: "QUERY", todos: todoData.data.listTodos.items });
  }

  return (
    <div>
      <div className="App">
        <button onClick={createNewTodo}>Add Todo</button>
      </div>
      <div>
        {state.todos.map((todo, i) => (
          <p key={todo.id}>
            {todo.name} : {todo.description}
          </p>
        ))}
      </div>
    </div>
  );
}
export default App;

amplify mock api
npm start

Expected behavior
From the http://localhost:20002/ local endpoint using graphiql to create a mutation create a todo item. This would then be automatically updated on the http://localhost:3000/ endpoint via the graphql subscription.

Screenshots
Screen Shot 2019-12-05 at 8 44 23 PM

Desktop (please complete the following information):

  • OS: Mac OSX 10.13.6
  • Node Version. 10.17.0

Additional context
The mutations are being persisted to the local database and the changes can be viewed by refreshing the page, however, the websocket is not updating in realtime.

@ammarkarachi ammarkarachi added bug Something isn't working mock Issues tied to the mock functionality labels Dec 6, 2019
@attilah attilah added enhancement and removed bug Something isn't working labels Dec 9, 2019
@attilah
Copy link
Contributor

attilah commented Dec 9, 2019

@riacoding Mock does not yet support the new WebSocket based subscriptions, only MQTT and the code you're trying to run using the new AmplifyJS library is leveraging the new WebSocket based subscriptions, hence creating this error for you.

@riacoding
Copy link
Author

@attilah is there a roadmap to have this feature implemented? I understand the issue but it seems more of a regression as it was working in 1.2.4. I have been looking at the repo ,Am I right to assume that the mock would need to implement a pure WS server instead of MQTT to handle the new AWSAppSyncRealtimeProvider?

@narayanncube
Copy link

@riacoding - any success on this?

@riacoding
Copy link
Author

riacoding commented Feb 19, 2020 via email

@narayanncube
Copy link

Ok

Thanks for replying

They said it’s in the pipeline for getting fixed but there is no timeline as of yet

On Wed, Feb 19, 2020 at 10:53 AM narayanncube @.***> wrote: @riacoding https://github.com/riacoding - any success on this? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2935?email_source=notifications&email_token=AACZHNSYFVXF7D4RHLINN53RDV537A5CNFSM4JWMMZF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMJA5NQ#issuecomment-588385974>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACZHNX3W3ICTVLNMF7BOVDRDV537ANCNFSM4JWMMZFQ .

@camin-mccluskey
Copy link

any update on this @riacoding

@riacoding
Copy link
Author

riacoding commented Mar 15, 2020 via email

@dillonharless18
Copy link

Facing this issue as well still.

@passedByMe
Copy link

we are at the second wave of god damn covid!
this thing is still not working...

@siegerts siegerts added feature-request Request a new feature and removed enhancement labels Sep 3, 2021
@PeterMitrano
Copy link

+1 for this fix

@mgarabedian
Copy link

Unsure if this is the same original issue above, but I filed this bug regarding Mock AppSync Subscriptions.
aws-amplify/amplify-category-api#122

@josefaidt
Copy link
Contributor

Hey y'all as noted in @mgarabedian 's comment this item is currently being tracked on aws-amplify/amplify-category-api#122. Closing in favor of tracking 9621. As a workaround we can use a proxy or frontend app config to rewrite /graphql/realtime to /graphql during mock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request a new feature mock Issues tied to the mock functionality p3
Projects
None yet
Development

No branches or pull requests