GraphQLSP icon indicating copy to clipboard operation
GraphQLSP copied to clipboard

RFC: Mark certain queries as used even no attributes are accessed

Open wolflu05 opened this issue 11 months ago • 8 comments

Summary

Checking for unused fields is a really powerful feature which definitely makes sense, but sometimes we don't want that, but instead want to pass the complete return type to an other function which e.g. stores this in local storage, but then we end up with an error that not all properties are accessed. E.g.:

const meQuery = graphql(`
  # we have an error here: Field(s) me.username are not used.
  query me {
    me {
      id
      username
      # ...
    }
  }
`);

const res = await client.query(meQuery, {});
localStorage.setItem("user", res.data!.me);

Proposed Solution

Add some type of @gql-tada-mark-used comment, which could be used like this:

const res = await client.query(meQuery, {});
localStorage.setItem("user", res.data!.me);  // @gql-tada-mark-used

This should then mark everything from the me query as used and there shouldn't be an error

Alternatively a simple @gql-tada-ignore-unused comment to the query definition may be sufficient too.

// @gql-tada-ignore-unused
const meQuery = graphql(`
  # we have an error here: Field(s) me.username are not used.
  query me {

Requirements

Have the ability to mark certain queries as fully used and ignore checking if all fields are actually accessed, because that will fail if the complete object is passed to any function.

wolflu05 avatar Mar 19 '24 16:03 wolflu05