1 | import CodeMirror from 'codemirror';
|
2 | import getTypeInfo from './utils/getTypeInfo';
|
3 | import { getArgumentReference, getDirectiveReference, getEnumValueReference, getFieldReference, getTypeReference, } from './utils/SchemaReference';
|
4 | import './utils/jump-addon';
|
5 | CodeMirror.registerHelper('jump', 'graphql', (token, options) => {
|
6 | if (!options.schema || !options.onClick || !token.state) {
|
7 | return;
|
8 | }
|
9 | const state = token.state;
|
10 | const kind = state.kind;
|
11 | const step = state.step;
|
12 | const typeInfo = getTypeInfo(options.schema, state);
|
13 | if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||
|
14 | (kind === 'AliasedField' && step === 2 && typeInfo.fieldDef)) {
|
15 | return getFieldReference(typeInfo);
|
16 | }
|
17 | else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
|
18 | return getDirectiveReference(typeInfo);
|
19 | }
|
20 | else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
|
21 | return getArgumentReference(typeInfo);
|
22 | }
|
23 | else if (kind === 'EnumValue' && typeInfo.enumValue) {
|
24 | return getEnumValueReference(typeInfo);
|
25 | }
|
26 | else if (kind === 'NamedType' && typeInfo.type) {
|
27 | return getTypeReference(typeInfo);
|
28 | }
|
29 | });
|
30 |
|
\ | No newline at end of file |