Skip to content

The way BatchLoaderHandlerMethod resolve argument #297

Closed
@dugenkui03

Description

@dugenkui03

In #232 , I suggested that @BatchMapping should support @Argument, because user will define arguments on field, no matter whether the field is fetched by DataLoader or 'n+1' way. Furthermore, user will always want to get information about field, such as field definition or directives info.

Hence, I think BatchLoaderHandlerMethod should support custom argument resolve strategy which resolving method parameters into argument values, like #295 . BatchMappingDataFetcher should use dataLoader.load(env.getSource(), env);(code like below), and argument resolve strategy and batch handler method will get all the information about the fetched field.

	static class BatchMappingDataFetcher implements DataFetcher<Object> {

                ......

		@Override
		public Object get(DataFetchingEnvironment env) {
			DataLoader<?, ?> dataLoader = env.getDataLoaderRegistry().getDataLoader(this.dataLoaderKey);
			if (dataLoader == null) {
				throw new IllegalStateException("No DataLoader for key '" + this.dataLoaderKey + "'");
			}
                         // pass DataFetchingEnvironment to DataLoader and other component
			return dataLoader.load(env.getSource(), env);
		}
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions