How to use the @apollo-elements/lib.getGraphQLScriptChildDocument function in @apollo-elements/lib

To help you get started, weโ€™ve selected a few @apollo-elements/lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollo-elements / apollo-elements / packages / hybrids / factories / document.js View on Github external
const scriptChildMutation = new MutationObserver(() => {
      const doc = getGraphQLScriptChildDocument(host);
      if (doc) host[key] = doc;
    });
github apollo-elements / apollo-elements / packages / hybrids / factories / document.js View on Github external
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();
    };
  };
github apollo-elements / apollo-elements / packages / hybrids / factories / document.js View on Github external
const get = (host, previous) =>
    previous || getGraphQLScriptChildDocument(host) || doc || null;