GraphQL API
All Wasmer services use the Wasmer GraphQL API to interact with and retrieve data.
Did you know...? wasmer.io (opens in a new tab), the Wasmer CLI and wasmer.sh (opens in a new tab) are all interacting with Wasmer via the public Wasmer GraphQL API.
What is GraphQL?
GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
If you want to learn more about GraphQL, please visit the official Website: GraphQL.org (opens in a new tab)
The Wasmer GraphQL API (and the GraphiQL IDE) can be accessed here:
registry.wasmer.io/graphql (opens in a new tab)
Examples
Let's see now a few things that we can do with it!
Get a Package Version
We can do a POST to https://registry.wasmer.io/graphql (opens in a new tab) with the the following as the query
POST field:
{
getPackageVersion(name: "python") {
version
repository
homepage
distribution {
downloadUrl
size
}
}
}
Which should return something similar to:
{
"data": {
"getPackageVersion": {
"version": "0.1.0",
"repository": "https://github.com/wapm-packages/python",
"homepage": null,
"distribution": {
"downloadUrl": "https://registry-cdn.wasmer.io/packages/_/python/python-0.1.0.tar.gz",
"size": 5097541
}
}
}
}
Get all Packages for a given Interface
If we want to search all the packages published that have certain interface (for example, WASI), we can do a POST to https://registry.wasmer.io/graphql (opens in a new tab) with the the following as the query
POST field:
{
getInterfaceVersion(name: "wasi", version: "latest") {
interface {
name
description
}
packageVersions {
edges {
node {
version
package {
name
}
distribution {
downloadUrl
}
}
}
}
}
}
Which should return something similar to:
{
"data": {
"getInterfaceVersion": {
"interface": {
"name": "wasi",
"description": "The WebAssembly System Interface. WASI is a modular system interface for WebAssembly. It’s focused on security and portability."
},
"packageVersions": {
"edges": [
{
"node": {
"version": "0.1.0",
"package": {
"name": "_/python"
},
"distribution": {
"downloadUrl": "https://registry-cdn.wasmer.io/packages/_/python/python-0.1.0.tar.gz"
}
}
},
{
"node": {
"version": "0.0.2",
"package": {
"name": "JeremyLikness/wasi-ubasic"
},
"distribution": {
"downloadUrl": "https://registry-cdn.wasmer.io/packages/JeremyLikness/wasi-ubasic/wasi-ubasic-0.0.2.tar.gz"
}
}
},
{
"node": {
"version": "0.4.6",
"package": {
"name": "vshymanskyy/wasm3"
},
"distribution": {
"downloadUrl": "https://registry-cdn.wasmer.io/packages/vshymanskyy/wasm3/wasm3-0.4.6.tar.gz"
}
}
}
]
}
}
}
}
Happy hacking! 🎉