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

@screencloud/studio-graphql-client

v1.0.3

Published

a micro package for querying the studio graphql api.

Downloads

8

Readme

@screencloud/studio-graphql-client

a micro package for querying the studio graphql api.

install

This project is exposed as a public npm package

Run npm i -S @screencloud/studio-graphql-client to add it to your project.

usage

StudioGraphQLClient-class

A minimalistic class for quick and easy graphql requests. Wraps around the popular graphql-request npm package.

Instantiate with StudioGraphQLClientOptions such as

const client = new StudioGraphQLClient({ 
  endpoint: '<your graphql endpoint>',
  token: '<your developer token>',
});

Notes:

  • You may omit token or set it to undefined to run anonymous queries against the API.
  • Your endpoint is shown on the "Developer"-tab in your studio account settings.
  • You can also use 'eu' or 'us' as shorthands if you know your region.

executing queries

Use async request() to run queries against the API.

const client = new StudioGraphQLClient({ 
  endpoint: '<your graphql endpoint>',
  token: '<your developer token>',
});

client.request(`
  query { 
    currentOrg { 
      id 
      name
    }
  }
`).then((result) => {
  if (result.errors) {
    console.log('The request was unsuccessful', result.errors);
  } else {
    console.log('Your current org is ', result.data);
  }
});

getClient() singleton helper function

A function that exposes a shared instance (aka. singleton) to your package or script.

Run initClient() once during startup of your application.

import { initClient } from '@screencloud/studio-graphql-client';

initClient({
  endpoint: '<your graphql endpoint>',
  token: '<your developer token>',
});

Afterwards retrieve the singleton via getClient() in other files

import { getClient } from '@screencloud/studio-graphql-client';

const client = getClient();

client.request('<your graphql query>').then((result) => {
  console.log('query result', result);
});

nodejs and fetch()

The StudioGraphQLClient-class by default requires fetch to be a globally available function. This is always the case in modern browsers, but may not be the case in your local nodejs.

The package offers a polyfillFetch()-function to quickly help out.

import { polyfillFetch } from '@screencloud/studio-graphql-client';

polyfillFetch();

other functions

The package exposes most of its helper functions for various use-cases.

isStudioGraphQLToken(str: string): boolean

Returns true if a string is shaped like a valid studio graphql token;

This is used by StudioGraphQLCLient by default during construction.

parseGraphQLRequest(query: string): undefined

Attempts to parse the supplied query-argument as a graphql request. Throws if an invalid request is provided.

This is done by StudioGraphQLCLient by default when calling request().

mapStudioGraphQLEndpoint(endpoint: string): string | undefined

Maps a graphql endpoint such as 'eu' or 'us' to the full endpoint url of that region. Url-like strings will be returned as they are.

If the value can't be mapped otherwise, then undefined will be returned.

This is done by StudioGraphQLCLient by default during construction.