Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
graphql-cost-calculator
Advanced tools
Readme
This library provides query cost calculation for implemting rate limiting like Github GraphQL API.
NOTE: For now it only works for schemas that follow GraphQL Cursor Connections Specification.
Install the package via npm or yarn.
npm install graphql-cost-calculator
yarn add graphql-cost-calculator
import { calculateCost } from "graphql-cost-calculator";
import schema from "./schema"; // Import or build your schema
const result = calculateCost({
schema,
query: `
query {
viewer {
login
repositories(first: 100) {
edges {
node {
id
issues(first: 50) {
edges {
node {
id
labels(first: 60) {
edges {
node {
id
name
}
}
}
}
}
}
}
}
}
}
}
`
})
console.log(result) // { maxNode: 305101, cost: 51 }
{
schema: GraphQLSchema;
query: string;
variables?: Record<string, any>;
typeCostMap?: Record<string, number>;
}
You can set an additional object type weight for some objects. When your query includes some mached object types, the cost calculator adds weight for them.
const result = calculateCost({
schema,
query: `
query {
viewer {
login
repositories(first: 100) {
edges {
node {
id
issues(first: 50) {
edges {
node {
id
labels(first: 60) {
edges {
node {
id
name
}
}
}
}
}
}
}
}
}
}
}
`,
typeCostMap: { RepositoryConnection: 10 }
})
// (1 + 100 + 5000 + 1000(RepositoryConnection cost) / 100 = 61
console.log(result) // { maxNode: 305101, cost: 61 }
FAQs
cost calculator for GraphQL query
We found that graphql-cost-calculator demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.