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

GraphQL query fragments #25

Open
JacobMountain opened this issue Dec 28, 2020 · 1 comment
Open

GraphQL query fragments #25

JacobMountain opened this issue Dec 28, 2020 · 1 comment
Milestone

Comments

@JacobMountain
Copy link
Owner

JacobMountain commented Dec 28, 2020

Currently interface selections are inlined, this can lead to overly verbose/complex queries. fragments can be used to reduce the size of the query.
e.g.

query Hero($episode: Episode) { 
    hero(episode: $episode) { 
        id 
        name 
        friends { 
            id 
            name 
            ... on Human { 
                homePlanet 
                height 
                mass 
                __typename 
            } 
            ... on Droid { 
                primaryFunction 
                __typename 
            } 
            __typename 
        } 
        appearsIn
        ... on Human { 
            homePlanet 
            height 
            mass
            appearsIn 
            starships { 
                id 
                name 
                length 
                coordinates 
                __typename 
            } 
            __typename 
        } 
        ...Droid { 
            appearsIn 
            primaryFunction 
            __typename 
        } 
        __typename 
    } 
}

could be reduced to

query Hero($episode: Episode) { 
    hero(episode: $episode) { 
        id 
        name 
        friends { 
            id 
            name 
            ...Human
            ...Droid
            __typename 
        } 
        appearsIn
        ... Human
        ... on Droid
        __typename 
    } 
}
fragment Human on Human {
    homePlanet 
    height 
    mass 
    __typename 
}
fragment Droid on Droid {
    appearsIn 
    primaryFunction 
    __typename
}

Although at the final depth it wouldn't be able to use the fragment as it would add unnecessary depth

@JacobMountain JacobMountain added this to the 1.0.0 milestone Dec 28, 2020
@JacobMountain
Copy link
Owner Author

Need to figure out how we handle depth/max depth with fragments

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