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..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,15 +1,35 @@ diff --git a/esm/interface/getAutocompleteSuggestions.js b/esm/interface/getAutocompleteSuggestions.js -index ac159d132d095a789b966627d315f4238c79ab60..a3be2d27c9d5c7d6fd3745093301a07d28e79a8d 100644 +index ac159d132d095a789b966627d315f4238c79ab60..1d6f624a8ad888ebbe8aa9092feb845a7d8205b0 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,8 @@ const hasTypeSystemDefinitions = (sdl) => { + } + return hasTypeSystemDef; + }; ++const primitives = new Set(['Int', 'Float', 'String', 'Boolean', 'ID']) ++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 +236,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) // 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); + } @@ -28,4 +48,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..40a61fcb 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: qivyzqyfs7hon4wbvvbq7vibpa 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=qivyzqyfs7hon4wbvvbq7vibpa)(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=qivyzqyfs7hon4wbvvbq7vibpa)(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=qivyzqyfs7hon4wbvvbq7vibpa)(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=qivyzqyfs7hon4wbvvbq7vibpa)(graphql@16.7.1) monaco-editor: 0.20.0(patch_hash=uf5fj7h4rxeihd5auffjnde5pu) picomatch-browser: 2.2.6 prettier: 2.6.2