Skip to content

Commit 55b8b2e

Browse files
committed
Ignore "sub selection required" validation errors for fields annotated with the Apollo client field directive (#164)
1 parent 075f238 commit 55b8b2e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/main/com/intellij/lang/jsgraphql/ide/GraphQLValidationAnnotator.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.intellij.lang.jsgraphql.psi.GraphQLFieldDefinition;
2424
import com.intellij.lang.jsgraphql.psi.*;
2525
import com.intellij.lang.jsgraphql.psi.impl.GraphQLDescriptionAware;
26+
import com.intellij.lang.jsgraphql.psi.impl.GraphQLDirectivesAware;
2627
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaWithErrors;
2728
import com.intellij.lang.jsgraphql.schema.GraphQLTypeDefinitionRegistryServiceImpl;
2829
import com.intellij.lang.jsgraphql.schema.GraphQLTypeScopeProvider;
@@ -312,6 +313,21 @@ public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder a
312313
continue;
313314
}
314315
}
316+
if(validationErrorType == ValidationErrorType.SubSelectionRequired) {
317+
// apollo client 2.5 doesn't require sub selections for client fields
318+
final GraphQLDirectivesAware directivesAware = PsiTreeUtil.getParentOfType(errorPsiElement, GraphQLDirectivesAware.class);
319+
if (directivesAware != null) {
320+
boolean ignoreError = false;
321+
for (GraphQLDirective directive : directivesAware.getDirectives()) {
322+
if ("client".equals(directive.getName())) {
323+
ignoreError = true;
324+
}
325+
}
326+
if (ignoreError) {
327+
continue;
328+
}
329+
}
330+
}
315331
final String message = Optional.ofNullable(validationError.getDescription()).orElse(validationError.getMessage());
316332
createErrorAnnotation(annotationHolder, errorPsiElement, message);
317333
}

0 commit comments

Comments
 (0)