JSPM

  • Created
  • Published
  • Downloads 51
  • Score
    100M100P100Q73660F
  • License MIT

Full text searching on tsvector fields for use with graphile-plugin-connection-filter

Package Exports

  • graphile-plugin-fulltext-filter
  • graphile-plugin-fulltext-filter/esm/index.js
  • graphile-plugin-fulltext-filter/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphile-plugin-fulltext-filter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

graphile-plugin-fulltext-filter

graphile-plugin-fulltext-filter adds full-text search operators for tsvector fields to graphile-plugin-connection-filter in PostGraphile v4.

πŸš€ Installation

pnpm add graphile-plugin-fulltext-filter

✨ Features

  • Adds a matches operator for tsvector columns in PostGraphile v4
  • Works alongside graphile-plugin-connection-filter
  • Generates rank fields for ordering results (fullTextRank)
  • CLI and library-friendly setup
  • Uses pg-tsquery to safely parse user input

πŸ“¦ Usage

CLI

postgraphile --append-plugins graphile-plugin-connection-filter,graphile-plugin-fulltext-filter

See here for more information about loading plugins with PostGraphile.

Library

const express = require('express');
const { postgraphile } = require('postgraphile');
const PostGraphileConnectionFilterPlugin = require('graphile-plugin-connection-filter');
const FulltextFilterPlugin = require('graphile-plugin-fulltext-filter');

const app = express();

app.use(
  postgraphile(pgConfig, schema, {
    appendPlugins: [
      PostGraphileConnectionFilterPlugin,
      FulltextFilterPlugin,
    ],
  })
);

app.listen(5000);

⚑ Performance

All tsvector columns that aren't @omit'd should have indexes on them:

ALTER TABLE posts ADD COLUMN full_text tsvector;
CREATE INDEX full_text_idx ON posts USING gin(full_text);

πŸ”Ž Operators

This plugin adds the matches filter operator to the filter plugin, accepting a GraphQL String input and using the @@ operator to perform full-text searches on tsvector columns.

This plugin uses pg-tsquery to parse the user input to prevent Postgres throwing on bad user input unnecessarily.

🧭 Fields

For each tsvector column, a rank column will be automatically added to the GraphQL type for the table by appending Rank to the end of the column's name. For example, a column full_text will appear as fullText in the GraphQL type, and a second column, fullTextRank will be added to the type as a Float.

This rank field can be used for ordering and is automatically added to the orderBy enum for the table.

πŸ§ͺ Examples

query {
  allPosts(
    filter: {
      fullText: { matches: 'foo -bar' }
    }
    orderBy: FULL_TEXT_RANK_DESC
  ) {
    ...
    fullTextRank
  }
}

πŸ§ͺ Testing

# requires a local Postgres available (defaults to postgres/password@localhost:5432)
pnpm --filter graphile-plugin-fulltext-filter test

Education and Tutorials

  1. πŸš€ Quickstart: Getting Up and Running Get started with modular databases in minutes. Install prerequisites and deploy your first module.

  2. πŸ“¦ Modular PostgreSQL Development with Database Packages Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.

  3. ✏️ Authoring Database Changes Master the workflow for adding, organizing, and managing database changes with pgpm.

  4. πŸ§ͺ End-to-End PostgreSQL Testing with TypeScript Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.

  5. ⚑ Supabase Testing Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.

  6. πŸ’§ Drizzle ORM Testing Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.

  7. πŸ”§ Troubleshooting Common issues and solutions for pgpm, PostgreSQL, and testing.

πŸ“¦ Package Management

  • pgpm: πŸ–₯️ PostgreSQL Package Manager for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.

πŸ§ͺ Testing

  • pgsql-test: πŸ“Š Isolated testing environments with per-test transaction rollbacksβ€”ideal for integration tests, complex migrations, and RLS simulation.
  • pgsql-seed: 🌱 PostgreSQL seeding utilities for CSV, JSON, SQL data loading, and pgpm deployment.
  • supabase-test: πŸ§ͺ Supabase-native test harness preconfigured for the local Supabase stackβ€”per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
  • graphile-test: πŸ” Authentication mocking for Graphile-focused test helpers and emulating row-level security contexts.
  • pg-query-context: πŸ”’ Session context injection to add session-local context (e.g., SET LOCAL) into queriesβ€”ideal for setting role, jwt.claims, and other session settings.

🧠 Parsing & AST

  • pgsql-parser: πŸ”„ SQL conversion engine that interprets and converts PostgreSQL syntax.
  • libpg-query-node: πŸŒ‰ Node.js bindings for libpg_query, converting SQL into parse trees.
  • pg-proto-parser: πŸ“¦ Protobuf parser for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
  • @pgsql/enums: 🏷️ TypeScript enums for PostgreSQL AST for safe and ergonomic parsing logic.
  • @pgsql/types: πŸ“ Type definitions for PostgreSQL AST nodes in TypeScript.
  • @pgsql/utils: πŸ› οΈ AST utilities for constructing and transforming PostgreSQL syntax trees.

Credits

πŸ›  Built by the Constructive team β€” creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.

Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.