Skip to content

Commit 808d075

Browse files
committed
Additional logging for GraphQL libraries
1 parent f0d0ae7 commit 808d075

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/main/com/intellij/lang/jsgraphql/ide/resolve/GraphQLResolveUtil.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.intellij.lang.jsgraphql.schema.library.GraphQLLibrary;
55
import com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryDescriptor;
66
import com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryRootsProvider;
7+
import com.intellij.openapi.diagnostic.Logger;
78
import com.intellij.openapi.vfs.VirtualFile;
89
import com.intellij.psi.PsiElement;
910
import com.intellij.psi.PsiFile;
@@ -18,21 +19,30 @@
1819
import java.util.Collection;
1920

2021
public final class GraphQLResolveUtil {
22+
23+
private static final Logger LOG = Logger.getInstance(GraphQLResolveUtil.class);
24+
2125
private GraphQLResolveUtil() {
2226
}
2327

2428
public static void processFilesInLibrary(@NotNull GraphQLLibraryDescriptor libraryDescriptor,
2529
@NotNull PsiElement context,
2630
@NotNull Processor<? super GraphQLFile> processor) {
2731
GraphQLLibrary library = GraphQLLibraryRootsProvider.findLibrary(context.getProject(), libraryDescriptor);
28-
if (library == null) return;
32+
if (library == null) {
33+
LOG.warn("Library is not found: " + libraryDescriptor);
34+
return;
35+
}
2936

3037
PsiManager psiManager = context.getManager();
3138
for (VirtualFile root : library.getSourceRoots()) {
3239
PsiFile file = psiManager.findFile(root);
33-
if (file instanceof GraphQLFile && file.isValid()) {
34-
if (!processor.process(((GraphQLFile) file))) return;
40+
if (!(file instanceof GraphQLFile) || !file.isValid()) {
41+
LOG.warn("Library file is invalid: " + root.getPath());
42+
continue;
3543
}
44+
45+
if (!processor.process(((GraphQLFile) file))) return;
3646
}
3747
}
3848

src/main/com/intellij/lang/jsgraphql/schema/library/GraphQLLibraryDescriptor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.intellij.openapi.project.Project;
44
import org.jetbrains.annotations.NotNull;
55

6+
import java.util.Objects;
7+
68
public class GraphQLLibraryDescriptor {
79

810
private final String myIdentifier;
@@ -25,6 +27,19 @@ public boolean isEnabled(@NotNull Project project) {
2527
return true;
2628
}
2729

30+
@Override
31+
public boolean equals(Object o) {
32+
if (this == o) return true;
33+
if (o == null || getClass() != o.getClass()) return false;
34+
GraphQLLibraryDescriptor that = (GraphQLLibraryDescriptor) o;
35+
return Objects.equals(myIdentifier, that.myIdentifier);
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return Objects.hash(myIdentifier);
41+
}
42+
2843
@Override
2944
public String toString() {
3045
return "GraphQLLibraryDescriptor{" +

src/main/com/intellij/lang/jsgraphql/schema/library/GraphQLLibraryManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public GraphQLLibrary getOrCreateLibrary(@NotNull GraphQLLibraryDescriptor libra
6262
return myLibraries.computeIfAbsent(libraryDescriptor, __ -> {
6363
VirtualFile root = resolveLibraryRoot(libraryDescriptor);
6464
if (root == null) {
65+
LOG.warn("Unresolved library root: " + libraryDescriptor);
6566
return null;
6667
}
6768
return new GraphQLLibrary(libraryDescriptor, root);
@@ -79,8 +80,12 @@ public Collection<SyntheticLibrary> getAllLibraries() {
7980
}
8081

8182
@Nullable
82-
private VirtualFile resolveLibraryRoot(@NotNull GraphQLLibraryDescriptor definition) {
83-
String resourceName = ourDefinitionResourcePaths.get(definition);
83+
private VirtualFile resolveLibraryRoot(@NotNull GraphQLLibraryDescriptor descriptor) {
84+
String resourceName = ourDefinitionResourcePaths.get(descriptor);
85+
if (resourceName == null) {
86+
LOG.error("No resource files found for library: " + descriptor);
87+
return null;
88+
}
8489
URL resource = getClass().getClassLoader().getResource(DEFINITIONS_RESOURCE_DIR + resourceName);
8590
if (resource == null) {
8691
LOG.error("Resource not found: " + resourceName);

0 commit comments

Comments
 (0)