Replies: 2 comments 9 replies
-
Hi @cometkim ! I'm happy to see you here ❤️ I was thinking a lot about this, and we have 2 conflicting points here:
At the moment, we don't want to change the signature of the original functions, because not all servers or consumers of the wrapped To address this, I recommend considering implementing a persisted operations store that loads the data in an async way and then provides it to Here's a small example of that: class MyRemoteJsonStore implements PersistedOperationsStore {
private data: Record<string, string> = {};
constructor(private url) {}
canHandle() { return true };
get(id: string) {
return this.data[id];
}
public async load(): Promise<void> {
return fetch(this.url).then(r => r.json()).then(r => this.data = r);
}
}
// Create the store
const store = new MyRemoteJsonStore(URL);
// Create the envelop instance
const getEnveloped = envelop({ plugins: [ usePersistedOperations({ store ]);
// make sure to load and wait the initial data
await store.load();
// start your server / mark it as ready
server.listen();
// If you want, you can also refresh it using polling
setTimeout(() => {
store.load();
}, 1000 * 60 * 10); |
Beta Was this translation helpful? Give feedback.
-
An example is the plugin system of the mercurius-js (also Node graphql framework built on top of fastify) |
Beta Was this translation helpful? Give feedback.
-
onEnveloped
,onSchemaChange
,onPluginInit
andonParse
hooks don't seem to support async function in their definition.I see async situations in most use cases for integrating with external systems. So I think the whole lifecycle should allow for asynchronous functions. A good example is the plugin interface of GatsbyJS. All their interfaces allow either synchronous or asynchronous.
https://github.com/dotansimha/envelop/blob/b8cc21b/packages/plugins/persisted-operations/src/index.ts#L18
when user want to connect this plugin to an external store, mostly it should be via async IO. But
onParse
hook doesn't seem allow async function.Beta Was this translation helpful? Give feedback.
All reactions