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

@rxdi/graphql-client

v0.7.178

Published

#### Install

Downloads

341

Readme

Graphql module for client side rxdi application build with Apollo-graphql

Install

npm i @rxdi/graphql-client

Define routes with forRoot these will be evaluated lazy

import { Module } from '@rxdi/core';
import { AppComponent } from './app.component';
import { GraphqlModule } from '@rxdi/graphql-client';
import { DOCUMENTS } from './@introspection/documents';

@Module({
  imports: [
    GraphqlModule.forRoot({
      async onRequest(this: GraphQLRequest) {
        const headers = new Headers();
        headers.append('authorization', '');
        return headers;
      },
      uri: 'http://localhost:9000/graphql',
      pubsub: 'ws://localhost:9000/subscriptions',
      apolloClientOptions: {
        /* ApolloClientOptions defined above */
      },
      apolloRequestHandler: (operation, forward) => forward(operation)
      /*
      * Will cancel all request from the same type
      * in order to make only 1 request for specific update or query
      * `false` by default
      */
      cancelPendingRequests: true,
    }, DOCUMENTS),
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

In order to collect DOCUMENTS from .graphql files we need @gapi/cli

npm i -g @gapi/cli

Collect queries/mutations/subscriptions/fragments

gapi schema introspect --collect-documents --collect-types

More information can be found HERE

ApolloClientOptions interface

interface ApolloClientOptions {
  link?: ApolloLink;
  cache: ApolloCache;
  ssrForceFetchDelay?: number;
  ssrMode?: boolean;
  connectToDevTools?: boolean;
  queryDeduplication?: boolean;
  defaultOptions?: DefaultOptions;
  assumeImmutableResults?: boolean;
  resolvers?: Resolvers | Resolvers[];
  typeDefs?: string | string[] | DocumentNode | DocumentNode[];
  fragmentMatcher?: FragmentMatcher;
  name?: string;
  version?: string;
}

Base component

import { Injector } from "@rxdi/core";
import { DocumentTypes } from "../@introspection/documentTypes";
import { of, Observable } from "rxjs";
import { switchMap } from "rxjs/operators";
import { IQuery, IMutation, ISubscription } from "../@introspection";
import { LitElement } from "@rxdi/lit-html";
import {
  importQuery,
  ApolloClient,
  QueryOptions,
  SubscriptionOptions,
  MutationOptions,
  DataProxy,
} from "@rxdi/graphql-client";

export class BaseComponent extends LitElement {
  @Injector(ApolloClient)
  public graphql: ApolloClient;

  query<T = IQuery>(options: ImportQueryMixin) {
    return of(importQuery(options.query)).pipe(
      switchMap((query) => this.graphql.query({ ...options, query }) as any)
    ) as Observable<{ data: T }>;
  }

  mutate<T = IMutation>(options: ImportMutationMixin) {
    return of(importQuery(options.mutation)).pipe(
      switchMap((mutation) => this.graphql.mutate({ ...options, mutation }) as any)
    ) as Observable<{ data: T }>;
  }

  subscribe<T = ISubscription>(options: ImportSubscriptionMixin) {
    return of(importQuery(options.query)).pipe(
      switchMap((query) => this.graphql.subscribe({ ...options, query }) as any)
    ) as Observable<{ data: T }>;
  }
}

interface ImportQueryMixin extends QueryOptions {
  query: DocumentTypes;
}

interface ImportSubscriptionMixin extends SubscriptionOptions {
  query: DocumentTypes;
}

interface ImportMutationMixin extends MutationOptions {
  mutation: DocumentTypes;
  update?(proxy: DataProxy, res: { data: IMutation }): void;
}

Usage

import { Component, html, css, async } from "@rxdi/lit-html";
import { BaseComponent } from "../../shared/base.component";
import { RouteParams } from "@rxdi/router";
import { map } from "rxjs/operators";

@Component({
  selector: "project-details-component",
  style: css`
    .container {
      width: 1000px;
    }
  `,
  template(this: DetailsComponent) {
    return html`
      <div class="container">
        ${async(this.project)}
      </div>
    `;
  },
})
export class DetailsComponent extends BaseComponent {
  @RouteParams()
  private params: { projectName: string };

  private project: Observable<IProjectType>;

  OnUpdateFirst() {
    this.project = this.getProject();
  }
  getProject() {
    return this.query({
      query: "get-project.query.graphql",
      variables: {
        name: this.params.projectName,
      },
    }).pipe(
      map(({ data }) => data.getProject),
      map(
        (project) => html`
          <p>${project.createdAt}</p>
          <p>${project.id}</p>
          <p>${project.name}</p>
          <p>${project.ownedBy}</p>
        `
      )
    );
  }
}

Advanced features

Compression of Documents can be done like so