GraphQL
What is GraphQL?
Making a GraphQL API Request
All requests made to the GraphQL endpoint must be made as a POST request to 'https://api.succubus.space/graphql'.
Example Query Request
// Here we define our query as a multi-line string
// Storing it in a separate .graphql/.gql file is also possible
const query = `
query ($id: Int) { # Define which variables will be used in the query (ID)
hentai (id: $id) { # Insert our variables into the query arguments (ID)
id
name
titles
}
}
`;
// Define our query variables and values that will be used in the query request
const variables = {
id: 1226
};
// Define the config we'll need for our API request
const url = 'https://api.succubus.space/graphql',
options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: query,
variables: variables
})
};
// Make the HTTP Api request
fetch(url, options).then(handleResponse)
.then(handleData)
.catch(handleError);
function handleResponse(response) {
return response.json().then(function (json) {
return response.ok ? json : Promise.reject(json);
});
}
function handleData(data) {
console.log(data);
}
function handleError(error) {
alert('Error, check console');
console.error(error);
}Last updated