mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: drop graphql apis
This commit is contained in:
1 parent
0f7961d675
commit
6e16d03f67
52 files changed
+485
-583
No files matched your search
@@ -2,30 +2,11 @@ import 'streamsaver/examples/zip-stream';
|
||||
|
||||
import { request } from './base';
|
||||
|
||||
export async function api(q: string, path: string[] = []) {
|
||||
let query = q.trim();
|
||||
if (!query.startsWith('query')) query = `query{${query}}`;
|
||||
const res = await request.post(`/d/${UiContext.domainId}/api`, { query });
|
||||
if (res.errors) throw new Error(res.errors[0].message);
|
||||
let cursor = res;
|
||||
for (const p of path) {
|
||||
cursor = cursor[p];
|
||||
if (!cursor) return undefined;
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
export const gql = (
|
||||
pieces: TemplateStringsArray,
|
||||
...templates: (string | number | string[] | number[])[]
|
||||
) => {
|
||||
let res = '';
|
||||
for (let i = 0; i < pieces.length; i++) {
|
||||
res += pieces[i];
|
||||
if (templates[i]) res += JSON.stringify(templates[i]);
|
||||
}
|
||||
export async function api(method: string, args: Record<string, any>, projection: any) {
|
||||
const res = await request.post(`/d/${UiContext.domainId}/api/${encodeURIComponent(method)}`, { args, projection });
|
||||
if (res.error) throw new Error(res.error);
|
||||
return res;
|
||||
};
|
||||
}
|
||||
|
||||
export function getAvailableLangs(langsList?: string[]) {
|
||||
const prefixes = new Set(Object.keys(window.LANGS).filter((i) => i.includes('.')).map((i) => i.split('.')[0]));
|
||||
|
||||
Reference in new issue
Block a user