Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A function to generate a type whose parameters are non null #506

Open
akhildevelops opened this issue Jan 7, 2025 · 0 comments
Open

A function to generate a type whose parameters are non null #506

akhildevelops opened this issue Jan 7, 2025 · 0 comments

Comments

@akhildevelops
Copy link

akhildevelops commented Jan 7, 2025

I have below graphql schema (it's subset of my schema file) and all the fields for PodFindAndDeployOnDemandInput input type aren't mandatory except for the countryCode

# Input Type
input PodFindAndDeployOnDemandInput{
    aiApiId:String	
    cloudType:CloudTypeEnum	
    containerDiskInGb:Int	
    countryCode:String!
    deployCost:Float	
    dockerArgs:String	
    env:[EnvironmentVariableInput]	
    gpuCount:Int	
    gpuTypeId:String	
    gpuTypeIdList:[String]	
    imageName:String	
    minDisk:Int	
    minDownload:Int	
    minMemoryInGb:Int	
    minUpload:Int	
    minVcpuCount:Int	
    name:String	
    networkVolumeId:String	
    port:Port	
    ports:String	
    startJupyter:Boolean	
    startSsh:Boolean	
    stopAfter:DateTime	
    supportPublicIp:Boolean	
    templateId:String	
    terminateAfter:DateTime	
    volumeInGb:Int	
    volumeKey:String	
    volumeMountPath:String	
    dataCenterId:String	
    savingsPlan:SavingsPlanInput	
    cudaVersion:String	
    allowedCudaVersions:[String]	
    instanceIds:[String]	
    computeType:ComputeType
}

# Mutation
type Mutation{
    podFindAndDeployOnDemand(input:PodFindAndDeployOnDemandInput!): Pod
}

#Output type of above mutation
type Pod{
    lowestBidPriceToResume: Float
    aiApiId: String
    apiKey: String
    consumerUserId: String	
    containerDiskInGb: Int
    containerRegistryAuthId: String
    costMultiplier: Float
    costPerHr: Float!
    createdAt: DateTime
    adjustedCostPerHr: Float!	
    desiredStatus: PodStatus!
    dockerArgs: String
    dockerId: String
    env: [String]
    gpuCount: Int!
    gpuPowerLimitPercent: Int!
    gpus: [Gpu]!
    id: String!
    imageName: String!
    lastStatusChange: String
    locked: Boolean
    machineId: String!
    memoryInGb: Float!	
    name: String!
    podType: PodType
    port: Port
    ports: String
    registry: PodRegistry
    templateId: String
    uptimeSeconds: Int
    vcpuCount: Float!
    version: Int
    volumeEncrypted: Boolean!
    volumeInGb: Float
    volumeKey: String
    volumeMountPath: String
    lastStartedAt: DateTime
    cpuFlavorId: String
    machineType: String
    slsVersion: Int	
    networkVolumeId: String	
    cpuFlavor: CpuFlavor	
    runtime: PodRuntime	
    machine: PodMachineInfo	
    latestTelemetry: PodTelemetry	
    endpoint: Endpoint	
    networkVolume: NetworkVolume	
    savingsPlans: [SavingsPlan]	
}

The equivalent rust generated code for input type is:

pub struct PodFindAndDeployOnDemandInput {
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "aiApiId")]
            pub ai_api_id: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "cloudType")]
            pub cloud_type: Option<CloudTypeEnum>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "containerDiskInGb")]
            pub container_disk_in_gb: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "countryCode")]
            pub country_code: String,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "deployCost")]
            pub deploy_cost: Option<Float>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "dockerArgs")]
            pub docker_args: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            pub env: Option<Vec<Option<EnvironmentVariableInput>>>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "gpuCount")]
            pub gpu_count: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "gpuTypeId")]
            pub gpu_type_id: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "gpuTypeIdList")]
            pub gpu_type_id_list: Option<Vec<Option<String>>>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "imageName")]
            pub image_name: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "minDisk")]
            pub min_disk: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "minDownload")]
            pub min_download: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "minMemoryInGb")]
            pub min_memory_in_gb: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "minUpload")]
            pub min_upload: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "minVcpuCount")]
            pub min_vcpu_count: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            pub name: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "networkVolumeId")]
            pub network_volume_id: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            pub port: Option<Port>,
            #[serde(skip_serializing_if = "Option::is_none")]
            pub ports: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "startJupyter")]
            pub start_jupyter: Option<Boolean>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "startSsh")]
            pub start_ssh: Option<Boolean>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "stopAfter")]
            pub stop_after: Option<DateTime>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "supportPublicIp")]
            pub support_public_ip: Option<Boolean>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "templateId")]
            pub template_id: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "terminateAfter")]
            pub terminate_after: Option<DateTime>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "volumeInGb")]
            pub volume_in_gb: Option<Int>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "volumeKey")]
            pub volume_key: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "volumeMountPath")]
            pub volume_mount_path: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "dataCenterId")]
            pub data_center_id: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "savingsPlan")]
            pub savings_plan: Option<SavingsPlanInput>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "cudaVersion")]
            pub cuda_version: Option<String>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "allowedCudaVersions")]
            pub allowed_cuda_versions: Option<Vec<Option<String>>>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "instanceIds")]
            pub instance_ids: Option<Vec<Option<String>>>,
            #[serde(skip_serializing_if = "Option::is_none")]
            #[serde(rename = "computeType")]
            pub compute_type: Option<ComputeType>,
        }

Creating PodFindAndDeployOnDemandInput is verbose if the all fields default to None and the only required field is countryCode

expecting a function to generate PodFindAndDeployOnDemandInput type by taking non null as argument i.e, countryCode

fn gen_PodFindAndDeployOnDemandInput(countryCode:String)->PodFindAndDeployOnDemandInput{
           PodFindAndDeployOnDemandInput{
                                  countryCode,
                                  ai_api_id: None,
                                  cloud_type: None,
                                   ....
                                   ....          
           }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant