Skip to content

Commit 9638745

Browse files
authored
fix: Schema compatibility check (#398)
Adds a helper that rebuilds each schema (from prod + SDK) with the built-in spec directives (@deprecated, @Skip, @include, @specifiedBy) filtered out to avoid false positives when checking the schema. This time it just broke due to a change in the library, not in our schemas.
1 parent 1cd5ee6 commit 9638745

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

scripts/check_schema_compatibility.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from pathlib import Path
1212

1313
import requests
14-
from graphql import build_client_schema, build_schema, get_introspection_query
14+
from graphql import GraphQLSchema, build_client_schema, build_schema, get_introspection_query
15+
from graphql.type import specified_directives
1516
from graphql.utilities import find_breaking_changes
1617

1718
from openhexa.graphql import BUNDLED_SCHEMA_PATH
@@ -26,6 +27,19 @@
2627

2728
PRODUCTION_URL = "https://api.openhexa.org"
2829

30+
SPEC_DIRECTIVE_NAMES = {directive.name for directive in specified_directives}
31+
32+
33+
def strip_spec_directives(schema: GraphQLSchema) -> GraphQLSchema:
34+
"""Remove built-in spec directives (@deprecated, @skip, ...) so the diff only covers directives the API owns.
35+
36+
Built-in directives vary with the graphql-core version on each side of the comparison
37+
and produce false-positive breaking changes.
38+
"""
39+
kwargs = schema.to_kwargs()
40+
kwargs["directives"] = tuple(d for d in kwargs["directives"] if d.name not in SPEC_DIRECTIVE_NAMES)
41+
return GraphQLSchema(**kwargs)
42+
2943

3044
def fetch_server_schema(graphql_url: str):
3145
"""Fetch the live GraphQL schema from the server via introspection."""
@@ -46,7 +60,10 @@ def main():
4660
stored_schema = build_schema(BUNDLED_SCHEMA_PATH.read_text(), assume_valid_sdl=True)
4761
server_schema = fetch_server_schema(f"{PRODUCTION_URL}/graphql/")
4862

49-
breaking_changes = find_breaking_changes(stored_schema, server_schema)
63+
breaking_changes = find_breaking_changes(
64+
strip_spec_directives(stored_schema),
65+
strip_spec_directives(server_schema),
66+
)
5067
if breaking_changes:
5168
print(f"⚠️ {len(breaking_changes)} breaking change(s) detected:")
5269
for change in breaking_changes:

0 commit comments

Comments
 (0)