directus / v8-archive

Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
https://docs.directus.io/api/reference.html
507 stars 203 forks source link

Proactively fetch updates #2353

Open loganwishartcraig opened 4 years ago

loganwishartcraig commented 4 years ago

Opening this as a note.

Would be cool if the plugin could pull in content changes into the dev server using a Directus webhook. Similar to the gatsby-source-sanity watchMode: true option.

Mentioned in gatsby docs here

jooola commented 4 years ago

Just thinking out loud.

How would this be done ? It seems really tricky.

loganwishartcraig commented 4 years ago

Yeah, it does seem really tricky.

The way the gatsby-source-sanity plugin does it is by hooking into an event stream provided by their SDK. As far as I know, this isn't possible with the Directus SDK.

Just an idea: I'm wondering how difficult it would be to extend the API to expose a /gatsby_subscribe endpoint that could hook into events. Something that would sort of combine usage of the custom endpoints and custom hooks. Even if possible, it would require people updating their Directus API, and probably is beyond the scope of the plugin.

Or, we could do what you mention where we poll the activity collection every so often and then use the results to generate a set of changed records to re-sync?

Either way, it seems difficult.