Skip to content

Last argument to field resolver is not checked when using the context class schema parser option #418

Open

Description

@vojtapol

To reproduce:

SchemaParserOptions options = SchemaParserOptions.newOptions()
    .contextClass(CustomContext.class)
    .build();
type Mutation {
  myMutation(
    id: ID!
    field: String!
    persist: Boolean!
  ): Entity
}

The following method field resolver is accepted:

public Entity myMutation(String id, String field, CustomContext context)

Although it is missing the persist parameter. This is because the CustomContext type is accepted as the last parameter.

Ideally this should throw just like in the case where DataFetchingEnvironment is used as the last parameter.

Not sure if it's possible.

Activity

  1. oryan-block commented on Oct 18, 2026

    @oryan-block
    Collaborator

    Same problem without contextClass. The DataFetchingEnvironment case isn't checked either when the parameter counts match. This builds without a warning:

    type Query {
        users(first: Int): UserConnection
    }
    fun users(env: DataFetchingEnvironment): Connection<User>

    The method has as many parameters as the field has arguments, so FieldResolverScanner#verifyMethodArguments accepts it and first gets mapped onto env. Every query of users then fails, with Parameter specified as non-null is null: ... parameter env when first is omitted, and Cannot construct instance of graphql.schema.DataFetchingEnvironment when it's sent.

    Found by the every-field check in #879 (DeprecatedDirectiveTest's fixtures had this).

    Since these schemas build today, I think the fix is a WARN at build that names the field and the parameter, then throwing in 15.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions