From 45c72b53875485a5a01afe949897213be50eef51 Mon Sep 17 00:00:00 2001 From: U9G Date: Thu, 19 Oct 2023 12:09:33 -0400 Subject: [PATCH 1/4] Better autocomplete patch --- .../graphql-language-service@5.1.7.patch | 31 ++++++++++++++++--- .../browser_based_querying/pnpm-lock.yaml | 15 ++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch index e565e311..27391b14 100644 --- a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch +++ b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch @@ -1,15 +1,36 @@ diff --git a/esm/interface/getAutocompleteSuggestions.js b/esm/interface/getAutocompleteSuggestions.js -index ac159d132d095a789b966627d315f4238c79ab60..a3be2d27c9d5c7d6fd3745093301a07d28e79a8d 100644 +index ac159d132d095a789b966627d315f4238c79ab60..fa7f614cb2feb8a90bca66bf2c6dcb6763c4a1f3 100644 --- a/esm/interface/getAutocompleteSuggestions.js +++ b/esm/interface/getAutocompleteSuggestions.js -@@ -234,7 +234,12 @@ export function getAutocompleteSuggestions(schema, queryText, cursor, contextTok +@@ -63,6 +63,9 @@ const hasTypeSystemDefinitions = (sdl) => { + } + return hasTypeSystemDef; + }; ++const primitives = new Set(['Int', 'Float', 'String', 'Boolean']) ++const edgeDirectives = new Set(['fold', 'recurse', 'optional', 'transform']) ++const propertyDirectives = new Set(['filter', 'tag', 'output', 'transform']) + export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) { + var _a; + const opts = Object.assign(Object.assign({}, options), { schema }); +@@ -234,7 +237,23 @@ export function getAutocompleteSuggestions(schema, queryText, cursor, contextTok return getSuggestionsForVariableDefinition(token, schema, kind); } if (kind === RuleKinds.DIRECTIVE) { - return getSuggestionsForDirective(token, state, schema, kind); + // We should autocomplete fields on the line after we autocomplete a directive -+ if (state.needsAdvance) { // active after '@' or many other kinds of punctuation, so perfect for when we need to autocomplete directives -+ return getSuggestionsForDirective(token, state, schema, kind); ++ if (state.needsAdvance || state.name === null) { // active after '@' or many other kinds of punctuation, so perfect for when we need to autocomplete directives. ++ // `state` is `null` when the user autocompletes after typing just '@' then opening autocomplete menu ++ // further restrict the directives we suggest based on the type of the field we are on ++ // x.label does not include the '@' ++ let fieldType = typeInfo.fieldDef.type; ++ while (fieldType.ofType) { ++ fieldType = fieldType.ofType ++ } ++ if (primitives.has(fieldType.name)) { ++ return getSuggestionsForDirective(token, state, schema, kind).filter(x => propertyDirectives.has(x.label)) ++ } else { ++ return getSuggestionsForDirective(token, state, schema, kind).filter(x => edgeDirectives.has(x.label)) ++ } + } else { // there has been no '@' so we should autocomplete fields + return getSuggestionsForFieldNames(token, typeInfo, opts); + } @@ -28,4 +49,4 @@ index 38a10439b1a5d7e7adbdd3e16c743a9cedff9dab..c699c3166cf458a5f9e85a794591fd44 + for (let i = 0; i <= location.line; i++) { // fix console error spam from hovering a comment on the first line of a file by properly visiting the first line of a file stream = new CharacterStream(lines[i]); while (!stream.eol()) { - const style = parser.token(stream, state); \ No newline at end of file + const style = parser.token(stream, state); diff --git a/experiments/browser_based_querying/pnpm-lock.yaml b/experiments/browser_based_querying/pnpm-lock.yaml index aff428e0..596a5f66 100644 --- a/experiments/browser_based_querying/pnpm-lock.yaml +++ b/experiments/browser_based_querying/pnpm-lock.yaml @@ -1,8 +1,12 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + patchedDependencies: graphql-language-service@5.1.7: - hash: w6briuljthcrfw47ukgoxfvne4 + hash: i4sprbq3bcj6ibqhpya372at5q path: patches/graphql-language-service@5.1.7.patch monaco-editor@0.20.0: hash: uf5fj7h4rxeihd5auffjnde5pu @@ -576,6 +580,7 @@ packages: /@emotion/memoize@0.7.4: resolution: {integrity: sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==} + requiresBuild: true dev: false optional: true @@ -725,7 +730,7 @@ packages: copy-to-clipboard: 3.3.3 framer-motion: 6.5.1(react-dom@18.1.0)(react@18.1.0) graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=w6briuljthcrfw47ukgoxfvne4)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1) markdown-it: 12.3.2 react: 18.1.0 react-dom: 18.1.0(react@18.1.0) @@ -2572,7 +2577,7 @@ packages: '@codemirror/language': 6.0.0 codemirror: 5.65.14 graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=w6briuljthcrfw47ukgoxfvne4)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1) dev: false /codemirror@5.65.14: @@ -3569,7 +3574,7 @@ packages: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} dev: true - /graphql-language-service@5.1.7(patch_hash=w6briuljthcrfw47ukgoxfvne4)(graphql@16.7.1): + /graphql-language-service@5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1): resolution: {integrity: sha512-xkawYMJeoNYGhT+SpSH3c2qf6HpGHQ/duDmrseVHBpVCrXAiGnliXGSCC4jyMGgZQ05GytsZ12p0nUo7s6lSSw==} hasBin: true peerDependencies: @@ -4317,7 +4322,7 @@ packages: prettier: ^2.8.0 || ^3.0.0 dependencies: graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=w6briuljthcrfw47ukgoxfvne4)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1) monaco-editor: 0.20.0(patch_hash=uf5fj7h4rxeihd5auffjnde5pu) picomatch-browser: 2.2.6 prettier: 2.6.2 From 638b7067c098d75fa74fd3ce3941c1acbde57812 Mon Sep 17 00:00:00 2001 From: u9g Date: Thu, 19 Oct 2023 13:26:29 -0400 Subject: [PATCH 2/4] Update experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> --- .../patches/graphql-language-service@5.1.7.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch index 27391b14..2c21ca3a 100644 --- a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch +++ b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch @@ -6,7 +6,7 @@ index ac159d132d095a789b966627d315f4238c79ab60..fa7f614cb2feb8a90bca66bf2c6dcb67 } return hasTypeSystemDef; }; -+const primitives = new Set(['Int', 'Float', 'String', 'Boolean']) ++const primitives = new Set(['Int', 'Float', 'String', 'Boolean', 'ID']) +const edgeDirectives = new Set(['fold', 'recurse', 'optional', 'transform']) +const propertyDirectives = new Set(['filter', 'tag', 'output', 'transform']) export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) { From 5275d6e7645f7b6786de2c41b79fdc25d5497685 Mon Sep 17 00:00:00 2001 From: U9G Date: Sat, 21 Oct 2023 23:41:11 -0400 Subject: [PATCH 3/4] don't filter based on edge directive --- .../patches/graphql-language-service@5.1.7.patch | 4 ++-- experiments/browser_based_querying/pnpm-lock.yaml | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch index 2c21ca3a..6945964a 100644 --- a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch +++ b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch @@ -1,5 +1,5 @@ diff --git a/esm/interface/getAutocompleteSuggestions.js b/esm/interface/getAutocompleteSuggestions.js -index ac159d132d095a789b966627d315f4238c79ab60..fa7f614cb2feb8a90bca66bf2c6dcb6763c4a1f3 100644 +index ac159d132d095a789b966627d315f4238c79ab60..ec3fabdd1ed75a2175bbd0c8112ba0437a6398cd 100644 --- a/esm/interface/getAutocompleteSuggestions.js +++ b/esm/interface/getAutocompleteSuggestions.js @@ -63,6 +63,9 @@ const hasTypeSystemDefinitions = (sdl) => { @@ -29,7 +29,7 @@ index ac159d132d095a789b966627d315f4238c79ab60..fa7f614cb2feb8a90bca66bf2c6dcb67 + if (primitives.has(fieldType.name)) { + return getSuggestionsForDirective(token, state, schema, kind).filter(x => propertyDirectives.has(x.label)) + } else { -+ return getSuggestionsForDirective(token, state, schema, kind).filter(x => edgeDirectives.has(x.label)) ++ return getSuggestionsForDirective(token, state, schema, kind)//.filter(x => edgeDirectives.has(x.label)) // Don't filter until we can decide if there is a @transform(op: "count") before this directive + } + } else { // there has been no '@' so we should autocomplete fields + return getSuggestionsForFieldNames(token, typeInfo, opts); diff --git a/experiments/browser_based_querying/pnpm-lock.yaml b/experiments/browser_based_querying/pnpm-lock.yaml index 596a5f66..426acdf1 100644 --- a/experiments/browser_based_querying/pnpm-lock.yaml +++ b/experiments/browser_based_querying/pnpm-lock.yaml @@ -6,7 +6,7 @@ settings: patchedDependencies: graphql-language-service@5.1.7: - hash: i4sprbq3bcj6ibqhpya372at5q + hash: jkcxw65ywwhpb6sv4fqdhk6zn4 path: patches/graphql-language-service@5.1.7.patch monaco-editor@0.20.0: hash: uf5fj7h4rxeihd5auffjnde5pu @@ -730,7 +730,7 @@ packages: copy-to-clipboard: 3.3.3 framer-motion: 6.5.1(react-dom@18.1.0)(react@18.1.0) graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1) markdown-it: 12.3.2 react: 18.1.0 react-dom: 18.1.0(react@18.1.0) @@ -2577,7 +2577,7 @@ packages: '@codemirror/language': 6.0.0 codemirror: 5.65.14 graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1) dev: false /codemirror@5.65.14: @@ -3574,7 +3574,7 @@ packages: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} dev: true - /graphql-language-service@5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1): + /graphql-language-service@5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1): resolution: {integrity: sha512-xkawYMJeoNYGhT+SpSH3c2qf6HpGHQ/duDmrseVHBpVCrXAiGnliXGSCC4jyMGgZQ05GytsZ12p0nUo7s6lSSw==} hasBin: true peerDependencies: @@ -4322,7 +4322,7 @@ packages: prettier: ^2.8.0 || ^3.0.0 dependencies: graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=i4sprbq3bcj6ibqhpya372at5q)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1) monaco-editor: 0.20.0(patch_hash=uf5fj7h4rxeihd5auffjnde5pu) picomatch-browser: 2.2.6 prettier: 2.6.2 From d7e3015df2a365a42a73fa54f361a420f867f546 Mon Sep 17 00:00:00 2001 From: U9G Date: Sun, 22 Oct 2023 00:24:19 -0400 Subject: [PATCH 4/4] remove dead code --- .../patches/graphql-language-service@5.1.7.patch | 9 ++++----- experiments/browser_based_querying/pnpm-lock.yaml | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch index 6945964a..b46ea6e9 100644 --- a/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch +++ b/experiments/browser_based_querying/patches/graphql-language-service@5.1.7.patch @@ -1,18 +1,17 @@ diff --git a/esm/interface/getAutocompleteSuggestions.js b/esm/interface/getAutocompleteSuggestions.js -index ac159d132d095a789b966627d315f4238c79ab60..ec3fabdd1ed75a2175bbd0c8112ba0437a6398cd 100644 +index ac159d132d095a789b966627d315f4238c79ab60..1d6f624a8ad888ebbe8aa9092feb845a7d8205b0 100644 --- a/esm/interface/getAutocompleteSuggestions.js +++ b/esm/interface/getAutocompleteSuggestions.js -@@ -63,6 +63,9 @@ const hasTypeSystemDefinitions = (sdl) => { +@@ -63,6 +63,8 @@ const hasTypeSystemDefinitions = (sdl) => { } return hasTypeSystemDef; }; +const primitives = new Set(['Int', 'Float', 'String', 'Boolean', 'ID']) -+const edgeDirectives = new Set(['fold', 'recurse', 'optional', 'transform']) +const propertyDirectives = new Set(['filter', 'tag', 'output', 'transform']) export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) { var _a; const opts = Object.assign(Object.assign({}, options), { schema }); -@@ -234,7 +237,23 @@ export function getAutocompleteSuggestions(schema, queryText, cursor, contextTok +@@ -234,7 +236,23 @@ export function getAutocompleteSuggestions(schema, queryText, cursor, contextTok return getSuggestionsForVariableDefinition(token, schema, kind); } if (kind === RuleKinds.DIRECTIVE) { @@ -29,7 +28,7 @@ index ac159d132d095a789b966627d315f4238c79ab60..ec3fabdd1ed75a2175bbd0c8112ba043 + if (primitives.has(fieldType.name)) { + return getSuggestionsForDirective(token, state, schema, kind).filter(x => propertyDirectives.has(x.label)) + } else { -+ return getSuggestionsForDirective(token, state, schema, kind)//.filter(x => edgeDirectives.has(x.label)) // Don't filter until we can decide if there is a @transform(op: "count") before this directive ++ return getSuggestionsForDirective(token, state, schema, kind) // Don't filter edges until we can decide if there is a @transform(op: "count") before this directive, which would force us to switch to property directives + } + } else { // there has been no '@' so we should autocomplete fields + return getSuggestionsForFieldNames(token, typeInfo, opts); diff --git a/experiments/browser_based_querying/pnpm-lock.yaml b/experiments/browser_based_querying/pnpm-lock.yaml index 426acdf1..40a61fcb 100644 --- a/experiments/browser_based_querying/pnpm-lock.yaml +++ b/experiments/browser_based_querying/pnpm-lock.yaml @@ -6,7 +6,7 @@ settings: patchedDependencies: graphql-language-service@5.1.7: - hash: jkcxw65ywwhpb6sv4fqdhk6zn4 + hash: qivyzqyfs7hon4wbvvbq7vibpa path: patches/graphql-language-service@5.1.7.patch monaco-editor@0.20.0: hash: uf5fj7h4rxeihd5auffjnde5pu @@ -730,7 +730,7 @@ packages: copy-to-clipboard: 3.3.3 framer-motion: 6.5.1(react-dom@18.1.0)(react@18.1.0) graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=qivyzqyfs7hon4wbvvbq7vibpa)(graphql@16.7.1) markdown-it: 12.3.2 react: 18.1.0 react-dom: 18.1.0(react@18.1.0) @@ -2577,7 +2577,7 @@ packages: '@codemirror/language': 6.0.0 codemirror: 5.65.14 graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=qivyzqyfs7hon4wbvvbq7vibpa)(graphql@16.7.1) dev: false /codemirror@5.65.14: @@ -3574,7 +3574,7 @@ packages: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} dev: true - /graphql-language-service@5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1): + /graphql-language-service@5.1.7(patch_hash=qivyzqyfs7hon4wbvvbq7vibpa)(graphql@16.7.1): resolution: {integrity: sha512-xkawYMJeoNYGhT+SpSH3c2qf6HpGHQ/duDmrseVHBpVCrXAiGnliXGSCC4jyMGgZQ05GytsZ12p0nUo7s6lSSw==} hasBin: true peerDependencies: @@ -4322,7 +4322,7 @@ packages: prettier: ^2.8.0 || ^3.0.0 dependencies: graphql: 16.7.1 - graphql-language-service: 5.1.7(patch_hash=jkcxw65ywwhpb6sv4fqdhk6zn4)(graphql@16.7.1) + graphql-language-service: 5.1.7(patch_hash=qivyzqyfs7hon4wbvvbq7vibpa)(graphql@16.7.1) monaco-editor: 0.20.0(patch_hash=uf5fj7h4rxeihd5auffjnde5pu) picomatch-browser: 2.2.6 prettier: 2.6.2