Skip to content

Commit 615033b

Browse files
pmantica1bojanserafimov
authored andcommitted
Add a SchemaGraph section in the README.md (kensho-technologies#326)
* Add SchemaGraph documentation in the README.md file * Add SchemaGraph documentation in the README.md file * Nits * Nits * Nits * Nits * Fix heading sizes * Added SchemaGraph introduction * Simplify SchemaGraph section * Fix hyperlink to SchemaGraph section * Nits * Add index disclaimer * Nit
1 parent 3acc466 commit 615033b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ For a more detailed overview and getting started guide, please see
6565
* [Pretty-Printing GraphQL Queries](#pretty-printing-graphql-queries)
6666
* [Expanding `@optional` vertex fields](#expanding-optional-vertex-fields)
6767
* [Optional `type_equivalence_hints` compilation parameter](#optional-type_equivalence_hints-parameter)
68+
* [SchemaGraph](#schemagraph)
6869
* [FAQ](#faq)
6970
* [License](#license)
7071

@@ -1512,6 +1513,46 @@ would enable the use of a `@fold` on the `adjacent_animal` vertex field of `Foo`
15121513
}
15131514
```
15141515

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+
15151556
## FAQ
15161557

15171558
**Q: Do you really use GraphQL, or do you just use GraphQL-like syntax?**

0 commit comments

Comments
 (0)