Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
graphql-request-helper
Advanced tools
Helper Class of Graphql Client
Installing
$ npm install graphql-request-helper
import { GraphQLClient } from "graphql-request-helper";
Create Graphql Client
const graphQLClient = new GraphQLClient("http://localhost:3000/api/graphql");
Query
requestconst data = await graphQLClient.query({
name: "getAnimals",
fields: [
"id",
"name",
"age",
{
name: "family",
fields: ["id", "name"],
},
],
params: {
age: 3,
},
});
GraphQLClient receives the above fields and params and sends the following request
query{
getAnimals(age: 3){
id
name
age
family{
id
name
}
}
}
Mutation
requestconst data = await graphQLClient.mutation({
name: "addAnimal",
fields: [
"id",
"name",
"age",
{
name: "family",
fields: ["id", "name"],
},
],
params: {
name: "puppy",
age: 1,
isCute: true,
},
});
GraphQLClient receives the above fields and params and sends the following request
mutation{
addAnimal(name: "puppy", age: 1, isCute: true){
id
name
age
family{
id
name
}
}
}
import { GraphQLError } from "graphql-request-helper";
try {
const data = await graphQLClient.query({
// ...
});
} catch (e) {
if (e instanceof GraphQLError) {
console.log(e.errors);
}
}
then e.errors will be like this
[
{
"message": "Schema is not configured for mutations.",
"locations": [
{
"line": 1,
"column": 1
}
]
}
]
const graphQLClient = new GraphQLClient("http://localhost:3000/api/graphql", {
axios: {
headers: {
Authorization: "Bearer ...",
},
},
});
The axios option is used as the third parameter in the axios request
constructor(url, options) {
this.axiosOptions = options?.axios
}
// ...
const response = await axios.post(
this.graphQLUrl,
{
query,
},
this.axiosOptions
);
You can also modify it as a setAxiosOptions function.
const graphQLClient = new GraphQLClient("http://localhost:3000/api/graphql", {
axios: {
headers: {
Authorization: "Bearer A",
},
},
});
graphQLClient.setAxiosOptions({
headers: {
Authorization: "Bearer B",
},
});
FAQs
Helper Class of Graphql Client
We found that graphql-request-helper 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.