javascript graphql add fragments conditionally

This is precisely what an @include directive is good for:

query fetchEvent($id: ID!, $idType: EventIdType!, $isBn: Boolean!) {
    event(id: $id, idType: $idType) {
        ...EventFields
        ...BnFields @include(if: $isBn)
        content
    }
}

Then, add isBn: lang === 'bn' to the variables you are passing along with the query.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top