Write a piece of code that detects a cycle in a graph.
Treat the graph as directed and represented by an adjacency-list dictionary. Return True if any directed cycle exists, including a self-loop, otherwise return False. The function must inspect disconnected components, and a neighbor absent from the dictionary should be treated as a node with no outgoing edges.
Use def has_cycle(graph):, where graph is a JSON object whose keys identify nodes and whose values are lists of neighboring node identifiers. Return a boolean.
def has_cycle(graph):