Skip to content

GraphQL schema build crashes on MDR names with invalid GraphQL characters (e.g. hyphen) #1011

Description

@bjagg

Describe the bug

graphql-org1 (dev) is crash-looping. On startup it loads the OpenAPI schema from MDR (data model 17, 200 OK) and then fails building the Strawberry/GraphQL schema:

generate_graphql_schema -> strawberry Schema(...) -> GraphQLSchema(...)
graphql.error.graphql_error.GraphQLError:
    Names must only contain [_a-zA-Z0-9] but 'iSO639-2LangCode' does not.
ERROR  Application startup failed. Exiting.   (container exit code 3)

ECS then restarts it → it crashes again → running 0 / desired 1 → the ALB returns 503 for every request to https://graphql-org1.dev.lif.unicon.net.

Root cause

components/lif/openapi_to_graphql/type_factory.py exposes the raw MDR schema name as the GraphQL name — e.g. strawberry.field(name=field_name, …) (line ~318, and ~8 other field/type/enum sites). GraphQL identifiers must match /[_A-Za-z][_0-9A-Za-z]*/. An MDR attribute named iSO639-2LangCode (hyphen) is therefore an illegal GraphQL name, and a single bad name fails the entire schema build — taking the whole service down. safe_identifier is applied to the Python attribute name but not to the exposed GraphQL name.

So any MDR element whose name contains an invalid character (or leads with a digit) can hard-down GraphQL. (Likely the concrete instance behind the spike #369; also a naming-convention violation per docs/specs/data-model-rules.md — no hyphens.)

Fix

Harden openapi_to_graphql so an invalid MDR name can never crash schema build: sanitize names to valid GraphQL identifiers at every GraphQL-name boundary (field names, object/array sub-type names, enum type names), with a case-preserving sanitizer (distinct from safe_identifier, which snake-cases for Python). Add regression coverage.

Immediate workaround (data): rename the offending MDR element iSO639-2LangCode → a GraphQL-safe name (e.g. iso6392LangCode) in data model 17; graphql-org1 recovers on next restart.

Context: surfaced while verifying the LDE dev deploy (#998). Separate from PR #1010 (LDE client timeouts).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions