forked from 0no-co/gql.tada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.bench.ts
45 lines (38 loc) · 1.18 KB
/
api.bench.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { describe, bench } from 'vitest';
import * as ts from './tsHarness';
describe('Document', () => {
const virtualHost = ts.createVirtualHost({
...ts.readVirtualModule('@0no-co/graphql.web'),
...ts.readSourceFolders(['.']),
'simpleIntrospection.ts': ts.readFileFromRoot('src/__tests__/fixtures/simpleIntrospection.ts'),
'index.ts': `
import { simpleIntrospection } from './simpleIntrospection';
import { ResultOf, initGraphQLTada, readFragment } from './api';
const graphql = initGraphQLTada<{ introspection: simpleIntrospection; }>();
const todoFragment = graphql(\`
fragment TodoData on Todo {
id
text
}
\`);
const todoQuery = graphql(\`
query {
todos {
id
complete
...TodoData
}
}
\`, [todoFragment]);
const result: ResultOf<typeof todoQuery> = {} as any;
const todo = readFragment(todoFragment, result?.todos?.[0]);
`,
});
const typeHost = ts.createTypeHost({
rootNames: ['index.ts'],
host: virtualHost,
});
bench('create simple query', () => {
ts.runDiagnostics(typeHost);
});
});