Coder Social home page Coder Social logo

appsync-client-go's People

Contributors

aeby avatar dependabot[bot] avatar jeremyforan avatar kazuhitonakamura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appsync-client-go's Issues

Subscription failing to start using WithIAMV2.

Hello,

I am trying to switch from API to IAMv2 authentication. The API is working but when I try to use the WithIAMV2 function I get the 1006 error:

2024/01/08 18:47:01 invalid message received: connection_error
2024/01/08 18:47:02 websocket: close 1006 (abnormal closure): unexpected EOF
2024/01/08 18:47:02 connection failed
2024/01/08 18:47:05 ERROR unable to initiate Subscription error="connection failed"
2024/01/08 18:47:08 ERROR unable to create subscription websocket error="connection failed"

I tried a few different approaches and I am still getting this error:

func createSubscriberWithV2(graphEndpoint string, realtimeEndpoint string, rUpdate chan []Radio, connLost chan bool) (*appsync.PureWebSocketSubscriber, error) {
	subRequest, err := authorRadioUpdatesSubscriptionPostRequest()
	if err != nil {
		slog.Error("unable to produce subscription request", "error", err)
		return nil, err
	}

	ctx := context.TODO()

	cfg, err := config.LoadDefaultConfig(ctx)
	if err != nil {
		return nil, err
	}

	credentials, err := cfg.Credentials.Retrieve(ctx)
	if err != nil {
		log.Fatalln(err)
		return nil, err
	}

	signer := sdkv2v4.NewSigner()

	opt := appsync.WithIAMV2(signer, credentials, cfg.Region, graphEndpoint)
	//	opt := appsync.WithIAMV2(signer, credentials, cfg.Region, graphEndpoint)

	ws := appsync.NewPureWebSocketSubscriber(
		realtimeEndpoint,
		subRequest,
		// Anonymous function that handles subscription events
		func(r *graphql.Response) {
			radios := new([]Radio)

			slog.Info("received radio subscription update")
			if err = r.DataAs(radios); err != nil {
				slog.Error("unable to process radio update from subscription", "error", err)

			} else {
				rUpdate <- *radios
			}
		},

		// Anonymous function that handles subscription lost event
		func(err error) {
			slog.Error("subscription lost", "error", err)
			connLost <- true
		},
		opt,
	)

	//this error may be related to this: https://github.com/sony/appsync-client-go/pull/11/commits/9670282ce3a1f51a1d2be738737f4445dfcf2948
	
	err = ws.Start()
	if err != nil {
		slog.Error("unable to initiate Subscription", "error", err)
		return nil, err
	}
	return ws, nil
}

I have ensured the credentials are correct, along with the http and real-time endpoint. Do you have any suggestions I could try?

Set up AppSync credentials

Hello.
I'm willing to use your package to make query requests to appsync. Is there a way to configure appsync credentials? Do you have any example of this?

Switch connection error check from string check to error type check.

Previously the code, is checking for an error string containing "i/o timeout" to handle connection loss. However, the error message "read: operation timed out" does not match the check.

To address this, I modified the error checking to cover more cases. Instead of looking for a specific error string, check for a timeout is using the net.Error interface and its Timeout() method. This approach is generally more reliable and less prone to breakage if the error messages change.

Before:

	_, payload, err := r.ws.ReadMessage()
		if err != nil {
			log.Println(err)
			if strings.Contains(err.Error(), "i/o timeout") {
				r.onConnectionLost(err)
			}
			return
		}

After

	_, payload, err := r.ws.ReadMessage()
		if err != nil {
			log.Println(err)
			if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
				r.onConnectionLost(err)
			}
			return
		}

Support for custom domains

Right now the service being signed is hardcoded to "appsync". However for custom gql domains, these look like API Gateway, and the service for this needs to be "execute-api"

Regarding line 55 in client.go

Websocket: Close 1006 (abnormal closure): unexpected EOF

When I try to run the appsync_eventapp.go against the sample Event App I get the following error:

appsync_eventapp.go:68: subscription subscribeToEventComments()
go/src/github.com/sony/appsync-client-go/pure_websocket_subscriber.go:256: invalid message received
go/src/github.com/sony/appsync-client-go/pure_websocket_subscriber.go:241: websocket: close 1006 (abnormal closure): unexpected EOF
go/src/awesomeProject/demo.go:115: connection failed

The mutations do work. Any idea why this could happen?

Silent Subscription Loss

Hey,

First, thanks for this library it has been a massive help.

I am looking to run a Linux service and receive notifications from an appsync service. After a day or two, it looks like we are losing the subscription connection and it is silently failing.

Is this something that maybe cause by a timeout? Do we need to do some sort of subscription 'keep-alive'?

Kind Regards

adding slog for additional logging

Hello,

I am wondering if there is interest in adding an slog logger to the code base. https://go.dev/blog/slog

PROS: slog is a structured logging library that enhances logging capabilities in projects. It enables projects that import the module to configure log levels according to their needs. This feature allows for more precise control over what is logged, ensuring that developers can focus on the most relevant log information.

CONS: The library was added to the standard library in 1.21. Go version 1.21 would be required to support this library.

If this is something you think would be beneficial I would be happy to start writing it.

Kind regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.