Skip to content

Commit 374dbf8

Browse files
committed
Prevent caching an empty schema because of PCE
1 parent 77410eb commit 374dbf8

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/main/com/intellij/lang/jsgraphql/ide/editor/GraphQLIntrospectionService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
import com.intellij.openapi.application.WriteAction;
3232
import com.intellij.openapi.command.WriteCommandAction;
3333
import com.intellij.openapi.components.ServiceManager;
34-
import com.intellij.openapi.editor.EditorBundle;
3534
import com.intellij.openapi.fileEditor.FileEditor;
3635
import com.intellij.openapi.fileEditor.FileEditorManager;
3736
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
3837
import com.intellij.openapi.fileEditor.TextEditor;
3938
import com.intellij.openapi.fileTypes.PlainTextLanguage;
39+
import com.intellij.openapi.progress.ProcessCanceledException;
4040
import com.intellij.openapi.progress.ProgressIndicator;
4141
import com.intellij.openapi.progress.ProgressManager;
4242
import com.intellij.openapi.progress.Task;
@@ -474,6 +474,8 @@ public void run(@NotNull ProgressIndicator indicator) {
474474
// always try to print the schema to validate it since that will be done in schema discovery of the JSON anyway
475475
final String schemaAsSDL = printIntrospectionAsGraphQL(introspection);
476476
schemaText = format == IntrospectionOutputFormat.SDL ? schemaAsSDL : responseJson;
477+
} catch (ProcessCanceledException exception) {
478+
throw exception;
477479
} catch (Exception exception) {
478480
handleIntrospectionError(exception, null, responseJson);
479481
return;
@@ -482,6 +484,8 @@ public void run(@NotNull ProgressIndicator indicator) {
482484
ApplicationManager.getApplication().invokeLater(() -> {
483485
try {
484486
createOrUpdateIntrospectionOutputFile(schemaText, format, introspectionSourceFile, schemaPath);
487+
} catch (ProcessCanceledException exception) {
488+
throw exception;
485489
} catch (Exception e) {
486490
handleIntrospectionError(e, null, responseJson);
487491
}

src/main/com/intellij/lang/jsgraphql/schema/GraphQLRegistryProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.intellij.openapi.components.ServiceManager;
2727
import com.intellij.openapi.diagnostic.Logger;
2828
import com.intellij.openapi.editor.LogicalPosition;
29+
import com.intellij.openapi.progress.ProcessCanceledException;
2930
import com.intellij.openapi.project.Project;
3031
import com.intellij.openapi.util.Ref;
3132
import com.intellij.openapi.util.TextRange;
@@ -181,6 +182,8 @@ private GraphQLValidatedTypeDefinitionRegistry getRegistry(@NotNull PsiElement s
181182
processFile.accept(newIntrospectionFile);
182183
}
183184
}
185+
} catch (ProcessCanceledException e) {
186+
throw e;
184187
} catch (Exception e) {
185188
final List<SourceLocation> sourceLocation = Collections.singletonList(new SourceLocation(1, 1, GraphQLPsiUtil.getFileName(psiFile)));
186189
errors.add(new SchemaProblem(Collections.singletonList(new InvalidSyntaxError(sourceLocation, e.getMessage()))));

src/main/com/intellij/lang/jsgraphql/schema/GraphQLSchemaProviderImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
1212
import com.intellij.lang.jsgraphql.psi.GraphQLPsiUtil;
1313
import com.intellij.openapi.Disposable;
1414
import com.intellij.openapi.diagnostic.Logger;
15+
import com.intellij.openapi.progress.ProcessCanceledException;
1516
import com.intellij.openapi.project.Project;
1617
import com.intellij.psi.PsiElement;
17-
import graphql.Directives;
1818
import graphql.GraphQLException;
19-
import graphql.schema.GraphQLDirective;
2019
import graphql.schema.GraphQLObjectType;
2120
import graphql.schema.GraphQLSchema;
2221
import graphql.schema.idl.TypeDefinitionRegistry;
2322
import graphql.schema.idl.UnExecutableSchemaGenerator;
2423
import org.jetbrains.annotations.NotNull;
2524

26-
import java.lang.reflect.Field;
27-
import java.util.Collection;
2825
import java.util.Collections;
2926
import java.util.Map;
3027

@@ -73,6 +70,8 @@ public GraphQLValidatedSchema getValidatedSchema(@NotNull PsiElement psiElement)
7370
try {
7471
final GraphQLSchema schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(registryWithErrors.getRegistry());
7572
return new GraphQLValidatedSchema(schema, Collections.emptyList(), registryWithErrors);
73+
} catch (ProcessCanceledException e) {
74+
throw e;
7675
} catch (GraphQLException e) {
7776
if (LOG.isDebugEnabled()) {
7877
LOG.debug("Schema build error:", e);
@@ -93,6 +92,8 @@ public GraphQLSchema getTolerantSchema(@NotNull PsiElement psiElement) {
9392
return fileNameToTolerantSchema.computeIfAbsent(GraphQLPsiUtil.getFileName(psiElement.getContainingFile()), fileName -> {
9493
try {
9594
return UnExecutableSchemaGenerator.makeUnExecutableSchema(getTolerantRegistry(psiElement));
95+
} catch (ProcessCanceledException e) {
96+
throw e;
9697
} catch (Exception e) {
9798
if (LOG.isDebugEnabled()) {
9899
LOG.debug("Schema build error:", e);

0 commit comments

Comments
 (0)