Skip to content

Check for scalar arguments when building the schema instead of on every request #859

Open

Description

@oryan-block

For each argument, MethodFieldResolver either passes graphql-java's value straight to the resolver method or converts it to the parameter type with Jackson. It passes it through only if the value already fits the parameter type and the argument is a scalar other than ID (isConcreteScalarType). To know if the argument is a scalar, it looks the type up in environment.graphQLSchema on every call.

That's the only place we read the schema from the environment. It's done at runtime because the data fetchers are created in SchemaParser before the GraphQLSchema exists, and MethodFieldResolver doesn't know which type names are scalars. But we do know that at build time: SchemaClassScanner has every type definition by name (TypeClassMatcher already checks for ScalarTypeDefinition) and the built-in scalars are in GRAPHQL_SCALARS.

So FieldResolverScanner could pass the scalar names into MethodFieldResolver, and createDataFetcher() could decide once per argument. That means:

One difference: the runtime lookup also sees changes made to the schema after we build it, e.g. by a SchemaTransformer. I don't think that matters for whether a type is a scalar, but worth checking.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions