@graphql-mesh/serve-runtime
Version:
25 lines (24 loc) • 749 B
JavaScript
import { mapMaybePromise } from '@graphql-mesh/utils';
export function useChangingSchema(getSchema, setSchemaCallback) {
let currentSchema;
let setSchema;
return {
onPluginInit(payload) {
setSchema = function (schema) {
if (currentSchema !== schema) {
currentSchema = schema;
payload.setSchema(schema);
}
};
setSchemaCallback(setSchema);
},
// @ts-expect-error - Typing issue with onRequestParse
onRequestParse() {
return {
onRequestParseDone() {
return mapMaybePromise(getSchema(), setSchema);
},
};
},
};
}