diff --git a/packages/insomnia/src/ui/components/codemirror/__tests__/should-indent-with-tabs.test.ts b/packages/insomnia/src/ui/components/codemirror/__tests__/should-indent-with-tabs.test.ts deleted file mode 100644 index 4b2065c8dd6..00000000000 --- a/packages/insomnia/src/ui/components/codemirror/__tests__/should-indent-with-tabs.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { describe, expect, it } from '@jest/globals'; - -import { shouldIndentWithTabs } from '../code-editor'; - -describe('shouldIndentWithTabs()', () => { - it('should return false if mode contains yaml', () => { - expect(shouldIndentWithTabs({ mode: 'text/yaml', indentWithTabs: true })).toBe(false); - }); - - it('should return false if preference is disabled', () => { - expect(shouldIndentWithTabs({ mode: 'text/json', indentWithTabs: false })).toBe(false); - }); - - it('should return true if preference is enabled', () => { - expect(shouldIndentWithTabs({ mode: 'text/json', indentWithTabs: true })).toBe(true); - }); - - it('should return false if mode is openapi', () => { - expect(shouldIndentWithTabs({ mode: 'openapi', indentWithTabs: true })).toBe(false); - }); -}); diff --git a/packages/insomnia/src/ui/components/editors/__tests__/environment-editor.test.ts b/packages/insomnia/src/ui/components/editors/__tests__/environment-editor.test.ts index a74e02878de..622b38029b4 100644 --- a/packages/insomnia/src/ui/components/editors/__tests__/environment-editor.test.ts +++ b/packages/insomnia/src/ui/components/editors/__tests__/environment-editor.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from '@jest/globals'; import { NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME } from '../../../../templating'; -import { checkNestedKeys, ensureKeyIsValid } from '../environment-editor'; +import { checkNestedKeys, ensureKeyIsValid } from '../environment-utils'; describe('ensureKeyIsValid()', () => { it.each([ diff --git a/packages/insomnia/src/ui/components/editors/body/graph-ql-editor.tsx b/packages/insomnia/src/ui/components/editors/body/graph-ql-editor.tsx index 688f0ade16d..10877a87403 100644 --- a/packages/insomnia/src/ui/components/editors/body/graph-ql-editor.tsx +++ b/packages/insomnia/src/ui/components/editors/body/graph-ql-editor.tsx @@ -448,6 +448,7 @@ export const GraphQLEditor: FC = ({ if (schema) { graphqlOptions = { hintOptions: { + schema, completeSingle: false, }, infoOptions: { diff --git a/packages/insomnia/src/ui/components/editors/environment-editor.tsx b/packages/insomnia/src/ui/components/editors/environment-editor.tsx index 9099d88ad7a..a1f3d7ce444 100644 --- a/packages/insomnia/src/ui/components/editors/environment-editor.tsx +++ b/packages/insomnia/src/ui/components/editors/environment-editor.tsx @@ -2,53 +2,8 @@ import orderedJSON from 'json-order'; import React, { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react'; import { JSON_ORDER_PREFIX, JSON_ORDER_SEPARATOR } from '../../../common/constants'; -import { NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME } from '../../../templating'; import { CodeEditor, CodeEditorHandle } from '../codemirror/code-editor'; - -// NeDB field names cannot begin with '$' or contain a period '.' -// Docs: https://github.com/DeNA/nedb#inserting-documents -const INVALID_NEDB_KEY_REGEX = /^\$|\./; - -export const ensureKeyIsValid = (key: string, isRoot: boolean): string | null => { - if (key.match(INVALID_NEDB_KEY_REGEX)) { - return `"${key}" cannot begin with '$' or contain a '.'`; - } - - if (key === NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME && isRoot) { - return `"${NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME}" is a reserved key`; - } - - return null; -}; - -/** - * Recursively check nested keys in and immediately return when an invalid key found - */ -export function checkNestedKeys(obj: Record, isRoot = true): string | null { - for (const key in obj) { - let result: string | null = null; - - // Check current key - result = ensureKeyIsValid(key, isRoot); - - // Exit if necessary - if (result) { - return result; - } - - // Check nested keys - if (typeof obj[key] === 'object') { - result = checkNestedKeys(obj[key], false); - } - - // Exit if necessary - if (result) { - return result; - } - } - - return null; -} +import { checkNestedKeys } from './environment-utils'; export interface EnvironmentInfo { object: Record; diff --git a/packages/insomnia/src/ui/components/editors/environment-utils.ts b/packages/insomnia/src/ui/components/editors/environment-utils.ts new file mode 100644 index 00000000000..9533d595b97 --- /dev/null +++ b/packages/insomnia/src/ui/components/editors/environment-utils.ts @@ -0,0 +1,46 @@ +import { NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME } from '../../../templating'; + +// NeDB field names cannot begin with '$' or contain a period '.' +// Docs: https://github.com/DeNA/nedb#inserting-documents +const INVALID_NEDB_KEY_REGEX = /^\$|\./; + +export const ensureKeyIsValid = (key: string, isRoot: boolean): string | null => { + if (key.match(INVALID_NEDB_KEY_REGEX)) { + return `"${key}" cannot begin with '$' or contain a '.'`; + } + + if (key === NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME && isRoot) { + return `"${NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME}" is a reserved key`; + } + + return null; +}; + +/** + * Recursively check nested keys in and immediately return when an invalid key found + */ +export function checkNestedKeys(obj: Record, isRoot = true): string | null { + for (const key in obj) { + let result: string | null = null; + + // Check current key + result = ensureKeyIsValid(key, isRoot); + + // Exit if necessary + if (result) { + return result; + } + + // Check nested keys + if (typeof obj[key] === 'object') { + result = checkNestedKeys(obj[key], false); + } + + // Exit if necessary + if (result) { + return result; + } + } + + return null; +}