Polishing docs and removing unused code
This commit is contained in:
@@ -696,8 +696,9 @@ You can explicitly specify the argument name, for example `@Argument("bookInput"
|
||||
it not specified, it defaults to the method parameter name, but this requires the
|
||||
`-parameters` compiler flag with Java 8+ or debugging information from the compiler.
|
||||
|
||||
The "required" character of an `@Argument` or its default value is controlled at the schema
|
||||
level.
|
||||
The `@Argument` annotation does not have a "required" flag, nor the option to specify a
|
||||
default value. Both of these can be specified at the GraphQL schema level and are enforced
|
||||
by the GraphQL Engine.
|
||||
|
||||
You can use `@Argument` on a `Map<String, Object>` argument, to obtain all argument
|
||||
values. The name attribute on `@Argument` must not be set.
|
||||
|
||||
@@ -31,9 +31,9 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* and a parameter name is not specified, then the map parameter is populated
|
||||
* via {@link graphql.schema.DataFetchingEnvironment#getArguments()}.
|
||||
*
|
||||
* <p>This annotation does not specify whether the input argument is required
|
||||
* and if it should use a default value: this should be done at the schema
|
||||
* in order to be enforced by the GraphQL engine itself.
|
||||
* <p>Note that this annotation has neither a "required" flag nor the option to
|
||||
* specify a default value, both of which can be specified at the GraphQL schema
|
||||
* level and are enforced by the GraphQL Java engine.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Annotation for handler methods that batch load field values, given a list
|
||||
* Annotation for a handler method that batch loads field values, given a list
|
||||
* of source/parent values. For example:
|
||||
*
|
||||
* <pre class="code">
|
||||
@@ -34,9 +34,10 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>The annotated method is registered as a batch loading function and along
|
||||
* <p>The annotated method is registered as a batch loading function via
|
||||
* {@link org.springframework.graphql.execution.BatchLoaderRegistry}, and along
|
||||
* with it, a {@link graphql.schema.DataFetcher} for the field is registered
|
||||
* transparently that looks up the field through the registered
|
||||
* transparently that looks up the field value through the registered
|
||||
* {@code DataLoader}.
|
||||
*
|
||||
* <p>Effectively, a shortcut for:
|
||||
@@ -46,7 +47,7 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* public class BookController {
|
||||
*
|
||||
* public BookController(BatchLoaderRegistry registry) {
|
||||
* registry.forTypePair(Long.class, Author.class).registerBatchLoader((ids, env) -> ...);
|
||||
* registry.forTypePair(Long.class, Author.class).registerBatchLoader((ids, environment) -> ...);
|
||||
* }
|
||||
*
|
||||
* @SchemaMapping
|
||||
@@ -60,7 +61,7 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface BatchMapping {
|
||||
@@ -79,12 +80,12 @@ public @interface BatchMapping {
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* Customizes the name of the parent/container type for the GraphQL field.
|
||||
* <p>By default, if not specified, it is derived from the class name of the
|
||||
* List of source/parent values injected into the handler method.
|
||||
* <p>This value for this attribute can be initialized from a class-level
|
||||
* Customizes the name of the source/parent type for the GraphQL field.
|
||||
* <p>By default, if not specified, it is based on the simple class name of
|
||||
* the List of source/parent values injected into the handler method.
|
||||
* <p>The value for this attribute can also be inherited from a class-level
|
||||
* {@link SchemaMapping @SchemaMapping}. When used on both levels, the one
|
||||
* on the method level overrides the one at the class level.
|
||||
* here overrides the one at the class level.
|
||||
*/
|
||||
String typeName() default "";
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Target(value = {ElementType.TYPE, ElementType.METHOD})
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@SchemaMapping(typeName = "Query")
|
||||
|
||||
@@ -52,7 +52,7 @@ public @interface SchemaMapping {
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* Customizes the name of the parent/container type for the GraphQL field.
|
||||
* Customizes the name of the source/parent type for the GraphQL field.
|
||||
* <p>By default, if not specified, it is derived from the class name of a
|
||||
* {@link DataFetchingEnvironment#getSource() source} argument injected into
|
||||
* the handler method.
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.graphql.data.method.annotation;
|
||||
|
||||
/**
|
||||
* Common annotation value constants.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public interface ValueConstants {
|
||||
|
||||
/**
|
||||
* Constant defining a value for no default - as a replacement for {@code null} which
|
||||
* we cannot use in annotation attributes.
|
||||
* <p>This is an artificial, fixed value of 16 unicode characters, with its sole purpose
|
||||
* being to never match a user-declared value.
|
||||
* @see Argument#defaultValue()
|
||||
*/
|
||||
String DEFAULT_NONE = "\n\t\t\n\t\t\n\uE000\uE001\uE002\n\t\t\t\t\n";
|
||||
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.ValueConstants;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.DataBinder;
|
||||
|
||||
@@ -30,9 +30,10 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* An extension of {@link HandlerMethod} for annotated handler methods adapted
|
||||
* to a batch loader function with a list of values and {@link BatchLoaderEnvironment}
|
||||
* as their input.
|
||||
* An extension of {@link HandlerMethod} for annotated handler methods adapted to
|
||||
* {@link org.dataloader.BatchLoaderWithContext} or
|
||||
* {@link org.dataloader.MappedBatchLoaderWithContext} with the list of keys and
|
||||
* {@link BatchLoaderEnvironment} as their input.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
@@ -47,7 +48,7 @@ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport {
|
||||
|
||||
/**
|
||||
* Invoke the underlying batch loading method, resolving its arguments from
|
||||
* the given keys for batch loading and the {@link BatchLoaderEnvironment}.
|
||||
* the given keys and the {@link BatchLoaderEnvironment}.
|
||||
*
|
||||
* @param keys the batch loading keys
|
||||
* @param environment the environment available to batch loaders
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ContinuationHandlerMethodArgumentResolver implements HandlerMethodA
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Resolver that retrieves arguments of type {@link DataLoader} from the
|
||||
* {@link DataFetchingEnvironment}.
|
||||
* Resolver for a {@link DataLoader} obtained via
|
||||
* {@link DataFetchingEnvironment#getDataLoader(String)}.
|
||||
*
|
||||
* <p>The {@code DataLoader} is looked up by deriving the key using one of the following:
|
||||
* <p>The {@code DataLoader} key is based on one of the following:
|
||||
* <ol>
|
||||
* <li>The full name of the value type from the DataLoader generic types.</li>
|
||||
* <li>The method parameter name.</li>
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.graphql.data.method.annotation.support;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
|
||||
/**
|
||||
* Indicates that an input argument value in the method parameters of an
|
||||
* annotated DataFetcher method is not present.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class MissingArgumentException extends NestedRuntimeException {
|
||||
|
||||
private final String argumentName;
|
||||
|
||||
private final MethodParameter parameter;
|
||||
|
||||
|
||||
public MissingArgumentException(String argumentName, MethodParameter parameter) {
|
||||
super("");
|
||||
this.argumentName = argumentName;
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the expected name of the input argument.
|
||||
*/
|
||||
public String getArgumentName() {
|
||||
return this.argumentName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the method parameter bound to the input argument.
|
||||
*/
|
||||
public MethodParameter getParameter() {
|
||||
return this.parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "Required argument '" + this.argumentName +"' for method parameter type " +
|
||||
this.parameter.getNestedParameterType().getSimpleName() + " is not present";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Resolver for parent/container of a field, obtained via
|
||||
* Resolver for the source/parent of a field, obtained via
|
||||
* {@link DataFetchingEnvironment#getSource()}.
|
||||
*
|
||||
* <p>This resolver supports any non-simple value type, also excluding arrays
|
||||
|
||||
Reference in New Issue
Block a user