
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
graphql-query-path
Advanced tools
A library that allows you to smartly execute database queries by looking at the field selection. This can mitigate the N+1 and even 1+1 problem of GraphQL queries.
A library that allows you to smartly execute database queries by looking at the field selection. This can mitigate the N+1 and even 1+1 problem of GraphQL queries.
This repo contains two projects:
getPaths
and
getPathsFromAST
. They return a list of paths reflecting the graphql-queryArray
with
contains(glob: string): boolean
method that you can use to do glob matching.
This one is ~17k bigger because of a dependency on picomatch
.Install the package
npm i graphql-query-path
Use it in your graphql-resolver:
import { getPaths } from 'graphql-query-paths';
// or
// const { getPaths } = require('graphql-query-paths');
const resolvers = {
user(args, context, info) {
const paths = getPaths(info);
if (paths.find((p) => p.indexOf('/user/posts/') > -1)) {
db.getUsersWithPosts();
} else {
db.getUsers();
}
},
};
Use the extended version to match glob pattern with contains
from
graphql-query-paths-contains
. This includes picomatch
but increases the lib
size by ~17k.
npm i graphql-query-paths-contains
import { getPaths } from 'graphql-query-paths-contains';
// or
// const { getPaths } = require('graphql-query-paths-contains');
const resolvers = {
user(args, context, info) {
if (getPaths(info).contains("/users/posts/"))) {
db.getUsersWithPosts();
} else {
db.getUsers();
}
},
};
Library graphql-query-paths
function/argument | type | description |
---|---|---|
getPathsFromAST(ast) | string[][] | Returns a list of subqueries with paths reflected in the sub query per subquery |
ast | DocumentNode link | The DocumentNode from import { parse } from 'graphql' |
getPaths(info) | string[] | Returns a list of paths reflected in the query |
info | GraphQLResolveInfo link | The last argument in a resolver |
Library graphql-query-paths-contains extends the library above with a
contains
function
function/argument | type | description |
---|---|---|
Array.prototype.contains(glob) | boolean | Extends Array with contains function. To know if a result contains a path you can execute getPaths(info).contains("/user/**") . This returns a boolean |
glob | string | a string representing a glob to filter the array with |
Albert Groothedde
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
This README was generated by readme-md-generator
FAQs
Have a look at the [readme](../README.md) at:
The npm package graphql-query-path receives a total of 1 weekly downloads. As such, graphql-query-path popularity was classified as not popular.
We found that graphql-query-path demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.