-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
index.ts
42 lines (39 loc) · 1.18 KB
/
index.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
import { EditorState } from '@codemirror/state';
import { EditorView, lineNumbers } from '@codemirror/view';
import { history } from '@codemirror/commands';
import { autocompletion, closeBrackets } from '@codemirror/autocomplete';
import { bracketMatching, syntaxHighlighting } from '@codemirror/language';
import { oneDarkHighlightStyle, oneDark } from '@codemirror/theme-one-dark';
import { graphql } from 'cm6-graphql';
import query from './sample-query';
import { TestSchema } from './testSchema';
const state = EditorState.create({
doc: query,
extensions: [
bracketMatching(),
closeBrackets(),
history(),
autocompletion(),
lineNumbers(),
oneDark,
syntaxHighlighting(oneDarkHighlightStyle),
graphql(TestSchema, {
onShowInDocs(field, type, parentType) {
alert(
`Showing in docs.: Field: ${field}, Type: ${type}, ParentType: ${parentType}`,
);
},
onFillAllFields(view, schema, _query, cursor, token) {
alert(`Filling all fields. Token: ${token}`);
},
}),
],
});
new EditorView({
state,
parent: document.querySelector('#editor')!,
});
// Hot Module Replacement
if (module.hot) {
module.hot.accept();
}