npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@apollo-elements/hybrids

v5.0.3

Published

πŸ‘©β€πŸš€ Hybrids Starter Cultures for Apollo GraphQL πŸŒ›

Downloads

187

Readme

@apollo-elements/hybrids

Published on npm Published on webcomponents.org ISC License Release

πŸ‘Ύ hybrids GraphQL factories that shoot for the moon πŸš€

hybrids is a modern, functional, and opinionated UI library based on the web component standards. It sports a refreshing take on ui-as-value. Take a look at the repository and documentation, and this blog post introduction to hybrids

Apollo Elements hybrids make it easy to add GraphQL to your hybrids components.

πŸ”Ž Read the Full API Docs πŸ”Ž

πŸ““ Contents

πŸ”§ Installation

Apollo Elements hybrids are distributed through npm, the node package manager. To install a copy of the latest version in your project's node_modules directory, install npm on your system then run the following command in your project's root directory:

npm install --save @apollo-elements/hybrids

πŸ‘©β€πŸš€ Usage

See our docs on setting up Apollo client so your components can fetch their data.

This package provides mutation, query, and subscription factories that you can apply to your hybrids definitions.

❓ Queries

Use the query factory to connect your element to the apollo cache:

query HelloQuery($name: String) {
  hello(name: $name)
}
import { query, define, html } from '@apollo-elements/hybrids';
import HelloQuery from './Hello.query.graphql';
const render = ({ hello }) => html`
  <p>${hello.data?.hello ?? 'Hello'}</p>
`;

define('hello-element', {
  hello: query(HelloQuery),
  render
});

πŸ‘Ύ Mutations

Like queries, you can use the mutation factory.

mutation Name($name: String!) {
  name(name: $name) {
    name
  }
}
import { mutation, define, html } from '@apollo-elements/hybrids';
import UpdateNameMutation from './UpdateName.mutation.graphql';
const onKeyup = (host, event) => {
  if (event.key === 'Enter')
    host.updateName.mutate({ variables: { name: event.target.value } });
}

const render = () =>
  html`<input aria-label="Name" placeholder="Name" onkeyup="${onKeyup}"/>`;

define('name-input', {
  updateName: mutation(UpdateNameMutation),
  render,
});

πŸ—ž Subscriptions

Just like query and mutation, use subscription factory.

subscription {
  news
}
import { subscription, define, html } from '@apollo-elements/hybrids';
import NewsSubscription from './News.subscription.graphql';
const render = ({ news }) => news.error ? html`
  Error! ${news.error.message}
` : html`
  Latest News: ${news.data?.news}
`;

define('subscribing-element', {
  news: subscription(NewsSubscription),
  render
});

If you'd like to set up a subscription with an initial value from a query, then update that query's cached value each time the subscription reports new data, pass a subscription document and an updateQuery function with signature (prev: CachedValue, { subscriptionData }): next: CachedValue to the subscribeToMore method on a query element:

import { subscription, define, html } from '@apollo-elements/hybrids';
import { gql } from '@apollo/client/core';

import { apolloClient } from '../client'

define('messages-list', {
  messages: query(gql`{ messages }`),
  render({ messages }) {
    const messages = messages.data?.messages ?? [];
    return html`<ul>${messages.map(message => html`<li>${message}</li>`)}</ul>`;
  },
  /** a 'private' property that calls `subscribeToMore` on connect */
  __messagePosted_subscription: {
    connect(host) {
      host.messages.subscribeToMore({
        document: gql`
          subscription {
            messagePosted
          }
        `,
        updateQuery(previous = [], { subscriptionData }) {
          return (
              !subscriptionData.data ? previous
            : [subscriptionData.data.messagePosted, ...previous]
          );
        }
      });
    }
  }
});

πŸ‘·β€β™‚οΈ Maintainers

apollo-elements is a community project maintained by Benny Powers.

Contact me on Codementor