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

graphql-zealot

v1.1.1

Published

Utilities for the GraphQL warrior

Downloads

7

Readme

graphql-zealot

Utilities for the GraphQL warrior

Semantically Released Build Status Code Coverage version downloads Styled with Prettier AirBnB style guide

MIT License All Contributors PRs Welcome Commitizen friendly Code of Conduct

Watch on GitHub Star on GitHub Tweet

Utilities for the GraphQL warrior

Installing

yarn add graphql-zealot

Or: npm install --save graphql-zealot.

API Reference

Table of Contents

AddTo

src/apollo.js:19-19

Direction to add to in a list. Either "head" or "tail"

Type: ("head" | "tail")

addEdge

src/apollo.js:32-47

Returns a function that will use Apollo's DataProxy to update a Query by adding an edge to a list of edges.

Parameters

  • query DocumentNode GraphQL query constructed with graphql-tag
  • operationName string Mutation name
  • edgePath Array<string> An array to a path to the list of edges
  • addTo AddTo Whether to add the new edge to the beginning or end of the list

Returns Function A function that it's passed to Apollo's update function.

addEdgeToFragment

src/apollo.js:75-108

Returns a function that will use Apollo's DataProxy to update a Fragment by adding an edge to a list of edges.

Parameters

  • fragment DocumentNode GraphQL fragment constructed with graphql-tag
  • operationName string Mutation name
  • edgePath Array<string> An array to a path to the list of edges
  • rootId string The root ID for this fragment
  • addTo string Whether to add the new edge to the beginning or end of the list
  • fragmentOptions (DataProxyReadFragmentOptions | DataProxyWriteFragmentOptions) (optional, default {})

Examples

{
  // ...
  update: addEdgeToFragment(
     Favorites.fragments.favorites,
    'toggleFavorite',
    ['favorites'],
    userId,
    'head',
    {
      fragmentName: 'Favorites',
    }
  ),
}

Returns Function A function that it's passed to Apollo's update function.

removeEdge

src/apollo.js:119-147

Remove an edge from a list

Parameters

Returns any

removeEdgeFromFragment

src/apollo.js:159-184

Remove edge from a list in Fragment

Parameters

  • fragment DocumentNode
  • edgeId string
  • rootId string
  • edgePath Array<string>
  • fragmentOptions (DataProxyReadFragmentOptions | DataProxyWriteFragmentOptions)

Returns Function

replaceEdgeInFragment

src/apollo.js:223-232

Replaces an edge in a Fragment

Parameters

Returns any

replaceEdge

src/connection.js:38-55

Replaces an edge in a list

Parameters

Returns any

cursorForObjectInConnection

src/connection.js:64-79

Modified version of cursorForObjectInConnection which uses primary ID as well

Parameters

Returns any

getContentTypeFromFilename

src/files.js:26-29

Return a content type from a filename, uses mime.

Parameters

Returns string ContentType

getTypenameForFile

src/files.js:37-48

Convert a content-type to a valid GraphQL scbema type

Parameters

Returns string Image, Video, Audio if content type matches, GenericFile otherwise

optimisticFileResponse

src/files.js:56-80

Returns an optimistic response for a File for instant display

Parameters

Returns any

formValues

src/forms.js:7-9

Return values for obj omitting id and __typename.

isEmpty

src/isEmpty.js:18-18

  • See: Ramda's isEmpty

Returns true whether the arguments is nil or and empty string

Type: Function

isEmptyProp

src/isEmpty.js:24-26

Returns whether a prop isEmpty

Type: Function

isEmptyPath

src/isEmpty.js:32-34

Returns whether the given Ramda path isEmpty

Type: Function

isOptimistic

src/isOptimistic.js:14-14

Returns true is a given string is an UUID.

UUIDs are commonly used to mark optimistic responses.

Type: function (string): boolean

addEdgeToMutationResult

src/mutations.js:18-25

Add edge to a mutation result

Shape: { edge: { node: result } }

Parameters

  • response any

Returns {edge: {node: any}}

addEdgeAndCursorToMutationResult

src/mutations.js:35-46

Add both edge and cursor to a mutation result Cursor is calculated via cursorForObjectInConnection.

Type: Function

Parameters

  • connectionGetter Function Function that returns a promise of a Connection of all records
  • obj Object The current object

optimisticResponse

src/mutations.js:59-77

Generate an optimistic response

Type: Function

Parameters

  • operationName String The name of the mutation that was run
  • payloadName String The name of the payload in the response object
  • response Object Partial response for the object that's to be returned by the server

Returns Function function that takes variables and can be passed to Apollo's optimisticResponse

mapEdgesToProp

src/props.js:25-44

Map edges to prop

Convert edges structure to an array of objects (nodes).

Type: Function

Parameters

  • edgePath String A dot-path to the edges (e.g viewer.user.favorites, edges suffix is optional)
  • propName String Name of the prop to map edges to

Returns Function Function that takes a data object. mapEdgesToProp is curried so you can pass it directly.

flattenEdges

src/props.js:54-75

Flattens edges recursively

Replaces edges structures with arrays of nodes.

Type: Function

Parameters

  • connection Connection

Developing

Built With

  • Ramda
  • Apollo
  • GraphQL

Pre-requisites

Setting up Dev

Here's a brief intro about what a developer must do in order to start developing the project further:

git clone https://github.com/blackxored/graphql-zealot
cd graphql-zealot
yarn

Building

If your project needs some additional steps for the developer to build the project after some code changes, state them here. for example:

yarn build

Versioning

We use SemVer for versioning. In addition, it's automatic via semantic-release, and our commit convention.

For the versions available, see the Releases on this repository.

Tests

yarn test

Style guide

We base our code style on AirBnB's style guide and we check with ESLint and automatically format our code with Prettier.

License

This project is licensed under the MIT License - see the license file for details.

Acknowledgments

  • Hat tip to anyone who's code was used
  • Inspiration
  • etc

Contributing

If you're interested in contributing to this project in any form, please read our Contribution Guidelines.

Code of Conduct

We've adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributors

Thanks goes to these people (emoji key):

| Adrian Perez💻 📖 🚇 ⚠️ | | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |

This project follows the all-contributors specification. Contributions of any kind welcome!