Work towards subscriptions

- Replace chi with gorilla/mux
- Write custom CORS rules
- Start on notification subscriptions
This commit is contained in:
viktorstrate
2020-02-21 16:50:50 +01:00
parent b3f4264b3d
commit b2a8fd09f9
12 changed files with 787 additions and 34 deletions

View File

@@ -0,0 +1,27 @@
package resolvers
import (
"context"
"github.com/viktorstrate/photoview/api/graphql/auth"
"github.com/viktorstrate/photoview/api/graphql/notification"
)
func (r *subscriptionResolver) Notification(ctx context.Context) (notification.NotificationChannel, error) {
user := auth.UserFromContext(ctx)
if user == nil {
return nil, auth.ErrUnauthorized
}
notificationChannel := make(notification.NotificationChannel, 1)
listenerID := notification.RegisterListener(user, notificationChannel)
go func() {
<-ctx.Done()
notification.DeregisterListener(listenerID)
}()
return notificationChannel, nil
}