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

@dialexa/pleco-graphql

v0.1.3

Published

# Pleco GraphQL

Downloads

4

Readme

Pleco logo

Pleco GraphQL

Table of Contents

Overview

This library provides GraphQL types that can be used to form your own filter types

GraphQL Types

All the GraphQL types can be found in src/graphql/index.ts. For each GraphQLScalarType (excluding Boolean), which includes ID, Int, String, and Float, we provide a GraphQL type allowing users to provide comparison operations like in, lt, gt, eq, as well as the nesting abilities with AND and OR.

Provided Exports

| operation | FilterQuery_Boolean | FilterQuery_ID | FilterQuery_String | FilterQuery_Int | FilterQuery_Float | |-----------|--------------------- |-----------------|---------------------|------------------|--------------------| | AND | ✔ | ✔ | ✔ | ✔ | ✔ | | OR | ✔ | ✔ | ✔ | ✔ | ✔ | | in | ✔ | ✔ | ✔ | ✔ | ✔ | | nin | ✔ | ✔ | ✔ | ✔ | ✔ | | eq | ✔ | ✔ | ✔ | ✔ | ✔ | | ne | ✔ | ✔ | ✔ | ✔ | ✔ | | gt | | | ✔ | ✔ | ✔ | | lt | | | ✔ | ✔ | ✔ | | gte | | | ✔ | ✔ | ✔ | | lte | | | ✔ | ✔ | ✔ | | contains | | | ✔ | | |

In addition to the 4 FilterQuery_* types, pleco-graphql also provides

  • SortDirection: an enum of ASC and DESC
  • LimitOffsetPage: an input object with limit and offset
  • graphQLTypes which is a string containing the definitions of all the types in SDL.

All these exports were written using what they will appear as in SDL. The javascript objects are:

| SDL Name | Javascript Export | |----------------------|---------------------------| | FilterQuery_Boolean | GraphQLFilterQueryBoolean | | FilterQuery_ID | GraphQLFilterQueryID | | FilterQuery_String | GraphQLFilterQueryString | | FilterQuery_Int | GraphQLFilterQueryInt | | FilterQuery_Float | GraphQLFilterQueryFloat | | SortDirection | GraphQLSortDirection | | LimitOffsetPage | GraphQLLimitOffsetPage |

Notes

  • null can be passed to eq and ne and will do a whereNull and whereNotNull, respectively
  • contains is case insensitive

Usage

Take the following GraphQL schema

type Vehicle {
  make: String
  model: String
}

input VehicleFilterInput {
  AND: [VehicleFilterInput]
  OR: [VehicleFilterInput]

  "fields on the vehicle table"
  make: FilterQuery_String
  model: FilterQuery_String

  "fields not directly on the vehicle table"
  numberOfUsers: FilterQuery_Int
  highwayMPG: FilterQuery_Int
  cityMPG: FilterQuery_Int
  userSurveyRating: FilterQuery_Float
}

input VehicleSortInput {
  numberOfUsers: SortDirection
  userSurveyRating: SortDirection
}

type Query {
  vehicles(filter: VehicleFilterInput, sort: VehicleSortInput): [Vehicle]
}

Using this input, a user could construct the following filter query:

query GetVehicles ($filter: VehicleFilterInput, $sort: VehicleSortInput) {
  vehicles (filter: $filter, sort: $sort) {
    make
    model
  }
}

with variables

{
  "filter": {
    "AND": [
      { "make": { "eq": "nissan" } },
      { "model": { "in": ["altima", "sentra"] } },
      { "numberOfUsers": { "AND": [{ "gt": 1000 }, { "lt": 1999 }] } },
      {
        "OR": [
          { "highwayMPG": { "gt": 30 } },
          { "cityMPG": { "gte": 20 } }
        ]
      },
      { "userSurveyRating": { "gte": 80.5 } }
    ]
  },
  "sort": {
    "userSurveyRating": "ASC"
  }
}

This will specify that the user wants all vehicles whose make is "nissan", with model "altima" or "sentry", who has between 1000-1999 users (exclusive), whose user survey ratings is greater than or equal to 80.5 and whose MPG satisifies either highway strictly greater than 30mpg or city greater than or equal to 20mpg, and sorted by userSurveyRating ascending.

Known Limitations

  • Implicit eq and in are not currently supported because GraphQL does not support union input types yet