private boolean doesFragmentConditionMatch(FieldCollectorParameters parameters, InlineFragment inlineFragment) { if (inlineFragment.getTypeCondition() == null) { return true; } GraphQLType conditionType; conditionType = getTypeFromAST(parameters.getGraphQLSchema(), inlineFragment.getTypeCondition()); return checkTypeCondition(parameters, conditionType); }
private void collectFieldsForInlineFragment(Map<String, List<FieldAndType>> fieldMap, Set<String> visitedFragmentSpreads, GraphQLType parentType, InlineFragment inlineFragment) { GraphQLType graphQLType = inlineFragment.getTypeCondition() != null ? (GraphQLOutputType) TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), inlineFragment.getTypeCondition()) : parentType; collectFields(fieldMap, inlineFragment.getSelectionSet(), graphQLType, visitedFragmentSpreads); }
@Override public void checkInlineFragment(InlineFragment inlineFragment) { if (inlineFragment.getTypeCondition() == null) { return; } GraphQLType type = getValidationContext().getSchema().getType(inlineFragment.getTypeCondition().getName()); if (type == null) return; if (!(type instanceof GraphQLCompositeType)) { String message = "Inline fragment type condition is invalid, must be on Object/Interface/Union"; addError(ValidationErrorType.InlineFragmentTypeConditionInvalid, inlineFragment.getSourceLocation(), message); } }
private void enterImpl(InlineFragment inlineFragment) { TypeName typeCondition = inlineFragment.getTypeCondition(); GraphQLOutputType type; if (typeCondition != null) { GraphQLType typeConditionType = schema.getType(typeCondition.getName()); if (typeConditionType instanceof GraphQLOutputType) { type = (GraphQLOutputType) typeConditionType; } else { type = null; } } else { type = getParentType(); } addOutputType(type); }
private Builder(InlineFragment existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.typeCondition = existing.getTypeCondition(); this.directives = existing.getDirectives(); this.selectionSet = existing.getSelectionSet(); this.ignoredChars = existing.getIgnoredChars(); }
private NodePrinter<InlineFragment> inlineFragment() { return (out, node) -> { TypeName typeName = node.getTypeCondition(); //Inline fragments may not have a type condition String typeCondition = typeName == null ? "" : wrap("on ", type(typeName), ""); String directives = directives(node.getDirectives()); String selectionSet = node(node.getSelectionSet()); out.printf("%s", comments(node)); out.printf("%s", spaced( "...", typeCondition, directives, selectionSet )); }; }
private Comparator<Selection> comparingSelections() { Function<Selection, String> byName = s -> { if (s instanceof FragmentSpread) { return ((FragmentSpread) s).getName(); } if (s instanceof Field) { return ((Field) s).getName(); } if (s instanceof InlineFragment) { TypeName typeCondition = ((InlineFragment) s).getTypeCondition(); return typeCondition == null ? "" : typeCondition.getName(); } return ""; }; Function<Selection, Integer> byType = s -> { if (s instanceof Field) { return 1; } if (s instanceof FragmentSpread) { return 2; } if (s instanceof InlineFragment) { return 3; } return 4; }; return comparing(byType).thenComparing(comparing(byName)); }
@Override public TraversalControl visitInlineFragment(InlineFragment inlineFragment, TraverserContext<Node> context) { if (!conditionalNodes.shouldInclude(variables, inlineFragment.getDirectives())) { return TraversalControl.ABORT; } QueryVisitorInlineFragmentEnvironment inlineFragmentEnvironment = new QueryVisitorInlineFragmentEnvironmentImpl(inlineFragment, context); if (context.getVar(NodeTraverser.LeaveOrEnter.class) == LEAVE) { postOrderCallback.visitInlineFragment(inlineFragmentEnvironment); return TraversalControl.CONTINUE; } preOrderCallback.visitInlineFragment(inlineFragmentEnvironment); // inline fragments are allowed not have type conditions, if so the parent type counts QueryTraversalContext parentEnv = context.getVarFromParents(QueryTraversalContext.class); GraphQLCompositeType fragmentCondition; if (inlineFragment.getTypeCondition() != null) { TypeName typeCondition = inlineFragment.getTypeCondition(); fragmentCondition = (GraphQLCompositeType) schema.getType(typeCondition.getName()); } else { fragmentCondition = parentEnv.getRawType(); } // for unions we only have other fragments inside context.setVar(QueryTraversalContext.class, new QueryTraversalContext(fragmentCondition, fragmentCondition, parentEnv.getEnvironment(), inlineFragment)); return TraversalControl.CONTINUE; }
private boolean isConditional(Selection selection) { return (selection instanceof FragmentDefinition && ((FragmentDefinition) selection).getTypeCondition() != null) || (selection instanceof InlineFragment && ((InlineFragment) selection).getTypeCondition() != null); }
private boolean doesFragmentConditionMatch(FieldCollectorParameters parameters, InlineFragment inlineFragment) { if (inlineFragment.getTypeCondition() == null) { return true; } GraphQLType conditionType; conditionType = getTypeFromAST(parameters.getGraphQLSchema(), inlineFragment.getTypeCondition()); return checkTypeCondition(parameters, conditionType); }
private Map<String, List<Selection>> getConditionalSelections(SelectionSet selectionSet) { return selectionSet.getSelections().stream() .filter(this::isConditional) .collect(Collectors.groupingBy(s -> s instanceof FragmentDefinition ? ((FragmentDefinition) s).getTypeCondition().getName() : ((InlineFragment) s).getTypeCondition().getName())); }
private void collectFieldsForInlineFragment(Map<String, List<FieldAndType>> fieldMap, Set<String> visitedFragmentSpreads, GraphQLType parentType, InlineFragment inlineFragment) { GraphQLType graphQLType = inlineFragment.getTypeCondition() != null ? (GraphQLOutputType) TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), inlineFragment.getTypeCondition()) : parentType; collectFields(fieldMap, inlineFragment.getSelectionSet(), graphQLType, visitedFragmentSpreads); }
@Override public void checkInlineFragment(InlineFragment inlineFragment) { if (inlineFragment.getTypeCondition() == null) { return; } GraphQLType type = getValidationContext().getSchema().getType(inlineFragment.getTypeCondition().getName()); if (type == null) return; if (!(type instanceof GraphQLCompositeType)) { String message = "Inline fragment type condition is invalid, must be on Object/Interface/Union"; addError(ValidationErrorType.InlineFragmentTypeConditionInvalid, inlineFragment.getSourceLocation(), message); } }
private void collectInlineFragment(FieldCollectorParameters parameters, Map<String, List<ResolvedField>> fields, List<String> visitedFragments, InlineFragment inlineFragment, GraphQLFieldsContainer parent) { if (!conditionalNodes.shouldInclude(parameters.getVariables(), inlineFragment.getDirectives())) { return; } if (inlineFragment.getTypeCondition() != null) { parent = (GraphQLFieldsContainer) getTypeFromAST(parameters.getGraphQLSchema(), inlineFragment.getTypeCondition()); } collectFields(parameters, fields, inlineFragment.getSelectionSet().getSelections(), visitedFragments, parent); }
private void enterImpl(InlineFragment inlineFragment) { TypeName typeCondition = inlineFragment.getTypeCondition(); GraphQLOutputType type; if (typeCondition != null) { GraphQLType typeConditionType = schema.getType(typeCondition.getName()); if (typeConditionType instanceof GraphQLOutputType) { type = (GraphQLOutputType) typeConditionType; } else { type = null; } } else { type = getParentType(); } addOutputType(type); }
private Builder(InlineFragment existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.typeCondition = existing.getTypeCondition(); this.directives = existing.getDirectives(); this.selectionSet = existing.getSelectionSet(); this.ignoredChars = existing.getIgnoredChars(); }
private NodePrinter<InlineFragment> inlineFragment() { return (out, node) -> { TypeName typeName = node.getTypeCondition(); //Inline fragments may not have a type condition String typeCondition = typeName == null ? "" : wrap("on ", type(typeName), ""); String directives = directives(node.getDirectives()); String selectionSet = node(node.getSelectionSet()); out.printf("%s", comments(node)); out.printf("%s", spaced( "...", typeCondition, directives, selectionSet )); }; }
private Comparator<Selection> comparingSelections() { Function<Selection, String> byName = s -> { if (s instanceof FragmentSpread) { return ((FragmentSpread) s).getName(); } if (s instanceof Field) { return ((Field) s).getName(); } if (s instanceof InlineFragment) { TypeName typeCondition = ((InlineFragment) s).getTypeCondition(); return typeCondition == null ? "" : typeCondition.getName(); } return ""; }; Function<Selection, Integer> byType = s -> { if (s instanceof Field) { return 1; } if (s instanceof FragmentSpread) { return 2; } if (s instanceof InlineFragment) { return 3; } return 4; }; return comparing(byType).thenComparing(comparing(byName)); }
if (selection instanceof InlineFragment) { InlineFragment fragment = (InlineFragment) selection; final String typeConditionName = fragment.getTypeCondition().getName(); String typeUri = typeNameStore.makeUri( typeConditionName.startsWith(prefix) ?
@Override public TraversalControl visitInlineFragment(InlineFragment inlineFragment, TraverserContext<Node> context) { if (!conditionalNodes.shouldInclude(variables, inlineFragment.getDirectives())) { return TraversalControl.ABORT; } QueryVisitorInlineFragmentEnvironment inlineFragmentEnvironment = new QueryVisitorInlineFragmentEnvironmentImpl(inlineFragment, context); if (context.getVar(NodeTraverser.LeaveOrEnter.class) == LEAVE) { postOrderCallback.visitInlineFragment(inlineFragmentEnvironment); return TraversalControl.CONTINUE; } preOrderCallback.visitInlineFragment(inlineFragmentEnvironment); // inline fragments are allowed not have type conditions, if so the parent type counts QueryTraversalContext parentEnv = context.getVarFromParents(QueryTraversalContext.class); GraphQLCompositeType fragmentCondition; if (inlineFragment.getTypeCondition() != null) { TypeName typeCondition = inlineFragment.getTypeCondition(); fragmentCondition = (GraphQLCompositeType) schema.getType(typeCondition.getName()); } else { fragmentCondition = parentEnv.getRawType(); } // for unions we only have other fragments inside context.setVar(QueryTraversalContext.class, new QueryTraversalContext(fragmentCondition, fragmentCondition, parentEnv.getEnvironment(), inlineFragment)); return TraversalControl.CONTINUE; }