-
Notifications
You must be signed in to change notification settings - Fork 79
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
Mock Appsync Subscription Url "/graphql/realtime" doesn't work #122
Comments
Hey @mgarabedian 👋 thanks for raising this! I was able to successfully reproduce this behavior, and was able to workaround it by proxying both paths to As an example, if we have a Next.js app we can rewrite the paths using the config // next.config.cjs
import { aws_appsync_graphqlEndpoint } from './src/aws-exports'
export default {
async rewrites() {
return [
{
source: '/graphql',
destination: aws_appsync_graphqlEndpoint,
},
{
source: '/graphql/realtime',
destination: aws_appsync_graphqlEndpoint,
},
]
},
} Then using the sample Next.js homepage we can configure our client to route to point to our Next.js dev server URL import { API, graphqlOperation } from 'aws-amplify'
import { useEffect } from 'react'
import * as subscriptions from '../graphql/subscriptions'
export default function HomePage(props) {
// Subscribe to creation of Todo
API.configure({
aws_appsync_graphqlEndpoint: 'http://localhost:3000/graphql',
})
const subscription = API.graphql(
graphqlOperation(subscriptions.onCreateTodo)
).subscribe({
next: ({ provider, value }) => console.log({ provider, value }),
error: (error) => console.warn(error),
})
useEffect(() => {
return () => subscription.unsubscribe()
}, [])
return <h1>hello from the homepage</h1>
} Marking as a bug 🙂 |
Is this bug solved? Can't connect the websocket for subscribe events on graphQl... |
The proxying workaround doesn't work for me. |
For anyone else running into this issue with Create React App, I got it working with the help of @josefaidt 's proposed solution: setupProxy.js file (create proxy in create-react-app):
App.js file:
|
Hi @mgarabedian @alexNerazim @LaurensBrinker @lysachok. Thanks for reporting this issue. We've recently released a fix for this one, can you please upgrade your Amplify CLI to version |
Works for me now, thanks!
|
Works for me as well. Thank you! |
Before opening, please confirm:
How did you install the Amplify CLI?
No response
If applicable, what version of Node.js are you using?
No response
Amplify CLI Version
7.6.5
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
no
Amplify Categories
api
Amplify Commands
Not applicable
Describe the bug
Appsync mock subscriptions have not been working for me for some time. I have been trying to understand why. Doing some debugging, it appears that amplify-js is calling the URL '/graphql/realtime' to initiate the websocket connection, but the mock server is not setup to handle that URL.
If I use a nginx proxy to rewrite that url from '/graphql/realtime' to '/graphql' , or manually alter the amplify-js code to call '/graphql', then everything is fine.
Have I missed something in the configuration, or is this a bug?
Expected behavior
the url that amplify js calls works with mock.
Reproduction steps
Run a subscription on mock.
GraphQL schema(s)
# Put schemas below this line
Log output
Additional information
No response
The text was updated successfully, but these errors were encountered: