To parse expressions, a program must export a field called parse
in their Root
type.
The parse
field must have the following schema:
{
"name": "parse",
"type": "List",
"ofType": { "type": "Ref", "ofType": "Void" },
"params": [
{ "name": "name", "type": "String" },
{ "name": "value", "type": "String" }
]
},
For example, the Github driver defines the following expressions in its memconfig.json
:
...
"expressions": {
"user": {
"description": "User",
"type": "url",
"searchIn": "https://github.com",
"regex": "https://github.com/((?!pulls$|issues$|marketplace$|explore$|notifications$|codespaces$)[^/])+$"
},
"repo": {
"description": "Repo",
"type": "url",
"searchIn": "https://github.com",
"regex": "https://github.com/[^/]+/[^/]+$"
},
...
}
These expressions, when found (e.g. by the Google Chrome Membrane extension) are then passed to the parse
field to convert them to graph nodes
parse: async ({ args: { name, value } }) => {
// TODO: add more stuff like /tree, /commits, /blob, etc...
switch (name) {
case "user": {
const url = new URL(value);
const [, name] = url.pathname.split("/");
return [root.users.one({ name })];
}
case "repo": {
const url = new URL(value);
const [, user, repo] = url.pathname.split("/");
return [root.users.one({ name: user }).repos().one({ name: repo })];
}
}
};