Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
graphql-query-batcher
Advanced tools
Readme
A light weight (<700 bytes) graphql query batcher for javascript.
Create a batcher client.
Parameters
fetcher
Fetcher The url to the graphql endpoint you are targeting.options
Options the options to be used by client (optional, default {}
)
options.batchInterval
integer duration (in MS) of each batch window. (default 6) (optional, default 6
)options.shouldBatch
boolean should the client batch requests. (default true) (optional, default true
)options.maxBatchSize
integer max number of requests in a batch. (default 0) (optional, default 0
)options.defaultHeaders
boolean default headers to include with every requestExamples
const fetcher = batchedQuery => fetch('path/to/graphql', {
method: 'post',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(batchedQuery),
credentials: 'include',
})
.then(response => response.json())
const client = new QueryBatcher(fetcher, { maxBatchSize: 10 })
Fetch will send a graphql request and return the parsed json.
Parameters
query
string the graphql query.variables
Variables any variables you wish to inject as key/value pairs.operationName
[string] the graphql operationName.overrides
Options the client options overrides. (optional, default {}
)Examples
client.fetch(`
query getHuman($id: ID!) {
human(id: $id) {
name
height
}
}
`, { id: "1001" }, 'getHuman')
.then(human => {
// do something with human
console.log(human);
});
Returns promise resolves to parsed json of server response
Fetch will send a graphql request and return the parsed json.
Parameters
query
string the graphql query.variables
Variables any variables you wish to inject as key/value pairs.operationName
[string] the graphql operationName.overrides
Options the client options overrides. (optional, default {}
)Examples
client.forceFetch(`
query getHuman($id: ID!) {
human(id: $id) {
name
height
}
}
`, { id: "1001" }, 'getHuman')
.then(human => {
// do something with human
console.log(human);
});
Returns Promise<Array<Result>> resolves to parsed json of server response
const options = {
shouldBatch: true, // should we batch queries?
batchInterval: 6, // duration of each batch window (in MS)
maxBatchSize: 0, // max number of requests in a batch (0 = no max)
};
The graphql implementation you are using must suppoprt batching! This means that your graphql endpoint should be able to take an array of requests and return an array of results.
To learn more read this: https://dev-blog.apollodata.com/query-batching-in-apollo-63acfd859862
To see an expmaple implementation in Golang, see https://github.com/nicksrandall/batched-graphql-handler
FAQs
light weight query batcher for graphql
The npm package graphql-query-batcher receives a total of 7,698 weekly downloads. As such, graphql-query-batcher popularity was classified as popular.
We found that graphql-query-batcher 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.