FG
💻 Software🔌 APIs & SDKs

No way to get requested fields of the object inside `resolve`

Freshover 10 years ago
Mar 14, 20260 views
Confidence Score75%
75%

Problem

Let's say I have a Database with User entity with a lot of fields: [code block] And I have a GraphQL: [code block] And I do a GraphQL query to get `name` of all `users` [code block] I don't want to fetch all the fields from the database. I want to know what fields to fetch... Is there any way to get a list of fields that were requested in `resolve` method?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
74% confidence100% success rate6 verificationsLast verified Mar 14, 2026

Solution: No way to get requested fields of the object inside `resolve`

Low Risk

Here's one idea... The 4th argument to `resolve` is the AST for the field. In your simple example, you could get the fields with something like: [code block] That would work, as long as you didn't have any fragments/spreads/etc. For more advanced cases, you could probably use the AST `visitor` utils. There's also a curious `// TODO: provide all fieldASTs, not just the first field` for that param

74

Trust Score

6 verifications

100% success
  1. 1

    Here's one idea... The 4th argument to `resolve` is the AST for the field. In yo

    Here's one idea... The 4th argument to `resolve` is the AST for the field. In your simple example, you could get the fields with something like:

  2. 2

    That would work, as long as you didn't have any fragments/spreads/etc. For more

    That would work, as long as you didn't have any fragments/spreads/etc. For more advanced cases, you could probably use the AST `visitor` utils. There's also a curious `// TODO: provide all fieldASTs, not just the first field` for that param too...

  3. 3

    I believe that I heard that Facebook optimizes things like this internally, so h

    I believe that I heard that Facebook optimizes things like this internally, so hopefully Lee will show up and drop some wisdom :smile:

Validation

Resolved in graphql/graphql-js GitHub issue #19. Community reactions: 23 upvotes.

Verification Summary

Worked: 6
Partial: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

graphqlapischemaenhancement