mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 01:36:08 +08:00
30 lines
700 B
TypeScript
30 lines
700 B
TypeScript
import { pick } from 'lodash';
|
|
import React from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
import { NamedPage } from 'vj/misc/Page';
|
|
import { request } from 'vj/utils';
|
|
|
|
const defaultQuery = `\
|
|
query Example(
|
|
$name: String!
|
|
) {
|
|
user(uname: $name) {
|
|
_id
|
|
uname
|
|
}
|
|
}`;
|
|
|
|
export default new NamedPage('api', async () => {
|
|
const { GraphiQL } = await import('graphiql');
|
|
GraphiQL.Logo = function () {
|
|
return <p></p>;
|
|
} as any;
|
|
createRoot(document.getElementById('main')!).render(
|
|
<GraphiQL
|
|
fetcher={(body, opts = {}) => request.post('/api', body, pick(opts, 'headers'))}
|
|
defaultQuery={defaultQuery}
|
|
variables='{"name": "Hydro"}'
|
|
/>,
|
|
);
|
|
});
|