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

@quiqupltd/manual-trigger-link

v0.1.0

Published

A manual trigger link for Apollo Client

Downloads

2

Readme

Manual Trigger Link for Apollo GraphQL Client

An ApolloLink to trigger data coming manually.

Why?

To have a simulation of GraphQL Subscription events in client-side mocks, runnable from your browser console.

Installation

yarn add @quiqup/manual-trigger-link

Peer dependencies

  • apollo-link

Usage

NB! See also:

1. Use it in your mock client

You it in your mock client and pass a setTrigger function.

...
const link = ApolloLink.split(
  hasSubscription,
  ApolloLink.from([new ManualTriggerLink({ setTriggers }), schemaLink]),
  schemaLink
)
const cache = new InMemoryCache()
return new ApolloClient({ cache, link })

setTriggers function can be called several times during execution and will receive one parameter - an object with the following shape:

{
  _all, // Triggers updates on all subscriptions
  _inspect, // Returns an object with all current subscriptions
  [operationName], // A set of functions to trigger updates based on operationName (e.g. `task` for gql`subscription task {...}`)
}

Example of setTriggers func implementation:

const setTriggers = triggers => {
  if (!window.mocks) window.mocks = {}
  window.mocks.triggers = triggers
})

2. Setup your mock client

Set up your mock client by setting SchemaLink parameters, like rootValue or mocks.

Operation triggers can accept a context object which will be passed to your resolvers. In this example we can configure whether we want a normal task or an empty update (say, the task is unassigned from COR):

// This root value will be passed to SchemaLink
const rootValue = {
  task: (root, variables, context) => {
    const { empty } = context || {}
    return empty ? null : mockTaskObject
  },
}

3. User your mock client in your app

We recommend putting all mocking stuff under a dynamic import and not using it in production. For example, in dev environment there's a function like that, assigned to a window object:

mocksOn = async () => {
  const mockClientModule = await import('./get-mock-client')
  const client = await mockClientModule.default(getClientOptions(), triggers => {
    window.mocks.triggers = triggers
  })
}

4. Call mocks from dev console

So now you can call your mocks from browser's dev console:

mock.triggers.new() // for normal task mock
mock.triggers.new({ empty: true }) // to get an update with `null` as data

NB! There's an issue with apollo-link-state: it doesn't work with subscriptions. Inside, it closes all internal Observers' subscriptions objects, so you can't get new data. That's why for mock-client you should have apollo-link-state only for normal queries and mutations. This means that for now you can't use client resolvers for subscriptions. Please see this issue: https://github.com/apollographql/apollo-link-state/issues/138

Acknowledgements

Bootstrapped with generator-quiqup-lib

License

MIT © QuiqupQuiqup