Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollo-elements/fast

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo-elements/fast

👩‍🚀🌛 FastElements for Apollo GraphQL 🚀👨‍🚀

  • 3.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57
increased by5.56%
Maintainers
1
Weekly downloads
 
Created
Source

@apollo-elements/fast

Published on npm Published on webcomponents.org ISC License Release

🚀 FASTElement base classes that connect to your Apollo cache 🌜

👩‍🚀 Launch your app at escape velocity! 👨‍🚀

🔎 Read the Full API Docs 🔎

📓 Contents

🔧 Installation

Apollo elements' fast is 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 computer then run the following command in your project's root directory:

npm install --save @apollo-elements/fast

👩‍🚀 Usage

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

First, let's define our component's GraphQL query.

query HelloQuery {
  helloWorld {
    name
    greeting
  }
}

Read our docs on working with GraphQL files during development and in production for more info, and be sure to read about generating TypeScript types from GraphQL to enhance your developer experience and reduce bugs.

Next, we'll define our UI component. Import the base class and helpers, query, and types, then define your component's template. Add an ApolloQueryBehavior with a query to automatically subscribe when your element connects.

Read more about working with Queries

import type { Binding, ViewTemplate } from '@apollo-elements/fast';

import { ApolloQueryBehavior } from '@apollo-elements/fast';
import { FASTElement, customElement, html, when } from '@apollo-elements/fast';

import { HelloQuery } from './Hello.query.graphql';

import { not } from 'fp-ts/function';

type B = Binding<HelloQueryElement>;
const isLoading: B = x => x.hello.loading;
const hasError: B = x => !!x.hello.error;
const getErrorMessage: B = x => x.hello.error.message;
const getDataPropOr = (prop: string, or: string): B => x =>
  x.hello.data?.helloWorld?.[prop] ?? or;

const template: ViewTemplate<HelloQueryElement> = html`
  <what-spin-such-loader ?active="${isLoading}"></what-spin-such-loader>
  ${when(hasError, html`
    <h1>😢 Such Sad, Very Error! 😰</h1>
    <pre><code>${getErrorMessage}</code></pre>`)}
  ${when(not(hasError), html`
    <p>
      ${getDataPropOr('greeting', 'Hello')},
      ${getDataPropOr('name', 'Friend')}!
    </p>`)}
`;

@customElement({ name: 'hello-query', template })
export class HelloQueryElement extends FASTElement {
  hello = new ApolloQueryBehavior(this, HelloQuery);
}

📚 Other Libraries

Looking for other libraries? Want to use Apollo with vanilla extends HTMLElement components? Check out our docs site

👷‍♂️ Maintainers

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

Contact me on Codementor

Keywords

FAQs

Package last updated on 29 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc