当前位置: 首页>>代码示例>>Java>>正文


Java DataFetchingEnvironment.getArgument方法代码示例

本文整理汇总了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;
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:18,代码来源:PropertyDataFetcherWithArgs.java

示例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;
}
 
开发者ID:nfl,项目名称:glitr,代码行数:17,代码来源:RelayMutationDataFetcher.java

示例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;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:26,代码来源:AbstractTypeProvider.java

示例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());
    }
}
 
开发者ID:nwillc,项目名称:mysnipserver,代码行数:20,代码来源:CategoriesQuery.java

示例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");
  }
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:21,代码来源:DeleteDataSetDataFetcher.java

示例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();
}
 
开发者ID:ERS-HCL,项目名称:cart-cqrs-demo,代码行数:12,代码来源:CartDataFetcher.java

示例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;
}
 
开发者ID:nwillc,项目名称:ratpack-graphql,代码行数:12,代码来源:CompanyMutation.java

示例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;
}
 
开发者ID:nwillc,项目名称:ratpack-graphql,代码行数:12,代码来源:CompanyDelete.java

示例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;
    }
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:35,代码来源:ProductUpsertFetcher.java

示例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;
}
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:8,代码来源:UserFetcher.java

示例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;
}
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:9,代码来源:ProductDeleteFetcher.java

示例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;
}
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:8,代码来源:ProductFetcher.java

示例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;
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:34,代码来源:AnetResourceDataFetcher.java

示例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;
	}
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:14,代码来源:AnetResourceDataFetcher.java

示例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;
  }
 
开发者ID:deptofdefense,项目名称:anet,代码行数:16,代码来源:GraphQLUtils.java


注:本文中的graphql.schema.DataFetchingEnvironment.getArgument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。