This query returns all products that belong to a specific category based on the provided categoryid
. It fetches directly from the database using the Product
collection.
Copy graphqlCopyEditquery getProductsByCategory($categoryid: String!) {
getProductsByCategory(categoryid: $categoryid) {
_id
name
price
categoryid
}
}
๐ง Note: This query only matches documents where categoryid
equals the provided value. The data is returned as an array of product objects.
Copy jsonCopyEdit{
"data": {
"getProductsByCategory": [
{
"_id": "64ff86c1b879f5c87e9b9a7f",
"name": "PUBG UC 60",
"price": 0.99,
"categoryid": "fps-topups"
}
]
}
}
Copy pythonCopyEditimport requests
url = "https://api.vscgames.com/graphql"
headers = {"Content-Type": "application/json"}
query = '''
query getProductsByCategory($categoryid: String!) {
getProductsByCategory(categoryid: $categoryid) {
_id
name
price
categoryid
}
}
'''
variables = {"categoryid": "fps-topups"}
response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)
print(response.json())
Copy javascriptCopyEditconst fetch = require("node-fetch");
const query = `
query getProductsByCategory($categoryid: String!) {
getProductsByCategory(categoryid: $categoryid) {
_id
name
price
categoryid
}
}`;
const variables = { categoryid: "fps-topups" };
fetch("https://api.vscgames.com/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query, variables })
})
.then(res => res.json())
.then(data => console.log(data));