querifi v1.0.2
querifi
querifi allows you to easily access graphql apis. this enables you to query information from any graphql based api. querifi makes this process completely modular, making it super simple to get the data you need.
you can see an example of how querifi is used here
docs
these are the docs for the latest release of querifi. to install querifi, simply type npm i querify
into the terminal/command-line to get started.
each title contains the function exactly how it is viewed in visual studio code. so if you understand that representation, you will understand the function from its title.
setup
once querifi is installed, we can begin requiring and using the module. let's require querifi and pass the url and headers needed to access the graphql api:
const querifi = require("querifi"); // this will get our client
// pass the url and headers and get our client
replya("<url>", {"<header>": "<value>"}).then(client => {
// query the graphql api
});
insert the url and headers where they are seen in the program
this is all you need to start using the querifi api to access graphql apis
querify(type: string, ?find: [], ?send: {}): string
queryify creates query strings using the arguments provided. these query strings are formatted for use in graphql, and can be used to create any graphql formatted query string.
type - the type to be queried, e.g. user
find (optional) - the data to be returned from the query, e.g. id
, username
, email
send (optional) - the data to be sent with the query, e.g. id: 1
, username: "test"
use:
// example use case
let test = client.querify("query", [client.querify("user", ["id", "username", "email"], {username: `"test"`})]);
console.log(test); // > query{user(username: "test"){id, username, email}}
query(query: string): promise
query queries the given url for the data provided in the query string. this will return data which relates to the query in a promise. the json data can be accessed in a then method.
query - the query string to query, e.g. query{user(username: "test"){id, username, email}}
use:
// example use-case
client.query(client.querify("query", [client.querify("user", ["id", "username", "email"], {username: `"test"`})]))
.then(json => console.log(json)); // > { user: { id: 1, username: "test", email: "test@example.com" } }