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(); }
@Override public InlineFragment deepCopy() { return new InlineFragment( deepCopy(typeCondition), deepCopy(directives), deepCopy(selectionSet), getSourceLocation(), getComments(), getIgnoredChars() ); }
public Directive getDirective(String directiveName) { return getDirectivesByName().get(directiveName); }
@Override public TraversalControl visitInlineFragment(InlineFragment node, TraverserContext<Node> context) { InlineFragment changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.selectionSet(sortSelectionSet(node.getSelectionSet())); }); return changeNode(context, changedNode); }
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 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 collectInlineFragment(FieldCollectorParameters parameters, List<String> visitedFragments, Map<String, MergedField> fields, InlineFragment inlineFragment) { if (!conditionalNodes.shouldInclude(parameters.getVariables(), inlineFragment.getDirectives()) || !doesFragmentConditionMatch(parameters, inlineFragment)) { return; } collectFields(parameters, inlineFragment.getSelectionSet(), visitedFragments, fields); }
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 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; }
@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); } }
@Override public void checkInlineFragment(InlineFragment inlineFragment) { checkDirectivesUniqueness(inlineFragment, inlineFragment.getDirectives()); }
public InlineFragment build() { InlineFragment inlineFragment = new InlineFragment(typeCondition, directives, selectionSet, sourceLocation, comments, ignoredChars); return inlineFragment; } }
@Override public void checkInlineFragment(InlineFragment inlineFragment) { GraphQLOutputType fragType = getValidationContext().getOutputType(); GraphQLCompositeType parentType = getValidationContext().getParentType(); if (fragType == null || parentType == null) return; if (isValidTargetCompositeType(fragType) && isValidTargetCompositeType(parentType) && !doTypesOverlap(fragType, parentType)) { String message = String.format("Fragment cannot be spread here as objects of " + "type %s can never be of type %s", parentType.getName(), fragType.getName()); addError(ValidationErrorType.InvalidFragmentType, inlineFragment.getSourceLocation(), message); } }
protected InlineFragment createInlineFragment(GraphqlParser.InlineFragmentContext ctx) { InlineFragment.Builder inlineFragment = InlineFragment.newInlineFragment(); addCommonData(inlineFragment, ctx); if (ctx.typeCondition() != null) { inlineFragment.typeCondition(createTypeName(ctx.typeCondition().typeName())); } inlineFragment.directives(createDirectives(ctx.directives())); inlineFragment.selectionSet(createSelectionSet(ctx.selectionSet())); return inlineFragment.build(); }
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); }
@Override public TraversalControl visitInlineFragment(InlineFragment node, TraverserContext<Node> context) { InlineFragment changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.selectionSet(sortSelectionSet(node.getSelectionSet())); }); return changeNode(context, changedNode); }
@Override public void visitInlineFragment(QueryVisitorInlineFragmentEnvironment env) { InlineFragment fragment = env.getInlineFragment(); boolean containsField = fieldsToFind.stream().anyMatch(field -> fragment.getSelectionSet().getSelections().contains(field)); boolean isRelevant = containsField || relevantFragments.stream().anyMatch(frag -> fragment.getSelectionSet().getSelections().contains(frag)); if (isRelevant) { relevantFragments.add(fragment); inlineFragmentDirs.addAll(fragment.getDirectives()); } }
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 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; }