Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Custom Events #589

Closed
sorenbs opened this issue Sep 25, 2017 · 2 comments
Closed

Custom Events #589

sorenbs opened this issue Sep 25, 2017 · 2 comments

Comments

@sorenbs
Copy link
Member

sorenbs commented Sep 25, 2017

Currently the subscriptions API is automatically generated from the model types in a project.
This feature request introduces the ability to extend the subscription API with custom events.

Defining Custom events

A custom event can be added to the types.graphql file like this:

type MyEvent @event {
  title: String!
  user: User!
}

Publishing Custom events

Custom events can be published using graphcool-lib. When publishing an event you must include the type name and a json object containing all required data.

In the example above one of the fields is a Graphcool model type. In this case, instead of providing the entire User node, the id of an existing User must be provided:

graphcool.event('MyEvent', {title: 'this is an event', user: 'id-of-existing-user'})

Subscribing to Custom events

Custom events can be subscribed to with a normal subscription query from both frontend and backend.

Custom events should implement the normal permission system.

Custom events should support normal filters including relations

@kbrandwijk
Copy link
Contributor

kbrandwijk commented Sep 25, 2017

This would also require a change to the subscription filter, because this is not a 1-on-1 match with CREATE. Also, as this closely resembles the socket.io/realtime.co/others... implementation of 'channels', there might be a more standardized feature hidden in here: Type name is basically the same as channel name, and the type definition is just a strongly typed message payload.

I would suggest the following convenience methods on graphcool-lib:

  • graphcool.publish instead of graphcool.event
  • graphcool.subscribe as a one-liner to set up a subscription

graphcool.publish('ChannelName', stronglyTypedPayloadJson)
graphcool.subscribe('ChannelName').on('data', (data) => { console.log(data) })

Maybe even:

graphcool.subscribe('ChannelName', deviceToken) to register for push notifications 🙈

@marktani
Copy link
Contributor

This issue has been moved to graphcool/graphcool-framework.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants