graphql-request icon indicating copy to clipboard operation
graphql-request copied to clipboard

How to @skip fields in graphql-request?

Open johannesmutter opened this issue 3 years ago • 1 comments

Hi everyone,

How do I use the directive skip to ignore a field by checking a Boolean variable?

See example below with @skip(if: $skipReleaseDate):

const query = gql`
  query getMovie($title: String!, $skipReleaseDate: Boolean!) {
    Movie(title: $title) {
      releaseDate @skip(if: $skipReleaseDate)   ##### Don’t query releaseDate via skip directive
      actors {
        name
      }
    }
  }
`

const variables = {
  title: 'Inception',
  skipReleaseDate: true
}

const data = await request(endpoint, query, variables)

(Docs by dgraph on skip & include for reference)

Is this something currently supported?

johannesmutter avatar Dec 30 '20 22:12 johannesmutter

@johannesmutter It works just fine for me.

Karl-EdwardFPJeanMehu avatar Jan 15 '21 13:01 Karl-EdwardFPJeanMehu

This is a GraphQL feature within he query string sent to server, nothing about this library's own code.

jasonkuhrt avatar Feb 03 '24 05:02 jasonkuhrt