public String getName() { return typeName.getName(); }
public boolean hasType(TypeName typeName) { String name = typeName.getName(); return types.containsKey(name) || ScalarInfo.STANDARD_SCALAR_DEFINITIONS.containsKey(name) || scalarTypes.containsKey(name) || objectTypeExtensions.containsKey(name); }
public MissingTypeError(String typeOfType, Node node, String name, TypeName typeName) { super(node, format("The %s type '%s' is not present when resolving type '%s' %s", typeOfType, typeName.getName(), name, lineCol(node))); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TypeInfo typeInfo = (TypeInfo) o; return isNonNull() == typeInfo.isNonNull() && isList() == typeInfo.isList() && Objects.equals(typeName.getName(), typeInfo.typeName.getName()); }
public MissingInterfaceTypeError(String typeOfType, TypeDefinition typeDefinition, TypeName typeName) { super(typeDefinition, format("The %s type '%s' is not present when resolving type '%s' %s", typeOfType, typeName.getName(), typeDefinition.getName(), lineCol(typeDefinition))); } }
@Override public int hashCode() { return Objects.hash(typeName.getName(), isNonNull(), isList()); }
public MissingTypeError(String typeOfType, TypeDefinition typeDefinition, TypeName typeName) { super(typeDefinition, format("The %s type '%s' is not present when resolving type '%s' %s", typeOfType, typeName.getName(), typeDefinition.getName(), lineCol(typeDefinition))); }
private Builder(TypeName existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); }
private void checkArgValueMatchesAllowedTypeName(List<GraphQLError> errors, Value instanceValue, Type allowedArgType) { if (instanceValue instanceof NullValue) { return; } String allowedTypeName = ((TypeName) allowedArgType).getName(); TypeDefinition allowedTypeDefinition = typeRegistry.getType(allowedTypeName) .orElseThrow(() -> new AssertException("Directive unknown argument type '%s'. This should have been validated before.")); if (allowedTypeDefinition instanceof ScalarTypeDefinition) { checkArgValueMatchesAllowedScalar(errors, instanceValue, allowedTypeName); } else if (allowedTypeDefinition instanceof EnumTypeDefinition) { checkArgValueMatchesAllowedEnum(errors, instanceValue, (EnumTypeDefinition) allowedTypeDefinition); } else if (allowedTypeDefinition instanceof InputObjectTypeDefinition) { checkArgValueMatchesAllowedInputType(errors, instanceValue, (InputObjectTypeDefinition) allowedTypeDefinition); } else { assertShouldNeverHappen("'%s' must be an input type. It is %s instead. ", allowedTypeName, allowedTypeDefinition.getClass()); } }
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 void checkImplements(DiffCtx ctx, ObjectTypeDefinition old, List<Type> oldImplements, List<Type> newImplements) { Map<String, Type> oldImplementsMap = sortedMap(oldImplements, t -> ((TypeName) t).getName()); Map<String, Type> newImplementsMap = sortedMap(newImplements, t -> ((TypeName) t).getName()); for (Map.Entry<String, Type> entry : oldImplementsMap.entrySet()) { InterfaceTypeDefinition oldInterface = ctx.getOldTypeDef(entry.getValue(), InterfaceTypeDefinition.class).get(); Optional<InterfaceTypeDefinition> newInterface = ctx.getNewTypeDef(newImplementsMap.get(entry.getKey()), InterfaceTypeDefinition.class); if (!newInterface.isPresent()) { ctx.report(DiffEvent.apiBreakage() .category(DiffCategory.MISSING) .typeName(old.getName()) .typeKind(getTypeKind(old)) .components(oldInterface.getName()) .reasonMsg("The new API is missing the interface named '%s'", oldInterface.getName()) .build()); } else { checkInterfaceType(ctx, oldInterface, newInterface.get()); } } }
private void enterImpl(FragmentDefinition fragmentDefinition) { enterName(fragmentDefinition.getName()); GraphQLType type = schema.getType(fragmentDefinition.getTypeCondition().getName()); addOutputType(type instanceof GraphQLOutputType ? (GraphQLOutputType) type : null); }
private String type(Type type) { if (type instanceof NonNullType) { NonNullType inner = (NonNullType) type; return wrap("", type(inner.getType()), "!"); } else if (type instanceof ListType) { ListType inner = (ListType) type; return wrap("[", type(inner.getType()), "]"); } else { TypeName inner = (TypeName) type; return inner.getName(); } }
@Override public void checkFragmentDefinition(FragmentDefinition fragmentDefinition) { GraphQLType type = getValidationContext().getSchema().getType(fragmentDefinition.getTypeCondition().getName()); if (type == null) return; if (!(type instanceof GraphQLCompositeType)) { String message = "Fragment type condition is invalid, must be on Object/Interface/Union"; addError(ValidationErrorType.InlineFragmentTypeConditionInvalid, fragmentDefinition.getSourceLocation(), message); } } }
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) { GraphQLType innerType; if (type instanceof ListType) { innerType = getTypeFromAST(schema, ((ListType) type).getType()); return innerType != null ? list(innerType) : null; } else if (type instanceof NonNullType) { innerType = getTypeFromAST(schema, ((NonNullType) type).getType()); return innerType != null ? nonNull(innerType) : null; } return schema.getType(((TypeName) type).getName()); } }
@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 checkVariableDefinition(VariableDefinition variableDefinition) { TypeName unmodifiedAstType = getValidationUtil().getUnmodifiedType(variableDefinition.getType()); GraphQLType type = getValidationContext().getSchema().getType(unmodifiedAstType.getName()); if (type == null) return; if (!isInput(type)) { String message = "Wrong type for a variable"; addError(ValidationErrorType.NonInputTypeOnVariable, variableDefinition.getSourceLocation(), message); } } }
@Override public TraversalControl visitFragmentDefinition(FragmentDefinition node, TraverserContext<Node> context) { if (!conditionalNodes.shouldInclude(variables, node.getDirectives())) { return TraversalControl.ABORT; } if (context.getVar(NodeTraverser.LeaveOrEnter.class) == LEAVE) { return TraversalControl.CONTINUE; } QueryTraversalContext parentEnv = context.getVarFromParents(QueryTraversalContext.class); GraphQLCompositeType typeCondition = (GraphQLCompositeType) schema.getType(node.getTypeCondition().getName()); context .setVar(QueryTraversalContext.class, new QueryTraversalContext(typeCondition, typeCondition, parentEnv.getEnvironment(), node)); return TraversalControl.CONTINUE; }
@Override public TraversalControl visitFragmentSpread(FragmentSpread fragmentSpread, TraverserContext<Node> context) { if (!conditionalNodes.shouldInclude(variables, fragmentSpread.getDirectives())) { return TraversalControl.ABORT; } FragmentDefinition fragmentDefinition = fragmentsByName.get(fragmentSpread.getName()); if (!conditionalNodes.shouldInclude(variables, fragmentDefinition.getDirectives())) { return TraversalControl.ABORT; } QueryVisitorFragmentSpreadEnvironment fragmentSpreadEnvironment = new QueryVisitorFragmentSpreadEnvironmentImpl(fragmentSpread, fragmentDefinition, context); if (context.getVar(NodeTraverser.LeaveOrEnter.class) == LEAVE) { postOrderCallback.visitFragmentSpread(fragmentSpreadEnvironment); return TraversalControl.CONTINUE; } preOrderCallback.visitFragmentSpread(fragmentSpreadEnvironment); QueryTraversalContext parentEnv = context.getVarFromParents(QueryTraversalContext.class); GraphQLCompositeType typeCondition = (GraphQLCompositeType) schema.getType(fragmentDefinition.getTypeCondition().getName()); assertNotNull(typeCondition, "Invalid type condition '%s' in fragment '%s'", fragmentDefinition.getTypeCondition().getName(), fragmentDefinition.getName()); context .setVar(QueryTraversalContext.class, new QueryTraversalContext(typeCondition, typeCondition, parentEnv.getEnvironment(), fragmentDefinition)); return TraversalControl.CONTINUE; }