本文整理汇总了Java中graphql.schema.DataFetchingEnvironment.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java DataFetchingEnvironment.getSource方法的具体用法?Java DataFetchingEnvironment.getSource怎么用?Java DataFetchingEnvironment.getSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.schema.DataFetchingEnvironment
的用法示例。
在下文中一共展示了DataFetchingEnvironment.getSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
Object source = environment.getSource();
if (source == null) {
return null;
}
if (source instanceof Map) {
return ((Map<?, ?>) source).get(name);
}
GraphQLType type = environment.getFieldType();
if (type instanceof GraphQLNonNull) {
type = ((GraphQLNonNull) type).getWrappedType();
}
if (type instanceof GraphQLList) {
return call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name) + "List");
}
if (type instanceof GraphQLEnumType) {
Object o = call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name));
if (o != null) {
return o.toString();
}
}
return call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name));
}
示例2: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Batched
@Override
public Object get(DataFetchingEnvironment env) {
List<Object> unresolved = new ArrayList<>();
Object result;
int depth = listDepth;
if ( env.getSource() instanceof List ) { // batched.
result = getBatched(env);
if ( null != resolver ) addUnresolved(unresolved, result, ++depth);
} else {
result = getUnbatched(env);
if ( null != resolver ) addUnresolved(unresolved, result, depth);
}
if ( null == resolver ) return result;
return replaceResolved(result, resolver.resolve(unresolved).iterator(), depth);
}
示例3: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
Object targetMethodResult = null;
try {
beforeInvocation(environment);
Object[] bindByClassValues = collectBindByClassValues(environment);
Object[] inputArguments = getMethodParametersBinder().bindParameters(environment.getArguments(), bindByClassValues);
if (isAllNulls(inputArguments) && canApplySourceObject(environment)) {
inputArguments = new Object[]{environment.getSource()};
}
targetMethodResult = getTargetMethod().invoke(getTargetObject(), inputArguments);
targetMethodResult = afterInvocation(environment, targetMethodResult);
} catch (Exception e) {
String msg = "Exception while calling data fetcher [" + getTargetMethod().getName() + "]";
if (LOGGER.isErrorEnabled())
LOGGER.error(msg, e);
throw new DataFetcherRuntimeException(msg, e);
}
return targetMethodResult;
}
示例4: parentNodeFetcher
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
/**
* Fetcher for the parent node reference of a node.
*
* @param env
* @return
*/
public Object parentNodeFetcher(DataFetchingEnvironment env) {
NodeContent content = env.getSource();
if (content == null) {
return null;
}
GraphQLContext gc = env.getContext();
String uuid = gc.getRelease().getUuid();
Node parentNode = content.getNode().getParentNode(uuid);
// The project root node can have no parent. Lets check this and exit early.
if (parentNode == null) {
return null;
}
gc.requiresPerm(parentNode, READ_PERM, READ_PUBLISHED_PERM);
return handleLanguageFallback(gc, parentNode, content);
}
示例5: nodeLanguageFetcher
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public Object nodeLanguageFetcher(DataFetchingEnvironment env) {
NodeContent content = env.getSource();
if (content == null) {
return null;
}
List<String> languageTags = getLanguageArgument(env);
GraphQLContext gc = env.getContext();
Node node = content.getNode();
Release release = gc.getRelease();
NodeGraphFieldContainer container = node.findVersion(gc, languageTags);
// There might not be a container for the selected language (incl. fallback language)
if (container == null) {
return null;
}
// Check whether the user is allowed to read the published container
boolean isPublished = container.isPublished(release.getUuid());
if (isPublished) {
gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM);
} else {
// Otherwise the container is a draft and we need to use the regular read permission
gc.requiresPerm(node, READ_PERM);
}
return new NodeContent(node, container);
}
示例6: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
List<ErrorCount> errorCounts = new ArrayList();
Map<String, Object> parentFeedMap = environment.getSource();
String namespace = (String) parentFeedMap.get("namespace");
Connection connection = null;
try {
connection = GTFSGraphQL.getConnection();
Statement statement = connection.createStatement();
String sql = String.format("select error_type, count(*) from %s.errors group by error_type", namespace);
LOG.info("SQL: {}", sql);
if (statement.execute(sql)) {
ResultSet resultSet = statement.getResultSet();
while (resultSet.next()) {
errorCounts.add(new ErrorCount(NewGTFSErrorType.valueOf(resultSet.getString(1)), resultSet.getInt(2)));
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
DbUtils.closeQuietly(connection);
}
return errorCounts;
}
示例7: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Integer get(DataFetchingEnvironment environment) {
Map<String, Object> parentFeedMap = environment.getSource();
String namespace = (String) parentFeedMap.get("namespace");
Connection connection = null;
try {
connection = GTFSGraphQL.getConnection();
Statement statement = connection.createStatement();
String sql = String.format("select count(*) from %s.%s", namespace, tableName);
if (statement.execute(sql)) {
ResultSet resultSet = statement.getResultSet();
resultSet.next();
return resultSet.getInt(1);
}
} catch (SQLException e) {
// In case the table doesn't exist in this feed, just return zero and don't print noise to the log.
// Unfortunately JDBC doesn't seem to define reliable error codes.
if (! JDBCTableReader.SQL_STATE_UNDEFINED_TABLE.equals(e.getSQLState())) {
e.printStackTrace();
}
} finally {
DbUtils.closeQuietly(connection);
}
return 0;
}
示例8: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
if (environment.getSource() instanceof SubjectReference) {
SubjectReference source = environment.getSource();
if (isList) {
return inner.getList(
source,
argumentsHelper.getPaginationArguments(environment),
((DatabaseResult) environment.getSource()).getDataSet()
);
} else {
return inner.getItem(source, ((DatabaseResult) environment.getSource()).getDataSet());
}
} else {
throw new IllegalStateException("Source is not a SubjectReference");
}
}
示例9: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public UserDto get(DataFetchingEnvironment environment) {
log.info("getSource {}", (Object) environment.getSource());
OrderDto order = environment.getSource();
UserDto user = userAdaptor.getUser(order.getUserId());
return user;
}
示例10: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public ProductDto get(DataFetchingEnvironment environment) {
log.info("getSource {}", (Object)environment.getSource());
OrderItemDto orderItemDto = environment.getSource();
ProductDto product = productAdaptor.getProduct(orderItemDto.getProductId());
return product;
}
示例11: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
SchemaInstance schemaInstance = environment.getSource();
GraphQLInstanceRequestContext context = environment.getContext();
return SchemaInstanceReferencedBy.fromSchemaInstances(
instanceOutputTypeService.findRefereeSchemaInstances(context.getSchemaInstanceKey(),
context.getSchemaKey(), schemaInstance.getId()));
}
示例12: FetchParams
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public FetchParams(DataFetchingEnvironment environment, HGQLSchema hgqlschema) {
subjectResource = environment.getSource();
String predicate = ((Field) environment.getFields().toArray()[0]).getName();
predicateURI = hgqlschema.getFields().get(predicate).getId();
client = environment.getContext();
if (!environment.getParentType().getName().equals("Query")) {
String targetName = hgqlschema.getTypes().get(environment.getParentType().getName()).getField(predicate).getTargetName();
if (hgqlschema.getTypes().containsKey(targetName) && hgqlschema.getTypes().get(targetName).getId()!=null) {
targetURI=hgqlschema.getTypes().get(targetName).getId();
}
}
}
示例13: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
Object result = super.get(environment);
if (result == null) {
Object source = environment.getSource();
if (source == null) return null;
result = getPropertyViaMethod(source, propertyName);
}
result = postProcess(result, environment);
if (result instanceof Set) {
// cast all set to list
result = new ArrayList<>((Set<?>) result);
}
return result;
}
示例14: ResolutionEnvironment
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public ResolutionEnvironment(DataFetchingEnvironment env, ValueMapper valueMapper, GlobalEnvironment globalEnvironment) {
this.context = env.getSource();
this.rootContext = env.getContext();
this.valueMapper = valueMapper;
this.globalEnvironment = globalEnvironment;
this.fields = env.getFields();
this.fieldType = env.getFieldType();
this.parentType = env.getParentType();
this.graphQLSchema = env.getGraphQLSchema();
this.dataFetchingEnvironment = env;
}
示例15: get
import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public Object get(DataFetchingEnvironment env) {
Object source = ( null != impl ) ? impl : env.getSource();
if (source == null) return null;
if (source instanceof ResolveDataFetchingEnvironment) {
source = ((ResolveDataFetchingEnvironment)source).resolve(env);
}
return getMethodViaGetter(source, env.getFieldType(), getFieldType(env.getParentType()), env.getArguments());
}