Skip to content

Commit 2818c16

Browse files
committed
Autocompletion inside GraphQL injections #662
1 parent d342d6a commit 2818c16

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

src/main/com/intellij/lang/jsgraphql/ide/resolve/GraphQLScopeProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class GraphQLScopeProvider(private val project: Project) {
9090
element: PsiElement,
9191
key: Key<CachedValue<GlobalSearchScope>>
9292
): GlobalSearchScope {
93-
val file = element.containingFile
93+
val file = element.containingFile.originalFile
94+
9495
return CachedValuesManager.getCachedValue(file, key) {
9596
val projectConfig = configProvider.resolveProjectConfig(file)
9697
var scope: GlobalSearchScope =

src/test/com/intellij/lang/jsgraphql/GraphQLCompletionTestCaseBase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ public abstract class GraphQLCompletionTestCaseBase extends GraphQLTestCaseBase
2929
return doTest();
3030
}
3131

32+
protected LookupElement @Nullable [] doTestWithProject() {
33+
return doTestWithProject(".graphql");
34+
}
35+
36+
protected LookupElement @Nullable [] doTestWithProject(@NotNull String ext) {
37+
String dirName = getTestName(false);
38+
myFixture.copyDirectoryToProject(dirName, "");
39+
reloadConfiguration();
40+
String filePath = dirName + ext;
41+
myFixture.configureFromTempProjectFile(filePath);
42+
return myFixture.complete(CompletionType.BASIC, 1);
43+
}
44+
3245
protected static void checkEqualsOrdered(LookupElement @Nullable [] items, String @NotNull ... variants) {
3346
assertNotNull(items);
3447
assertOrderedEquals(ContainerUtil.map(items, LookupElement::getLookupString), variants);

src/test/com/intellij/lang/jsgraphql/completion/GraphQLOperationsCompletionTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,8 @@ public void testSubscriptionOperationDirectives() {
398398
checkEqualsOrdered(lookupElements, "SubscriptionDir", "SubscriptionDir1");
399399
}
400400

401+
public void testEnumArgumentInInjection() {
402+
LookupElement[] lookupElements = doTestWithProject(".js");
403+
checkEqualsOrdered(lookupElements, "ADMIN", "GUEST", "USER");
404+
}
401405
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const QUERY = gql`
2+
{
3+
field {
4+
user(role: <caret>)
5+
}
6+
}
7+
`;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
schema: schema.graphql
2+
documents: '**/*.graphql'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type Query {
2+
field: FieldType
3+
}
4+
5+
type FieldType {
6+
user(role: UserRole): ID
7+
}
8+
9+
enum UserRole {
10+
ADMIN
11+
USER
12+
GUEST
13+
}

0 commit comments

Comments
 (0)