Skip to content

Commit

Permalink
Route handling draft. #64
Browse files Browse the repository at this point in the history
  • Loading branch information
Konard committed May 6, 2022
1 parent 7b25843 commit 241d6f8
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#2A3011",
"titleBar.activeBackground": "#3B4318",
"titleBar.activeForeground": "#FAFBF4"
}
}
71 changes: 70 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import expressPlayground from 'graphql-playground-middleware-express';
import moesif from 'moesif-nodejs';
import Debug from 'debug';
import waitOn from 'wait-on';
import { generateApolloClient } from '@deep-foundation/hasura/client';
import { DeepClient } from './imports/client';
import gql from 'graphql-tag';

const DEEPLINKS_HASURA_PATH = process.env.DEEPLINKS_HASURA_PATH || 'localhost:8080';
const DEEPLINKS_HASURA_SSL = process.env.DEEPLINKS_HASURA_SSL || 0;
Expand Down Expand Up @@ -98,4 +101,70 @@ const start = async () => {
}
}

start();
start();

const client = generateApolloClient({
path: `${process.env.DEEPLINKS_HASURA_PATH}/v1/graphql`,
ssl: !!+process.env.DEEPLINKS_HASURA_SSL,
secret: process.env.DEEPLINKS_HASURA_SECRET,
});

const deep = new DeepClient({
apolloClient: client,
})

const handleRoutes = async () => {
const routeTypeId = await deep.id('@deep-foundation/core', 'Route');
const handleRouteTypeId = await deep.id('@deep-foundation/core', 'HandleRoute');
const routerStringUseTypeId = await deep.id('@deep-foundation/core', 'RouterStringUse');
const routerListeningTypeId = await deep.id('@deep-foundation/core', 'RouterListening');

const routes = await client.query({
query: gql`
query {
links(where: {
type_id: { _eq: "${routeTypeId}" }
}) {
id
handleRoute: out(where: {
type_id: { _eq: "${handleRouteTypeId}" }
}) {
id
supports: from {
id
isolation: from {
id
image: value
}
}
handler: to {
id
file: to {
id
code: value
}
}
}
routerStringUse: out(where: {
type_id: { _eq: "${routerStringUseTypeId}" }
}) {
id
router: to {
id
routerListening: out(where: {
type_id: { _eq: "${routerListeningTypeId}" }
}) {
id
}
}
}
}
}
`, variables: {} });
};

const startRouteHandling = async () => {
setInterval(handleRoutes, 1000);
};

startRouteHandling();

0 comments on commit 241d6f8

Please sign in to comment.