Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const scriptChildMutation = new MutationObserver(() => {
const doc = getGraphQLScriptChildDocument(host);
if (doc) host[key] = doc;
});
const connect = (host, key) => {
const onInvalidate = ({ target }) => {
if (key === 'mutation') return;
if (host === target && host[key]) {
key === 'query' && host.observableQuery
? host.observableQuery.setVariables(host[key])
: host.subscribe();
}
};
host.addEventListener('@invalidate', onInvalidate);
if (!host[key]) host[key] = getGraphQLScriptChildDocument(host);
if (key !== 'mutation' && host[key]) host.subscribe();
const scriptChildMutation = new MutationObserver(() => {
const doc = getGraphQLScriptChildDocument(host);
if (doc) host[key] = doc;
});
scriptChildMutation.observe(host, { characterData: true, childList: true, subtree: true });
return () => {
host.removeEventListener('@invalidate', onInvalidate);
scriptChildMutation.disconnect();
};
};
const get = (host, previous) =>
previous || getGraphQLScriptChildDocument(host) || doc || null;