@graphql-mesh/serve-runtime
Version:
28 lines (27 loc) • 872 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useChangingSchema = useChangingSchema;
const utils_1 = require("@graphql-mesh/utils");
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 (0, utils_1.mapMaybePromise)(getSchema(), setSchema);
},
};
},
};
}
;