Skip to content

bug: SDK fails to deserialize NestedEdged GraphQL wrapper types in custom query responses #881

@minitriga

Description

@minitriga

Component

  • Python SDK

Infrahub SDK version

1.19.0

Current Behavior

When using a custom GraphQL query (e.g., in a transform) that includes a cardinality-one relationship like ip_prefix on IpamIPAddress, the SDK fails to deserialize the response with one of two errors:

  1. If __typename is included in the query under the relationship: Error: Unable to find the schema 'NestedEdgedBuiltinIPPrefix'
  2. If __typename is removed: ValueError: Unable to determine the type of the node, __typename not present in data

Additionally, the initialized property on the RelatedNode for such relationships always returns False, even when the data is present in the GraphQL response.

Expected Behavior

The SDK should correctly strip GraphQL wrapper type prefixes (NestedEdged, Edged, etc.) from __typename values when looking up schemas. The RelatedNode should be properly initialized with the data from the response.

Steps to Reproduce

  1. Define a GraphQL query that includes a cardinality-one relationship (e.g., ip_prefix on an IP address node)
  2. Include __typename in the relationship's response fields
  3. Execute the query via a transform or execute_graphql
  4. The SDK will fail with SchemaNotFoundError when trying to look up NestedEdgedBuiltinIPPrefix

Example query fragment:

ip_prefix {
  __typename
  node {
    ... on IpamIPPrefix {
      __typename
      id
    }
  }
}

Additional Information

The root cause is in InfrahubNode.from_graphql(). The method extracts __typename from the GraphQL response data:

node_kind = data.get("__typename") or data.get("node", {}).get("__typename", None)

For cardinality-one relationships, the GraphQL API returns a NestedEdged{Kind} wrapper type (e.g., NestedEdgedBuiltinIPPrefix). The outer __typename is truthy, so the inner node's actual __typename (e.g., BuiltinIPPrefix) is never reached. The schema lookup then fails because NestedEdgedBuiltinIPPrefix is a GraphQL wrapper type, not a registered schema kind.

The existing code in RelatedNodeBase.__init__ already strips the Related prefix for legacy non-paginated responses, but does not handle NestedEdged, Edged, NestedPaginated, or Paginated prefixes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions