apoc.graph.fromDocumentProcedure
| This procedure returns virtual nodes and relationships that can only be accessed by other APOC procedures. For more information, see Virtual Nodes & Relationships (Graph Projections). | 
| Syntax | 
 | ||
| Description | Generates a virtual sub-graph by extracting all of the  | ||
| Input arguments | Name | Type | Description | 
| 
 | 
 | A JSON object to generate a graph from. | |
| 
 | 
 | 
 | |
| Return arguments | Name | Type | Description | 
| 
 | 
 | The resulting graph. | |
Config parameters
The procedure supports the following config parameters:
| Name | Type | Default | Description | 
|---|---|---|---|
| 
 | 
 | false | Persist the graph otherwise return a Virtual Graph. | 
| 
 | 
 | type | The field name that became the label of the node. | 
| 
 | 
 | id | The document field name that will become the id field of the created nodes (used for node resolution when you create relationships between nodes). | 
| 
 | 
 | true | In case of missing id-field value it generates a UUID for it. | 
| 
 | 
 | "" | In case of missing label-field value is uses the provided default label. | 
| 
 | 
 | false | In case you want skip the validation process into the  | 
| 
 | 
 | {} | Click on link below for more detail. | 
Usage Examples
CALL apoc.graph.fromDocument("{'id': 1,'type': 'artist','name':'Genesis','members': ['Tony Banks','Mike Rutherford','Phil Collins'],'years': [1967, 1998, 1999, 2000, 2006],'albums': [{'type': 'album','id': 1,'producer': 'Jonathan King','title': 'From Genesis to Revelation'}]}", {write: false})
YIELD graph AS g
RETURN g.nodes AS nodes, g.relationships AS rels;| nodes | rels | 
|---|---|
| [(:Artist {name: "Genesis", id: 1, type: "artist", years: [1967, 1998, 1999, 2000, 2006], members: ["Tony Banks", "Mike Rutherford", "Phil Collins"]}), (:Album {producer: "Jonathan King", id: 1, type: "album", title: "From Genesis to Revelation"})] | [[:ALBUMS]] | 
CALL apoc.graph.fromDocument("{'id': 1,'type': 'artist','name':'Genesis','members': ['Tony Banks','Mike Rutherford','Phil Collins'],'years': [1967, 1998, 1999, 2000, 2006],'albums': [{'type': 'album','id': 1,'producer': 'Jonathan King','title': 'From Genesis to Revelation'}]}", {write: false})
YIELD graph
RETURN *As a result we have a virtual graph with two nodes and one relationship:
 
CALL apoc.graph.fromDocument('{"id":10,"myCustomType":"labelArtist","name":"Genesis","albums":[{"myCustomType":"labelAlbum","producer":"Jonathan King","id":20,"title":"From Genesis to Revelation"}]}', {labelField: "myCustomType"})
YIELD graph
RETURN *As a result we have a virtual graph with two nodes and one relationship:
 
CALL apoc.graph.fromDocument('{"myCustomType":"labelArtist","name":"Genesis","myCustomId":1,"albums":[{"myCustomType":"labelAlbum","producer":"Jonathan King","myCustomId":1,"title":"From Genesis to Revelation"}]}',
{labelField: "myCustomType", idField: "myCustomId"})
YIELD graph
RETURN *As a result we have a virtual graph with two nodes and one relationship:
 
CALL apoc.graph.fromDocument('{"id":1,"type":"Person","name":"Andrea","sizes":{"weight":{"value":70,"um":"Kg"},"height":{"value":174,"um":"cm"},"array":["foo","bar"]},"books":[{"title":"Flow My Tears, the Policeman Said","released":1974},{"title":"The man in the High Castle","released":1962}]}',
{mappings:{`$`:"Person:Reader{*,@sizes}",`$.books`:"Book{!title, released}"}})
yield graph
RETURN *As a result we have a virtual graph with three nodes and two relationship:
 
relMappingWe can pass a relMapping to customize relationship names, passing a map with the relationships you want to change as keys.
For example:
CALL apoc.graph.fromDocument("{'id': 1,'type': 'artist','name':'Genesis','members': ['Tony Banks','Mike Rutherford','Phil Collins'],'years': [1967, 1998, 1999, 2000, 2006],'albums': [{'type': 'album','id': 1,'producer': 'Jonathan King','title': 'From Genesis to Revelation'}]}",
{relMapping: {albums: "CUSTOM_REL"}});