Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions experiments/browser_based_querying/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@
"node": ">=16.13.0",
"pnpm": ">=8.0.0"
},
"packageManager": "pnpm@8.2.0",
"packageManager": "pnpm@8.9.1",
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
}
Expand Down
42 changes: 37 additions & 5 deletions experiments/browser_based_querying/patches/[email protected]
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
diff --git a/esm/interface/getAutocompleteSuggestions.js b/esm/interface/getAutocompleteSuggestions.js
index ac159d132d095a789b966627d315f4238c79ab60..a3be2d27c9d5c7d6fd3745093301a07d28e79a8d 100644
index ac159d132d095a789b966627d315f4238c79ab60..a3cb52a0b5203edfc5046b9011da02082727bd79 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);
+ }
}
return [];
}
@@ -441,7 +460,9 @@ function getSuggestionsForFragmentTypeConditions(token, typeInfo, schema, _kind)
const possibleObjTypes = schema.getPossibleTypes(abstractType);
const possibleIfaceMap = Object.create(null);
for (const type of possibleObjTypes) {
- for (const iface of type.getInterfaces()) {
+ // Only allow interfaces to be autocompleted that implement
+ // the type of the fragment.
+ if (type.getInterfaces().some(iface => iface.name === typeInfo.parentType.name)) {
possibleIfaceMap[iface.name] = iface;
}
}
diff --git a/esm/interface/getDiagnostics.js b/esm/interface/getDiagnostics.js
index 38a10439b1a5d7e7adbdd3e16c743a9cedff9dab..c699c3166cf458a5f9e85a794591fd445e843821 100644
--- a/esm/interface/getDiagnostics.js
Expand All @@ -28,4 +60,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);
const style = parser.token(stream, state);
17 changes: 0 additions & 17 deletions experiments/browser_based_querying/patches/[email protected]

This file was deleted.

25 changes: 13 additions & 12 deletions experiments/browser_based_querying/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.