Skip to content

Add field description inheritance from referenced types during introspection #1373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jwaldrip
Copy link

@jwaldrip jwaldrip commented Jul 2, 2025

Summary

This PR enhances GraphQL introspection by making fields inherit descriptions from their referenced types when no explicit description is provided. This improves API documentation by automatically propagating type descriptions to fields that reference those types.

Motivation

Currently, when a field has no description, introspection returns null even if the field references a well-documented type. This leads to incomplete API documentation where developers must manually duplicate type descriptions on every field that references that type.

Example

object :user do
  description "A user in the system"
  field :id, :id
  field :name, :string
end

object :post do
  field :author, :user  # Currently returns null description in introspection
end

With this change, the author field will automatically inherit the description "A user in the system" during introspection.

Implementation Details

  • Modified the __field introspection resolver to check if a field has no description and attempt to use the referenced type's description as a fallback
  • Properly handles wrapped types (non_null, list_of) by unwrapping them first before looking up the base type
  • Works with custom types, built-in scalars, interfaces, and all GraphQL type constructs

Testing

Added comprehensive test coverage in test/absinthe/introspection/field_description_inheritance_test.exs including:

  • Direct type references
  • Wrapped types (non_null, list_of)
  • Built-in scalar types
  • Interface types
  • Query fields
  • Nested type references

All existing tests continue to pass.

Documentation

Updated the field documentation in lib/absinthe/type/field.ex to explain the new behavior.

Breaking Changes

None. This is a backwards-compatible enhancement that only affects fields without explicit descriptions.

🤖 Generated with Claude Code

jwaldrip and others added 7 commits June 4, 2025 00:29
- Fix mix absinthe.schema.json to use schema's adapter for introspection
- Fix mix absinthe.schema.sdl to use schema's adapter for directive names
- Update SDL renderer to accept adapter parameter and use it for directive definitions
- Ensure directive names follow naming conventions (camelCase, etc.) in generated SDL

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
When a field has no description, it now inherits the description from its
referenced type during introspection. This provides better documentation
for GraphQL APIs by automatically propagating type descriptions to fields.

- Modified __field introspection resolver to fall back to type descriptions
- Handles wrapped types (non_null, list_of) correctly by unwrapping first
- Added comprehensive test coverage for various inheritance scenarios
- Updated field documentation to explain the new behavior

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@lloyd-pinrun
Copy link

Maybe I'm misunderstanding something, but would you actually want the field author to inherit the description of the type user? It seems like you'd want to add a new description for that field, e.g.:

object :post do
  @desc "The User who authored the post"
  field :author, :user
end

I'm unsure if this would be something folks would align with tbh, because if I abstain from adding a description for the field it's because it doesn't need one, and if I found that a description was inherited from the referenced type, it'd be unexpected behavior.

A potential alternative would be to include the ability to set field :author, :user, description: :inherit to allow users to explicitly decide if that field should inherit the type's description 🤷

Another thought is that the description of the "field" is separate from the description of the "object", e.g. the latter is a generalized description of the thing and the former is specific to its use-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants