本文整理汇总了Java中graphql.schema.DataFetchingEnvironment.getArgument方法的典型用法代码示例。如果您正苦于以下问题:Java DataFetchingEnvironment.getArgument方法的具体用法?Java DataFetchingEnvironment.getArgument怎么用?Java DataFetchingEnvironment.getArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.schema.DataFetchingEnvironment
的用法示例。
在下文中一共展示了DataFetchingEnvironment.getArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchParameters
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
private Object[] fetchParameters(Method m, DataFetchingEnvironment env) {
Parameter[] params = m.getParameters();
Object[] args = new Object[params.length];
for (int i = 0;i < args.length;i++) {
String argName = params[i].getName();
Object arg = null;
if (params[i].isAnnotationPresent(GraphQLParam.class)) {
argName = params[i].getAnnotation(GraphQLParam.class).value();
arg = env.getArgument(argName);
} else if (params[i].isAnnotationPresent(DefaultValue.class)) {
arg = params[i].getAnnotation(DefaultValue.class).value();
}
if (arg == null) { return null; }
args[i] = arg;
}
return args;
}
示例2: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object get(DataFetchingEnvironment env) {
Map<String, Object> inputMap = env.getArgument("input");
// map fields from input map to mutationInputClass
Object inputPayloadMtn = Glitr.getObjectMapper().convertValue(inputMap, mutationInputClass);
// apply some validation on inputPayloadMtn (should validation be in the mutationFunc instead?)
validate(inputPayloadMtn);
// mutate and return output
RelayMutationType mutationOutput = mutationFunc.call((RelayMutationType) inputPayloadMtn, env);
// set the client mutation id
mutationOutput.setClientMutationId((String) inputMap.get("clientMutationId"));
return mutationOutput;
}
示例3: handleUuidNameArgsNoPerm
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
/**
* Handle the UUID or name arguments and locate and return the vertex by the given functions.
*
* @param env
* @param uuidFetcher
* @param nameFetcher
* @return
*/
protected MeshCoreVertex<?, ?> handleUuidNameArgsNoPerm(DataFetchingEnvironment env, Function<String, MeshCoreVertex<?, ?>> uuidFetcher,
Function<String, MeshCoreVertex<?, ?>> nameFetcher) {
String uuid = env.getArgument("uuid");
MeshCoreVertex<?, ?> element = null;
if (uuid != null) {
element = uuidFetcher.apply(uuid);
}
String name = env.getArgument("name");
if (name != null) {
element = nameFetcher.apply(name);
}
if (element == null) {
return null;
}
return element;
}
示例4: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public List<Category> get(DataFetchingEnvironment environment) {
if (environment.containsArgument("match")) {
try {
final Object name = environment.getArgument("match");
final Query<Category> categoryQuery = new QueryBuilder<>(Category.class)
.contains("name", name.toString())
.build();
try (Stream<Category> categoryStream = getDao().find(categoryQuery)) {
return categoryStream.collect(Collectors.toList());
}
} catch (NoSuchFieldException e) {
throw new UncheckedSQLException("Cant build query", e);
}
}
try (Stream<Category> all = getDao().findAll()) {
return all.collect(Collectors.toList());
}
}
示例5: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
Optional<User> currentUser = ((RootData) environment.getRoot()).getCurrentUser();
if (!currentUser.isPresent()) {
throw new RuntimeException("User is not provided");
}
String dataSetId = environment.getArgument("dataSetId");
Tuple<String, String> ownerDataSetName = DataSetMetaData.splitCombinedId(dataSetId);
try {
dataSetRepository.removeDataSet(ownerDataSetName.getLeft(),ownerDataSetName.getRight(),currentUser.get());
return new RemovedDataSet(dataSetId);
} catch (IOException | NotEnoughPermissionsException e) {
LOG.error("Data set deletion exception", e);
throw new RuntimeException("Data set could not be deleted");
}
}
示例6: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Cart get(DataFetchingEnvironment env) {
final String id = env.getArgument("id");
if (id == null) {
throw new IllegalArgumentException("id is missing.");
}
CartAggregate cartAggregate = applicationContext.getBean(CartAggregate.class, id);
return cartAggregate.getCart();
}
示例7: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Company get(DataFetchingEnvironment environment) {
final Company company = new Company(environment.getArgument("name"), environment.getArgument("revenue"));
if (!getCompanies().containsKey(company.getName())) {
getCompanies().put(company.getName(), company);
} else {
getCompanies().get(company.getName()).setRevenue(company.getRevenue());
}
return company;
}
示例8: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Boolean get(DataFetchingEnvironment environment) {
final Object name = environment.getArgument("name");
final boolean containsKey = getCompanies().containsKey(name);
if (!containsKey) {
return Boolean.FALSE;
}
getCompanies().remove(name);
return Boolean.TRUE;
}
示例9: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public ProductDto get(DataFetchingEnvironment environment) {
log.info("getArguments {}", environment.getArguments());
Object inputObject = environment.getArgument("product");
ProductDto newProduct = ProductDto.builder().build();
// we map both 'product' as input type and separate primitive field arguments to this method for illustration
Function<Object, String> safeString = (o) -> o == null ? null : o.toString();
Function<Object, BigDecimal> safeBigDecimal = (o) -> (o instanceof Number) ? BigDecimal.valueOf((Double) o) : null;
Function<Object, List<String>> safeCategories = (o) -> (EMPTY_CATEGORIES.getClass().isInstance(o)) ? (List<String>) o : null;
if (inputObject == null) {
newProduct.setName(environment.getArgument("name"));
newProduct.setBrand(environment.getArgument("brand"));
newProduct.setDescription(environment.getArgument("description"));
newProduct.setPrice(safeBigDecimal.apply(environment.getArgument("price")));
newProduct.setCategory(environment.getArgument("category"));
} else {
// input type arguments not converted to java types
// InputProductQL inputProduct = (InputProductQL) inputObject;
// newProduct.setName(inputProduct.getName());
// newProduct.setBrand(inputProduct.getBrand());
// newProduct.setDescription(inputProduct.getDescription());
// newProduct.setPrice(BigDecimal.valueOf(inputProduct.getPrice()));
Map<String, Object> inputMap = (Map<String, Object>) inputObject;
newProduct.setName(safeString.apply(inputMap.get("name")));
newProduct.setBrand(safeString.apply(inputMap.get("brand")));
newProduct.setDescription(safeString.apply(inputMap.get("description")));
newProduct.setPrice(safeBigDecimal.apply(inputMap.get("price")));
newProduct.setCategory(safeCategories.apply(inputMap.get("category")));
}
log.info("saving new product={}", newProduct);
ProductDto savedProduct = productAdaptor.upsertProduct(newProduct);
log.info("saved new product={}", savedProduct);
return savedProduct;
}
示例10: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public UserDto get(DataFetchingEnvironment environment) {
log.info("getArguments {}", environment.getArguments());
String userId = environment.getArgument("userId");
UserDto user = userAdaptor.getUser(userId);
return user;
}
示例11: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public ProductDto get(DataFetchingEnvironment environment) {
log.info("getArguments {}", environment.getArguments());
String productId = environment.getArgument("productId");
ProductDto deletedProduct = productAdaptor.deleteProduct(productId);
log.info("deleted product={}", deletedProduct);
return deletedProduct;
}
示例12: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public ProductDto get(DataFetchingEnvironment environment) {
log.info("getArguments {}", environment.getArguments());
String productId = environment.getArgument("productId");
ProductDto product = productAdaptor.getProduct(productId);
return product;
}
示例13: fetchParameters
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
private List<Object> fetchParameters(Method method, DataFetchingEnvironment environment) {
List<Object> args = new LinkedList<Object>();
for (Parameter param : method.getParameters()) {
String argName = GraphQLUtils.getParamName(param);
Object arg = environment.getArgument(argName);
//Handle missing arguments but @DefaultValue annotations.
if (arg == null) {
if (param.isAnnotationPresent(DefaultValue.class)) {
arg = param.getAnnotation(DefaultValue.class).value();
} else if (param.isAnnotationPresent(Auth.class)) {
arg = ((Map<String,Object>)environment.getContext()).get("auth");
} else {
throw new WebApplicationException("Missing argument for function " + method.getName() + ", arg: " + argName);
}
}
//Verify the types are correct.
if (!param.getType().isAssignableFrom(arg.getClass())) {
//Try to convert it
try {
arg = mapper.convertValue(arg, param.getType());
} catch (IllegalArgumentException e) {
System.out.println("c: Arg is " + arg.getClass() + " and param is " + param.getType());
throw new WebApplicationException(String.format("Type mismatch on arg, wanted %s got %s on %s",
param.getType(), arg.getClass(), method.getName()));
}
}
args.add(arg);
}
return args;
}
示例14: findFetcher
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
private Method findFetcher(DataFetchingEnvironment environment) {
if (environment.getArgument("f") != null) {
String functionName = environment.getArgument("f");
Method fetcher = fetchers.get(functionName);
if (fetcher == null) {
throw new WebApplicationException("No such fetcher for name " + functionName);
}
return fetcher;
} else {
Method m = GraphQLUtils.findMethod(environment, validMethods);
return m;
}
}
示例15: getMethodScore
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
private static int getMethodScore(Method m, DataFetchingEnvironment environment) {
int score = 0;
for (Parameter p : m.getParameters()) {
String paramName = getParamName(p);
if (paramName != null && environment.getArgument(paramName) != null) {
score++;
} else if (p.isAnnotationPresent(Auth.class)) {
//no biggie.
} else if (!p.isAnnotationPresent(DefaultValue.class)) {
//We're missing args,
return -1;
}
}
return score;
}