Skip to content

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

@wolflu05

Description

@wolflu05

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions