Python neo4j driver to return the selected cypher query nodes and relationships in graph format

I tried to use below code snippet to read the query result which should return all
nodes and respective all relationships

result = session.run(query, param)
print(result.graph().relationships.items())
print(result.graph().nodes.items())

Can you anyone help me to return the result so I come to know properly,
using python 3.10 and neo4j 5 version along neo4j python driver.

#python #neo4j #pythondriver #cypher

@glilienfield can you give some sample code snippet? because when I try I didnt find anything in the documentation as such

Note, the result of calling ‘relationships’ is a set of relationships. Similarly, ‘nodes’ returns a set of nodes. As such, you have to iterate over each set and apply ‘items()’ to each set element.