Resolver#initialize argument cache misses arguments added by field extensions

Aperta
#5,572 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #5573 di @rmosolgo — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
ruby

Direzione di ricerca

Start with lib/graphql/schema/resolver.rb at the caching shown in the issue, then reproduce the FieldExtension example and inspect the resolver's argument lookup. Done means extension-added arguments appear in context.types.arguments(self.class) and context.types.argument(self.class, name), while existing resolution behavior remains intact.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

When a FieldExtension adds arguments to a mutation field via apply, those arguments are not included in the @arguments_by_keyword cache built in Resolver#initialize. This means context.types.argument(mutation_class, name) returns nil for extension-added arguments, even though they are valid schema arguments on the field.

The root cause is this caching in Resolver#initialize:

@arguments_by_keyword = {}
context.types.arguments(self.class).each do |arg|
  @arguments_by_keyword[arg.keyword] = arg
end

context.types.arguments(self.class) only returns arguments defined directly on the resolver class — not arguments added to the field by extensions.

Versions

graphql version: 2.5.15
rails (or other framework): Rails (version not specific to the bug)
other applicable versions: N/A

GraphQL schema

class ExtraInput < GraphQL::Schema::InputObject
  argument :value, String, required: false
end

class MyExtension < GraphQL::Schema::FieldExtension
  def apply
    field.argument(:extra, ExtraInput, required: false)
  end
end

class MyMutation < GraphQL::Schema::Mutation
  argument :input, String, required: false
  extension(MyExtension)

  field :result, String

  def resolve(input: nil, extra: nil)
    # extra is received correctly at resolve time,
    # but is not in @arguments_by_keyword
    { result: "ok" }
  end
end

class MutationRoot < GraphQL::Schema::Object
  field :my_mutation, mutation: MyMutation
end

class MySchema < GraphQL::Schema
  mutation MutationRoot
end

GraphQL query

mutation {
  myMutation(input: "test", extra: { value: "hello" }) {
    result
  }
}

Steps to reproduce

  1. Define a FieldExtension that adds an argument via field.argument(...) in apply
  2. Attach the extension to a mutation with extension(MyExtension)
  3. In any code that runs during resolution, call context.types.argument(MyMutation, "extra") — it returns nil
  4. Alternatively, inspect @arguments_by_keyword inside the resolver — :extra is missing

Expected behavior

context.types.arguments(self.class) (and by extension context.types.argument(self.class, name)) should include arguments added by field extensions, since those arguments are part of the field's actual schema signature and are accepted at query time.

Actual behavior

Extension-added arguments are missing from @arguments_by_keyword and from context.types.argument lookups against the resolver class. The arguments work correctly at resolve time (they're passed as keyword args), but any introspection or validation code that uses the types API to look up arguments on the mutation class can't find them.

Additional context

A workaround is to look up arguments via the schema field instead of the resolver class:

mutation_root = context.schema.mutation
mutation_field = context.types.field(mutation_root, "myMutation")
context.types.argument(mutation_field, "extra") # => returns the argument

This correctly finds extension-added arguments, but requires traversing the schema manually rather than using the resolver class directly.

Lingua principale
Ruby
Stelle
5.4k
Fork
1.4k
Merge medio
1g 8h
PR unite (30g)
74

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rmosolgo/graphql-ruby

Tutte le issue di rmosolgo/graphql-ruby

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.