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

@sylchi/keystone-graphql-client

v1.1.1

Published

Simple graphql fetch client for keystone.js with automatic file upload support.

Downloads

29

Readme

keystone-graphql-client

A simple graphql fetch client for frontend clients to access keystone.js based backend. Automatic file upload support included.

Reason for existence

  1. At the time of creation apollo graphql client was taking 73kb! of the 282.13kb gzipped bundle for my app.
  2. When I got started with keystone.js then getting file upload to work was not as straight forward as I would have liked.

Installation

npm install @sylchi/keystone-graphql-client

or

yarn add @sylchi/keystone-graphql-client

Usage

For convinience it will take the API url from a GRAPHQL_API_URL or NEXT_PUBLIC_GRAPHQL_API_URL enviroment variable. If that is set its just as simple as importing it and using it right away as you would use apollo client.

Query:

import { query } from  '@sylchi/keystone-graphql-client'

const options = {
	query: `
		query($sortBy: [SortUsersBy!]){
		  allUsers(sortBy: $sortBy){
		    id
		  }
		}
	`,
	variables: {
		sortBy: 'id_ASC'
	}
}

query(options).then(result => console.log(result))

Mutation

import {  mutate } from  '@sylchi/keystone-graphql-client'

const  getFile  = () =>  fetch('https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png',
{
	mode:  "cors",
	cache:  "no-cache"
})
.then(response  =>  response.blob())
.then(blob  => {
	return  new  File([blob], "file.png", { type:  "image/png" })
});

getFile().then(file  => {

const  options  = {
	mutation: `
		mutation($id: ID!, $data: UserUpdateInput!){
			updateUser(id: $id, data: $data){
				id
			}
		}
	`,
	variables: {
		id:  "5f5a7f712a64d9db72b30602", //replace with user id
		data: {
			avatar:  file
		}
	}
}

mutate(options).then(result  =>  console.log(result));

});

Configuration

This package takes 2 arguments for configuration, both are optional. In this example we have 2 different endpoints for authenticated users and normal users. If API url is not set and environment variables GRAPHQL_API_URL or NEXT_PUBLIC_GRAPHQL_API_URL are not set the url defaults to /admin/api. By default credentials fiels is set to include.

//can have any name
import GraphQlClient from '@sylchi/keystone-graphql-client';

const apiUrl = 'www.example.com';
const authedUrl = 'authed.example.com';
const fetchOptions  = {
	credentials:  'omit',
	method: 'POST',
	headers: {
		'x-user-lang':  'english'
	}
}
const fetchOptionsAuthed = {
	credentials:  'include',
	method: 'POST',
	headers: {
		'x-user-token':  '***********'
	}
}
const { query, mutate } =  GraphQlClient(apiUrl, fetchOptions);
const { query: authedQuery, mutate: authedMutate } = GraphQlClient(authedUrl, fetchOptionsAuthed);

Caveats

This package does not handle caching of requests

Other

Pull requests are welcome