irmin-graphql-js
is a Javascript library for communicating directly with irmin-graphql GraphQL servers.
To create an Irmin instance:
var ir = new Irmin("https://127.0.0.1:8080/graphql");
Setting a value:
let commit = await ir.main().set("a/b/c", "123");
console.log(commit.hash);
Getting a value:
let value = await ir.main().get("a/b/c");
console.log(value);
Once you get past the most basic operations you will most likely need to write and execute custom queries. irmin.js
makes this easy:
let body = `
query GetExample($key: String!) {
main {
tree {
get(key: $key)
}
}
}
`;
let query = {
body: body,
vars: {
key: "a/b/c"
},
operation: "GetExample"
};
let res = await ir.execute(query);
console.log(res.main.tree.get);
In the example above, body
is a string containing the actual query, data
is an object with body
, vars
and operation
fields. The vars
and operation
fields may be left undefined if not in use.
There are some examples using NodeJS in the examples/
directory, they require the node-fetch
package to be installed via npm.
You may also be interested in checking out the GraphQL section of the Irmin Tutorial!