Skip to content

Working with Fields with Variable Type #10

@planetmilesm

Description

@planetmilesm

Hello, I'm a graphQL newbie and I'm trying to see if I can use this library to replace the following query which relies on inline fragments to deal with a field which can vary in type (I am working with the Gitlab GraphQL API):

query {
    project(fullPath: "{project_path}") {
        vulnerabilities(severity: {severity}, reportType:{report_type}, state:{state}, first:100) {
        nodes{
            id
            title
            state
            severity
            description
            detectedAt
            reportType
            identifiers {
                externalType
                externalId
                name
                url
            }
            vulnerabilityPath
            location {
                ... on
                VulnerabilityLocationSast {
                    file
                    startLine
                    endLine
                },
                ... on
                VulnerabilityLocationContainerScanning {
                    image
                    operatingSystem
                    dependency {
                        package {
                            name
                        }
                        version
                    }
                }
                ... on
                VulnerabilityLocationSecretDetection {
                    file
                }
                ... on
                VulnerabilityLocationDependencyScanning {
                    file
                    dependency {
                        package {
                            name
                        }
                        version
                    }
                }
            }
        }
        pageInfo {
          hasNextPage
          endCursor
        }
        }
    }
    }

I have gotten up to here in writing the query using py2graphql:

project_vuln_query = client.query().project(
        fullPath=ProjectPath).vulnerabilities(
        severity=Severity, state=State).nodes.values(
        'id',
        'title',
        'state',
        'severity',
        'description',
        'detectedAt',
        'reportType',
        Query().identifiers.values(
            'externalType',
            'externalId',
            'name',
            'url'),
        'vulnerabilityPath',
        Query().location...?
        )

I can't find an example of how to do fragments in the documentation but the library looks powerful, I bet it can be done and I just can't figure it out. Any help is much appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions