private void checkInterfacesAreImplemented(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) { Map<String, TypeDefinition> typesMap = typeRegistry.types(); // objects List<ObjectTypeDefinition> objectTypes = filterTo(typesMap, ObjectTypeDefinition.class); objectTypes.forEach(objectType -> { List<Type> implementsTypes = objectType.getImplements(); implementsTypes.forEach(checkInterfaceIsImplemented("object", typeRegistry, errors, objectType)); }); Map<String, List<ObjectTypeExtensionDefinition>> typeExtensions = typeRegistry.objectTypeExtensions(); typeExtensions.values().forEach(extList -> extList.forEach(typeExtension -> { List<Type> implementsTypes = typeExtension.getImplements(); implementsTypes.forEach(checkInterfaceIsImplemented("extension", typeRegistry, errors, typeExtension)); })); }
/** * Returns the list of object types that implement the given interface type * * @param targetInterface the target to search for * * @return the list of object types that implement the given interface type */ public List<ObjectTypeDefinition> getImplementationsOf(InterfaceTypeDefinition targetInterface) { List<ObjectTypeDefinition> objectTypeDefinitions = getTypes(ObjectTypeDefinition.class); return objectTypeDefinitions.stream().filter(objectTypeDefinition -> { List<Type> implementsList = objectTypeDefinition.getImplements(); for (Type iFace : implementsList) { Optional<InterfaceTypeDefinition> interfaceTypeDef = getType(iFace, InterfaceTypeDefinition.class); if (interfaceTypeDef.isPresent()) { boolean equals = interfaceTypeDef.get().getName().equals(targetInterface.getName()); if (equals) { return true; } } } return false; }).collect(Collectors.toList()); }
private void buildObjectTypeInterfaces(BuildContext buildCtx, ObjectTypeDefinition typeDefinition, GraphQLObjectType.Builder builder, List<ObjectTypeExtensionDefinition> extensions) { Map<String, GraphQLOutputType> interfaces = new LinkedHashMap<>(); typeDefinition.getImplements().forEach(type -> { GraphQLOutputType newInterfaceType = buildOutputType(buildCtx, type); interfaces.put(newInterfaceType.getName(), newInterfaceType); }); extensions.forEach(extension -> extension.getImplements().forEach(type -> { GraphQLInterfaceType interfaceType = buildOutputType(buildCtx, type); if (!interfaces.containsKey(interfaceType.getName())) { interfaces.put(interfaceType.getName(), interfaceType); } })); interfaces.values().forEach(interfaze -> { if (interfaze instanceof GraphQLInterfaceType) { builder.withInterface((GraphQLInterfaceType) interfaze); return; } if (interfaze instanceof GraphQLTypeReference) { builder.withInterface((GraphQLTypeReference) interfaze); return; } }); }
private void checkObjectType(DiffCtx ctx, ObjectTypeDefinition oldDef, ObjectTypeDefinition newDef) { Map<String, FieldDefinition> oldFields = sortedMap(oldDef.getFieldDefinitions(), FieldDefinition::getName); Map<String, FieldDefinition> newFields = sortedMap(newDef.getFieldDefinitions(), FieldDefinition::getName); checkFields(ctx, oldDef, oldFields, newDef, newFields); checkImplements(ctx, oldDef, oldDef.getImplements(), newDef.getImplements()); checkDirectives(ctx, oldDef, newDef); }
private NodePrinter<ObjectTypeDefinition> objectTypeDefinition() { return (out, node) -> { out.printf("%s", comments(node)); out.printf("%s", spaced( "type", node.getName(), wrap("implements ", join(node.getImplements(), " & "), ""), directives(node.getDirectives()), block(node.getFieldDefinitions()) )); }; }
objectTypes.forEach(objectType -> { List<Type> implementsTypes = objectType.getImplements(); implementsTypes.forEach(checkInterfaceTypeExists(typeRegistry, errors, objectType));
@Override public TraversalControl visitObjectTypeDefinition(ObjectTypeDefinition node, TraverserContext<Node> context) { ObjectTypeDefinition changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.implementz(sort(node.getImplements(), comparingTypes())); builder.fieldDefinitions(sort(node.getFieldDefinitions(), comparing(FieldDefinition::getName))); }); return changeNode(context, changedNode); }
private Builder(ObjectTypeDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.description = existing.getDescription(); this.directives = existing.getDirectives(); this.implementz = existing.getImplements(); this.fieldDefinitions = existing.getFieldDefinitions(); this.ignoredChars = existing.getIgnoredChars(); }
/** * Returns the list of object types that implement the given interface type * * @param targetInterface the target to search for * * @return the list of object types that implement the given interface type */ public List<ObjectTypeDefinition> getImplementationsOf(InterfaceTypeDefinition targetInterface) { List<ObjectTypeDefinition> objectTypeDefinitions = getTypes(ObjectTypeDefinition.class); return objectTypeDefinitions.stream().filter(objectTypeDefinition -> { List<Type> implementsList = objectTypeDefinition.getImplements(); for (Type iFace : implementsList) { Optional<InterfaceTypeDefinition> interfaceTypeDef = getType(iFace, InterfaceTypeDefinition.class); if (interfaceTypeDef.isPresent()) { boolean equals = interfaceTypeDef.get().getName().equals(targetInterface.getName()); if (equals) { return true; } } } return false; }).collect(Collectors.toList()); }
private void checkInterfacesAreImplemented(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) { Map<String, TypeDefinition> typesMap = typeRegistry.types(); // objects List<ObjectTypeDefinition> objectTypes = filterTo(typesMap, ObjectTypeDefinition.class); objectTypes.forEach(objectType -> { List<Type> implementsTypes = objectType.getImplements(); implementsTypes.forEach(checkInterfaceIsImplemented("object", typeRegistry, errors, objectType)); }); Map<String, List<ObjectTypeExtensionDefinition>> typeExtensions = typeRegistry.objectTypeExtensions(); typeExtensions.values().forEach(extList -> extList.forEach(typeExtension -> { List<Type> implementsTypes = typeExtension.getImplements(); implementsTypes.forEach(checkInterfaceIsImplemented("extension", typeRegistry, errors, typeExtension)); })); }
public List<Interface> getInterfaces() { interfaces = new ArrayList<>(); if (!isObjectType()) { return interfaces; } ObjectTypeDefinition objectTypeDefinition = (ObjectTypeDefinition) typeEntry.getDefinition(); List<Type> interfaceTypes = objectTypeDefinition.getImplements(); for (Type anInterfaceType : interfaceTypes) { Interface anInterface = new Interface(); anInterface.type = toJavaTypeName(anInterfaceType); interfaces.add(anInterface); } return interfaces; }
private void buildObjectTypeInterfaces(BuildContext buildCtx, ObjectTypeDefinition typeDefinition, GraphQLObjectType.Builder builder, List<ObjectTypeExtensionDefinition> extensions) { Map<String, GraphQLOutputType> interfaces = new LinkedHashMap<>(); typeDefinition.getImplements().forEach(type -> { GraphQLOutputType newInterfaceType = buildOutputType(buildCtx, type); interfaces.put(newInterfaceType.getName(), newInterfaceType); }); extensions.forEach(extension -> extension.getImplements().forEach(type -> { GraphQLInterfaceType interfaceType = buildOutputType(buildCtx, type); if (!interfaces.containsKey(interfaceType.getName())) { interfaces.put(interfaceType.getName(), interfaceType); } })); interfaces.values().forEach(interfaze -> { if (interfaze instanceof GraphQLInterfaceType) { builder.withInterface((GraphQLInterfaceType) interfaze); return; } if (interfaze instanceof GraphQLTypeReference) { builder.withInterface((GraphQLTypeReference) interfaze); return; } }); }
private void checkObjectType(DiffCtx ctx, ObjectTypeDefinition oldDef, ObjectTypeDefinition newDef) { Map<String, FieldDefinition> oldFields = sortedMap(oldDef.getFieldDefinitions(), FieldDefinition::getName); Map<String, FieldDefinition> newFields = sortedMap(newDef.getFieldDefinitions(), FieldDefinition::getName); checkFields(ctx, oldDef, oldFields, newDef, newFields); checkImplements(ctx, oldDef, oldDef.getImplements(), newDef.getImplements()); checkDirectives(ctx, oldDef, newDef); }
objectTypes.forEach(objectType -> { List<Type> implementsTypes = objectType.getImplements(); implementsTypes.forEach(checkInterfaceTypeExists(typeRegistry, errors, objectType));
private NodePrinter<ObjectTypeDefinition> objectTypeDefinition() { return (out, node) -> { out.printf("%s", comments(node)); out.printf("%s", spaced( "type", node.getName(), wrap("implements ", join(node.getImplements(), " & "), ""), directives(node.getDirectives()), block(node.getFieldDefinitions()) )); }; }
@Override public TraversalControl visitObjectTypeDefinition(ObjectTypeDefinition node, TraverserContext<Node> context) { ObjectTypeDefinition changedNode = node.transform(builder -> { builder.directives(sort(node.getDirectives(), comparing(Directive::getName))); builder.implementz(sort(node.getImplements(), comparingTypes())); builder.fieldDefinitions(sort(node.getFieldDefinitions(), comparing(FieldDefinition::getName))); }); return changeNode(context, changedNode); }
private Builder(ObjectTypeDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.name = existing.getName(); this.description = existing.getDescription(); this.directives = existing.getDirectives(); this.implementz = existing.getImplements(); this.fieldDefinitions = existing.getFieldDefinitions(); this.ignoredChars = existing.getIgnoredChars(); }