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

@scalars/cli

v1.2.5

Published

Client for scalars application

Downloads

26

Readme

Scalar client


Scalars client provides auto-generated and type-safe query client for your application build in scalars

Getting started


The first step when using Scalars Client is installing its npm package as follows:

Installation

yarn

yarn add @scalars/cli

npm

npm install @scalars/cli

Once you installed the package it's needed to invoke the sync command which reads your scalars endpoint and client ID from your environment variables, don't forget to create an .env.dev file as follows:

# YOUR SCALARS ENDPOINT GOES HERE
SCALARS_API=https://app.scalars.co/qoboe5t4aH/api
# or
SCALARS_ENDPOINT=https://app.scalars.co/qoboe5t4aH/api

# YOUR SCALARS CLIENT ID GOES HERE
SCALARS_CLIENT_ID=c921b093-4334e-1be1-c0cb-5aa907d3d912

Using Scalars Client


Once Scalars Client has been generated you can import in your code

import { ScalarsClient } from '@scalars/cli'

const client = new ScalarsClient()

Then you can start using operations like creating, getting, updating and deleting on your entities:

Retrieve a car

const car = await client.query.car( {
    where: { id: '22bc79036f26481e' }
} )

💡 car will be an object like { id: '22bc79036f26481e' }

Note that you need to provide the select field on every operation to indicate which attributes of the entity you need to retrieve, otherwise it will only return a simple object:

Retrieve a car with its model and brand

const car = await client.query.car( {
    select: { id: true, model: true, brand: true },
    where: { id: '22bc79036f26481e' }
} )

Creating a new car

const newCar = await client.mutation.createCar( {
    data: { brand: 'Toyota', model: 'T90' }
} )

Updating an existing car

const updatedCar = await client.mutation.updateCar( {
    data: { brand: 'BMW' },
    where: { id: '22bc79036f26481e' }
} )

Deleting an existing car

const deletedCar = await client.mutation.deleteCar( {
    where: { id: '22bc79036f26481e' }
} )

Typescript support

Scalars Client offers type definitions, these ensure that all your operations are type safe and validated, also enables features like IntelliSense (autocompletion) in your editor.

Examples above would look as follows with type definitions:

Retrieve a car with its model and brand

const carSelect: CarSelect = { id: true, model: true, brand: true }
const carWhere: CarWhereUniqueInput = { id: '22bc79036f26481e' }
const car: ICar = await client.query.car( {
    select: carSelect,
    where: carWhere
} )

Creating a new car

const carData: CarCreateInput = { brand: 'Toyota', model: 'T90' }
const newCar: ICar = await client.mutation.createCar( {
    data: carData
} )

Updating an existing car

const carData: CarUpdateInput = { brand: 'BMW' }
const carWhere: CarWhereUniqueInput = { id: '22bc79036f26481e' }
const updatedCar = await client.mutation.updateCar( {
    data: carData,
    where: carWhere
} )

Deleting an existing car

const carWhere: CarWhereUniqueInput = { id: '22bc79036f26481e' }
const deletedCar = await client.mutation.deleteCar( {
    where: carWhere
} )