opsmill / infrahub-sdk-python

Python SDK to interact with Infrahub
https://www.opsmill.com
Apache License 2.0
3 stars 2 forks source link

bug: Certain queries on nodes in a hierarchy don't work and results in an invalid query #148

Open ogenstad opened 3 days ago

ogenstad commented 3 days ago

Component

Python SDK

Infrahub SDK version

v1.0.1a0

Current Behavior

Certain queries on nodes in a hierarchy don't work and results in an invalid query

Expected Behavior

The SDK should create a valid query.

Steps to Reproduce

  1. Load this schema into Infrahub
---
version: "1.0"
generics:
  - name: Generic # Location
    namespace: Location
    description: "Generic hierarchical location"
    label: "Location"
    hierarchical: true
    icon: "mingcute:location-line"
    human_friendly_id: ["name__value"]
    include_in_menu: true
    attributes:
      - name: name
        kind: Text
        unique: true
        order_weight: 900
      - name: shortname
        kind: Text
        optional: false

nodes:
  # -------------------- Continent --------------------
  - name: Continent
    namespace: Location
    description: "A continent on planet earth."
    menu_placement: "LocationGeneric"
    icon: "jam:world"
    inherit_from:
      - "LocationGeneric"
    generate_profile: false
    default_filter: "name__value"
    order_by:
      - "name__value"
    display_labels:
      - "name__value"
    children: "LocationCountry"
    parent: ""

  # -------------------- Country --------------------
  - name: Country
    namespace: Location
    description: "A country within a continent."
    menu_placement: "LocationGeneric"
    icon: "gis:search-country"
    inherit_from:
      - "LocationGeneric"
    generate_profile: false
    default_filter: "name__value"
    order_by:
      - "name__value"
    display_labels:
      - "name__value"
    children: "LocationSite"
    parent: "LocationContinent"
    attributes:
      - name: computed_shortname
        kind: Text

  # -------------------- Site --------------------
  - name: Site
    namespace: Location
    description: "A site within a country."
    menu_placement: "LocationGeneric"
    icon: "ri:building-line"
    inherit_from:
      - "LocationGeneric"
    default_filter: "name__value"
    order_by:
      - "name__value"
    display_labels:
      - "name__value"
    children: ""
    parent: "LocationCountry"
    attributes:
      - name: computed_shortname
        kind: Text
  1. Start a Python shell and issue this code:
from infrahub_sdk import InfrahubClientSync

client = InfrahubClientSync()
nodes = client.all(kind="LocationSite", prefetch_relationships=True, populate_store=True)
  1. Observe the error
File ~/Code/opsmill/infrahub/python_sdk/infrahub_sdk/client.py:1538, in InfrahubClientSync.execute_graphql(self, query, variables, branch_name, at, timeout, raise_for_error, tracker)
   1535 response = decode_json(response=resp)
   1537 if "errors" in response:
-> 1538     raise GraphQLError(errors=response["errors"], query=query, variables=variables)
   1540 return response["data"]

GraphQLError: An error occurred while executing the GraphQL Query
query {
    LocationSite(limit: 50) {
        count
        edges {
            node {
                id
                hfid
                display_label
                __typename
                shortname {
                    value
                    is_default
                    is_from_profile
                    is_visible
                    is_protected
                    source {
                        id
                        display_label
                        __typename
                    }
                    owner {
                        id
                        display_label
                        __typename
                    }
                }
                computed_shortname {
                    value
                    is_default
                    is_from_profile
                    is_visible
                    is_protected
                    source {
                        id
                        display_label
                        __typename
                    }
                    owner {
                        id
                        display_label
                        __typename
                    }
                }
                name {
                    value
                    is_default
                    is_from_profile
                    is_visible
                    is_protected
                    source {
                        id
                        display_label
                        __typename
                    }
                    owner {
                        id
                        display_label
                        __typename
                    }
                }
                parent {
                    node {
                        id
                        hfid
                        display_label
                        __typename
                        computed_shortname {
                            value
                            is_default
                            is_from_profile
                            is_visible
                            is_protected
                            source {
                                id
                                display_label
                                __typename
                            }
                            owner {
                                id
                                display_label
                                __typename
                            }
                        }
                        name {
                            value
                            is_default
                            is_from_profile
                            is_visible
                            is_protected
                            source {
                                id
                                display_label
                                __typename
                            }
                            owner {
                                id
                                display_label
                                __typename
                            }
                        }
                        shortname {
                            value
                            is_default
                            is_from_profile
                            is_visible
                            is_protected
                            source {
                                id
                                display_label
                                __typename
                            }
                            owner {
                                id
                                display_label
                                __typename
                            }
                        }
                        parent {
                            node {
                                id
                                hfid
                                display_label
                                __typename
                            }
                            properties {
                                is_visible
                                is_protected
                                source {
                                    id
                                    display_label
                                    __typename
                                }
                                owner {
                                    id
                                    display_label
                                    __typename
                                }
                            }
                        }
                    }
                    properties {
                        is_visible
                        is_protected
                        source {
                            id
                            display_label
                            __typename
                        }
                        owner {
                            id
                            display_label
                            __typename
                        }
                    }
                }
            }
        }
    }
}
, [{'message': "Cannot query field 'computed_shortname' on type 'LocationGeneric'. Did you mean to use an inline fragment on 'LocationCountry' or 'LocationSite'?", 'locations': [{'line': 68, 'column': 25}]}]

Additional Information

No response