New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix and test schema generation interface #220
Changes from 8 commits
bddd3e1
7dd15de
175d8af
a4cf4d4
dca87f9
842cc7b
a87337c
022a0f7
0c68abb
be54631
d90e791
94483dc
3a037b1
dfadb1f
05f3098
4ff3b15
2db75e2
c39de5b
99470ee
cfd45c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# snapshottest: v1 - https://goo.gl/zC4yUc | ||
from __future__ import unicode_literals | ||
|
||
from snapshottest import Snapshot | ||
|
||
|
||
snapshots = Snapshot() | ||
|
||
snapshots['GraphQLSchemaGenerationTests::test_graphql_schema_generation_from_schema_data_api 1'] = '''schema { | ||
query: RootSchemaQuery | ||
} | ||
|
||
directive @filter(op_name: String!, value: [String!]!) on FIELD | INLINE_FRAGMENT | ||
|
||
directive @tag(tag_name: String!) on FIELD | ||
|
||
directive @output(out_name: String!) on FIELD | ||
|
||
directive @output_source on FIELD | ||
|
||
directive @optional on FIELD | ||
|
||
directive @recurse(depth: Int!) on FIELD | ||
|
||
directive @fold on FIELD | ||
|
||
scalar Decimal | ||
|
||
interface Entity { | ||
_x_count: Int | ||
name: String | ||
} | ||
|
||
type Location implements Entity { | ||
_x_count: Int | ||
description: String | ||
in_Person_LivesIn: [Person] | ||
name: String | ||
} | ||
|
||
type Person implements Entity { | ||
_x_count: Int | ||
alias: [String] | ||
name: String | ||
net_worth: Decimal | ||
out_Person_LivesIn: [Location] | ||
} | ||
|
||
type RootSchemaQuery { | ||
Entity: Entity | ||
Location: Location | ||
Person: Person | ||
} | ||
''' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright 2018-present Kensho Technologies, LLC. | ||
from graphql.utils.schema_printer import print_schema | ||
from snapshottest import TestCase | ||
|
||
from ... import get_graphql_schema_from_orientdb_schema_data | ||
from ...schema_generation.schema_properties import ( | ||
ORIENTDB_BASE_EDGE_CLASS_NAME, ORIENTDB_BASE_VERTEX_CLASS_NAME, PROPERTY_TYPE_DECIMAL_ID, | ||
PROPERTY_TYPE_EMBEDDED_SET_ID, PROPERTY_TYPE_LINK_ID, PROPERTY_TYPE_STRING_ID | ||
) | ||
|
||
|
||
class GraphQLSchemaGenerationTests(TestCase): | ||
|
||
def test_graphql_schema_generation_from_schema_data_api(self): | ||
orientdb_schema_data = [ | ||
{ | ||
'name': ORIENTDB_BASE_VERTEX_CLASS_NAME, | ||
'abstract': False, | ||
'properties': [] | ||
}, | ||
{ | ||
'name': ORIENTDB_BASE_EDGE_CLASS_NAME, | ||
'abstract': False, | ||
'properties': [] | ||
}, | ||
{ | ||
'name': 'Entity', | ||
'abstract': True, | ||
'superClasses': [ORIENTDB_BASE_VERTEX_CLASS_NAME], | ||
'properties': [ | ||
{ | ||
'name': 'name', | ||
'type': PROPERTY_TYPE_STRING_ID, | ||
} | ||
] | ||
}, | ||
{ | ||
'name': 'Person', | ||
'abstract': False, | ||
'superClasses': ['Entity'], | ||
'properties': [ | ||
{ | ||
'name': 'net_worth', | ||
'type': PROPERTY_TYPE_DECIMAL_ID, | ||
}, | ||
{ | ||
'name': 'alias', | ||
'type': PROPERTY_TYPE_EMBEDDED_SET_ID, | ||
'linkedType': PROPERTY_TYPE_STRING_ID, | ||
'defaultValue': '{}' | ||
} | ||
], | ||
}, | ||
{ | ||
'name': 'Person_LivesIn', | ||
'abstract': False, | ||
'customFields': { | ||
'human_name_in': 'Person', | ||
'human_name_out': 'Location where person lives', | ||
}, | ||
'properties': [ | ||
{ | ||
'name': 'in', | ||
'type': PROPERTY_TYPE_LINK_ID, | ||
'linkedClass': 'Location', | ||
}, | ||
{ | ||
'name': 'out', | ||
'type': PROPERTY_TYPE_LINK_ID, | ||
'linkedClass': 'Person', | ||
} | ||
], | ||
'superClass': ORIENTDB_BASE_EDGE_CLASS_NAME | ||
}, | ||
{ | ||
'name': 'Location', | ||
'abstract': False, | ||
'superClasses': ['Entity'], | ||
'properties': [ | ||
{ | ||
'name': 'description', | ||
'type': PROPERTY_TYPE_STRING_ID, | ||
} | ||
] | ||
}, | ||
] | ||
schema, _ = get_graphql_schema_from_orientdb_schema_data(orientdb_schema_data) | ||
self.assertMatchSnapshot(print_schema(schema)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need this to be a snapshot test here? This feels like a unit test to me since we have well-defined input and output, and a single function call being tested. Invoking all the snapshot testing machinery feels like overkill for this use case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea because every time I've made a small change to the way we generate the schema, I've had to print it and then copy paste it into test_helpers. If I introduce this test as an unit test, every time we change the schema we now have to change two things. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ CREATE INDEX Animal.net_worth NOTUNIQUE | |
CREATE CLASS Animal_ParentOf EXTENDS E | ||
CREATE PROPERTY Animal_ParentOf.in LINK Animal | ||
CREATE PROPERTY Animal_ParentOf.out LINK Animal | ||
ALTER CLASS Animal_ParentOf CUSTOM human_name_in="Parent" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test on the generated schema graph that these properties exist and have their expected values? |
||
ALTER CLASS Animal_ParentOf CUSTOM human_name_out="Child" | ||
CREATE INDEX Animal_ParentOf ON Animal_ParentOf (in, out) UNIQUE_HASH_INDEX | ||
|
||
CREATE CLASS Animal_FedAt EXTENDS E | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the visual indentation is off by one space (compare
string
vsdefault
)