Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dialexa/pleco-graphql

Package Overview
Dependencies
Maintainers
5
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dialexa/pleco-graphql

# Pleco GraphQL

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
5
Weekly downloads
 
Created
Source

Pleco logo

Pleco GraphQL

Table of Contents

  • Overview
  • GraphQL Types

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

operationFilterQuery_BooleanFilterQuery_IDFilterQuery_StringFilterQuery_IntFilterQuery_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 NameJavascript Export
FilterQuery_BooleanGraphQLFilterQueryBoolean
FilterQuery_IDGraphQLFilterQueryID
FilterQuery_StringGraphQLFilterQueryString
FilterQuery_IntGraphQLFilterQueryInt
FilterQuery_FloatGraphQLFilterQueryFloat
SortDirectionGraphQLSortDirection
LimitOffsetPageGraphQLLimitOffsetPage
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

FAQs

Package last updated on 27 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc