@@ -65,6 +65,7 @@ For a more detailed overview and getting started guide, please see
65
65
* [ Pretty-Printing GraphQL Queries] ( #pretty-printing-graphql-queries )
66
66
* [ Expanding ` @optional ` vertex fields] ( #expanding-optional-vertex-fields )
67
67
* [ Optional ` type_equivalence_hints ` compilation parameter] ( #optional-type_equivalence_hints-parameter )
68
+ * [ SchemaGraph] ( #schemagraph )
68
69
* [ FAQ] ( #faq )
69
70
* [ License] ( #license )
70
71
@@ -1512,6 +1513,46 @@ would enable the use of a `@fold` on the `adjacent_animal` vertex field of `Foo`
1512
1513
}
1513
1514
```
1514
1515
1516
+ ### SchemaGraph
1517
+ The ` SchemaGraph ` is a utility class that encodes a database schema and allows for better schema
1518
+ introspection than the GraphQL schema. The ` SchemaGraph ` has three main advantages:
1519
+ 1 . It's able to store and expose a schema's index information. The interface for accessing index
1520
+ information is provisional though and might change in the near future.
1521
+ 2 . Its classes are allowed to inherit from non-abstract classes.
1522
+ 3 . It exposes many utility functions, such as ` get_subclass_set ` , that make it easier to explore
1523
+ the schema.
1524
+
1525
+ We plan to add ` SchemaGraph ` generation from SQLAlchemy metadata and can currently generate a
1526
+ ` SchemaGraph ` from OrientDB schema metadata as exemplified by the following mock example.
1527
+
1528
+ ``` python
1529
+ from graphql_compiler.schema_generation.orientdb.schema_graph_builder import (
1530
+ get_orientdb_schema_graph
1531
+ )
1532
+ from graphql_compiler.schema_generation.orientdb.utils import (
1533
+ ORIENTDB_INDEX_RECORDS_QUERY , ORIENTDB_SCHEMA_RECORDS_QUERY
1534
+ )
1535
+
1536
+ # Get schema metadata from hypothetical Animals database.
1537
+ client = your_function_that_returns_an_orientdb_client()
1538
+ schema_records = client.command(ORIENTDB_SCHEMA_RECORDS_QUERY )
1539
+ schema_data = [record.oRecordData for record in schema_records]
1540
+
1541
+ # Get index data.
1542
+ index_records = client.command(ORIENTDB_INDEX_RECORDS_QUERY )
1543
+ index_query_data = [record.oRecordData for record in index_records]
1544
+
1545
+ schema_graph = get_orientdb_schema_graph(schema_data, index_query_data)
1546
+
1547
+ print (schema_graph.get_subclass_set(' Animal' ))
1548
+ # {'Animal', 'Dog'}
1549
+
1550
+ print (schema_graph.get_unique_indexes_for_class(' Animal' ))
1551
+ # [IndexDefinition(name='uuid', 'base_classname'='Animal', fields={'uuid'}, unique=True, ordered=False, ignore_nulls=False)]
1552
+ ```
1553
+
1554
+ For more information about the ` SchemaGraph ` , please see the class documentation.
1555
+
1515
1556
## FAQ
1516
1557
1517
1558
** Q: Do you really use GraphQL, or do you just use GraphQL-like syntax?**
0 commit comments