How to use @apollo-elements/lib - 10 common examples

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;
github apollo-elements / apollo-elements / packages / mixins / apollo-element-mixin.js View on Github external
connectedCallback() {
      super.connectedCallback && super.connectedCallback();
      this.elementMutationObserver = new MutationObserver(this.onElementMutation);
      this.elementMutationObserver.observe(this, {
        characterData: true,
        childList: true,
        subtree: true,
      });
      this.document = getGraphQLScriptChildDocument(this) || null;
    }
github apollo-elements / apollo-elements / packages / mixins / apollo-element-mixin.js View on Github external
onElementMutation() {
      const doc = getGraphQLScriptChildDocument(this);
      if (doc) this.document = doc;
    }
  });
github apollo-elements / apollo-elements / packages / hybrids / apollo-query.js View on Github external
get: host => ({ query = host.query, variables = host.variables } = {}) => {
    if (!hasAllVariables({ query, variables })) return;
    host.observableQuery = host.watchQuery(host, { query });
    const error = onError(host);
    const next = onNext(host);
    return host.observableQuery.subscribe({ error, next });
  },
};
github apollo-elements / apollo-elements / packages / hybrids / apollo-subscription.js View on Github external
get: host => ({
    fetchPolicy = host.fetchPolicy,
    query = host.subscription,
    variables = host.variables,
  } = {}) => {
    if (!hasAllVariables({ query, variables })) return;
    const observable = host.client.subscribe({ fetchPolicy, query, variables });
    const error = host.nextError(host);
    const next = host.nextData(host);
    host.observable = observable;
    return observable.subscribe({ error, next });
  },
};
github apollo-elements / apollo-elements / packages / mixins / apollo-subscription-mixin.js View on Github external
async subscribe({
      fetchPolicy = this.fetchPolicy,
      query = this.subscription,
      variables = this.variables,
    } = {}) {
      if (!hasAllVariables({ query, variables })) return;
      this.observable = this.client.subscribe(
        stripUndefinedValues({ query, variables, fetchPolicy })
      );
      return this.observable.subscribe({
        next: this.nextData,
        error: this.nextError,
      });
    }
github apollo-elements / apollo-elements / packages / mixins / apollo-query-mixin.js View on Github external
async subscribe({ query = this.query, variables = this.variables } = {}) {
      if (!hasAllVariables({ query, variables })) return;
      this.observableQuery = this.watchQuery({ query, variables });
      return this.observableQuery.subscribe({
        next: this.nextData,
        error: this.nextError,
      });
    }
github apollo-elements / apollo-elements / packages / hybrids / factories / document.js View on Github external
const set = (host, next) => {
    if (!next) return doc || null;
    if (!isValidGql(next)) throw new Error(errorMessage);
    if (onSet && typeof onSet === 'function') onSet(next);
    return next;
  };