opsmill / infrahub-sdk-python

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

feature: support enums in the SDK #18

Open ajtmccarty opened 10 months ago

ajtmccarty commented 10 months ago

Component

Python SDK

Describe the Feature Request

Follows opsmill/infrahub#918

The GraphQL API can now support enums based on our schema correctly. The Python SDK will need some changes to how it generates mutations for an attribute using an enum behind the scenes.

Describe the Use Case

For an example, let's use the CoreAccount.role attribute, which uses this enum ["admin", "read-only", "read-write"]. The CoreAccountCreate mutation currently looks like this when creating an account with a particular role

mutation CreateAccount {
  CoreAccountCreate(
    data:{
      name: {value: "userperson"},
      password: {value: "infrahub"},
      role: {value: "read-only"}
    }
  ) {
    ok
    object {
      role { value }
    }
  }  
}

With correct enum support in the GraphQL API, "read_only" becomes READ_ONLY

mutation CreateAccount {
  CoreAccountCreate(
    data:{
      name: {value: "userperson"},
      password: {value: "infrahub"},
      role: {value: READ_ONLY}
    }
  ) {
    ok
    object {
      role { value }
    }
  }  
}

Additional Information

you can turn enum support in the GraphQL API on or off using the environment variable INFRAHUB_EXPERIMENTAL_GRAPHQL_ENUMS=true/false