Skip to content

Commit

Permalink
test(graphql): ensure type names do not leak graphene (#8345)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexledesma committed Jun 13, 2022
1 parent de10b7f commit c32caa0
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion js_modules/dagit/packages/core/src/app/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const PERMISSIONS_QUERY = gql`
}
}
fragment PermissionFragment on GraphenePermission {
fragment PermissionFragment on Permission {
permission
value
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js_modules/dagit/packages/core/src/graphql/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const TestProvider: React.FC<Props> = (props) => {
return Object.keys(PERMISSIONS_ALLOW_ALL).map((permission) => {
const override = permissionOverrides ? permissionOverrides[permission] : null;
const value = typeof override === 'boolean' ? override : true;
return {__typename: 'GraphenePermission', permission, value};
return {__typename: 'Permission', permission, value};
});
}, [permissionOverrides]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class GraphenePermission(graphene.ObjectType):
class Meta:
"Permission"
name = "Permission"

permission = graphene.NonNull(graphene.String)
value = graphene.NonNull(graphene.Boolean)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
from dagster_graphql.schema import types
import json

import pytest
from click.testing import CliRunner
from dagster_graphql.cli import ui

def test_schema_naming_invariant():
violations = []
for type_ in types():
if type_.__name__ != f"Graphene{type_._meta.name}": # pylint: disable=protected-access
violations.append(
(type_.__name__, f"Graphene{type_._meta.name}") # pylint: disable=protected-access
)
assert not violations, violations

@pytest.fixture(name="runner")
def runner_fixture():
yield CliRunner()


def test_schema_type_names_without_graphene(runner):
query = """
query GetSchemaTypeNames {
__schema {
types {
name
}
}
}
"""

result = runner.invoke(
ui,
["--empty-workspace", "--ephemeral-instance", "-t", query],
)
graphql_schema_types = json.loads(result.output)["data"]["__schema"]["types"]

violations = [
graphql_type["name"]
for graphql_type in graphql_schema_types
if "Graphene".casefold() in graphql_type["name"].casefold()
]
assert (
not violations
), f"'Graphene' cannot be included in the GraphQL type name. Violating types: {violations}."

0 comments on commit c32caa0

Please sign in to comment.