本文整理汇总了Java中graphql.schema.DataFetcher类的典型用法代码示例。如果您正苦于以下问题:Java DataFetcher类的具体用法?Java DataFetcher怎么用?Java DataFetcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataFetcher类属于graphql.schema包,在下文中一共展示了DataFetcher类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: listenableFutureInstrumentation
import graphql.schema.DataFetcher; //导入依赖的package包/类
/**
* Converts a {@link ListenableFuture} to a Java8 {@link java.util.concurrent.CompletableFuture}.
*
* <p>{@see CompletableFuture} is supported by the provided {@link
* graphql.execution.AsyncExecutionStrategy}.
*
* <p>Note: This should be installed before any other instrumentation.
*/
public static Instrumentation listenableFutureInstrumentation() {
return new NoOpInstrumentation() {
@Override
public DataFetcher<?> instrumentDataFetcher(
DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters) {
return (DataFetcher<Object>)
dataFetchingEnvironment -> {
Object data = dataFetcher.get(dataFetchingEnvironment);
if (data instanceof ListenableFuture) {
return FutureConverter.<Object>toCompletableFuture((ListenableFuture<Object>) data);
}
return data;
};
}
};
}
开发者ID:google,项目名称:rejoiner,代码行数:25,代码来源:GuavaListenableFutureSupport.java
示例2: getInstanceUpsertDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
public DataFetcher getInstanceUpsertDataFetcher(SchemaDescription schemaDescription, String instanceNamespace,
String domainName) {
return environment -> {
Map<String, Object> argMap = environment.getArguments();
Object inputValue = argMap.get("schemaInstance");
if (!(inputValue instanceof Map))
return "{}";
SchemaInstanceKey schemaInstanceKey = getSchemaInstanceKeyWithLabelArgument(instanceNamespace,
domainName, schemaDescription.getNamespace(), argMap);
@SuppressWarnings("unchecked")
Map<String, Object> inputMap = (Map<String, Object>) inputValue;
schemaDescription.getDomainFields().forEach(fieldDef -> validateField(fieldDef, inputMap));
if (inputMap.containsKey(ID)) {
validateProvidedID(schemaInstanceKey, schemaDescription, inputMap);
} else {
validateAndGenerateID(schemaDescription, inputMap);
}
SchemaInstance currentInstance = new SchemaInstance(inputMap, schemaInstanceKey);
currentInstance = schemaInstanceRepository.upsert(schemaInstanceKey, currentInstance);
return currentInstance;
};
}
开发者ID:nfl,项目名称:gold,代码行数:26,代码来源:DataFetcherFactory.java
示例3: newFieldDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher newFieldDataFetcher(final IGraphQLObjectMapper graphQLObjectMapper, final Optional<Object> targetObject, final Field field, final String fieldName, Class<? extends DataFetcher> dataFetcher) {
SpringDataFetcher dataFetcherObject = null;
try {
GraphQLSpringELDataFetcher springDataFetcher = field.getAnnotation(GraphQLSpringELDataFetcher.class);
if (springDataFetcher != null) {
dataFetcherObject = springDataFetcher.dataFetcher().newInstance();
dataFetcherObject.setFieldName(field.getName());
dataFetcherObject.setTypeFactory(graphQLObjectMapper.getTypeFactory());
dataFetcherObject.setTargetObject(null);
dataFetcherObject.setMethod(null);
dataFetcherObject.setExpression(springDataFetcher.value());
dataFetcherObject.setApplicationContext(context);
return dataFetcherObject;
}
} catch (Exception ex) {
throw Throwables.propagate(ex);
}
return super.newFieldDataFetcher(graphQLObjectMapper, targetObject, field, fieldName, dataFetcher);
}
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:23,代码来源:SpringDataFetcherFactory.java
示例4: newMethodDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher newMethodDataFetcher(final IGraphQLObjectMapper graphQLObjectMapper,
final Optional<Object> targetObject,
final Method method,
final String fieldName,
final Class<? extends DataFetcher> dataFetcher) {
checkNotNull(method);
SpringDataFetcher dataFetcherObject = null;
try {
GraphQLSpringELDataFetcher springDataFetcher = method.getAnnotation(GraphQLSpringELDataFetcher.class);
if (springDataFetcher != null) {
dataFetcherObject = springDataFetcher.dataFetcher().newInstance();
dataFetcherObject.setFieldName(fieldName);
dataFetcherObject.setTypeFactory(graphQLObjectMapper.getTypeFactory());
dataFetcherObject.setTargetObject(targetObject);
dataFetcherObject.setMethod(method);
dataFetcherObject.setExpression(springDataFetcher.value());
dataFetcherObject.setApplicationContext(context);
return dataFetcherObject;
}
} catch (Exception ex) {
throw Throwables.propagate(ex);
}
return super.newMethodDataFetcher(graphQLObjectMapper, targetObject, method, fieldName, dataFetcher);
}
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:26,代码来源:SpringDataFetcherFactory.java
示例5: addTypeConverter
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher addTypeConverter(Optional<GraphQLTypeConverter> typeConverterAnnotation, Class<?> fieldTypeClass, DataFetcher dataFetcher) {
Class<? extends DefaultTypeConverter> typeConverterClass= null;
if (typeConverterAnnotation.isPresent()) {
typeConverterClass = typeConverterAnnotation.get().typeConverter();
} else {
for (Map.Entry<Class<?>, Class<? extends DefaultTypeConverter>> entry : defaultTypeConverters.entrySet()) {
if (entry.getKey().isAssignableFrom(fieldTypeClass)) {
typeConverterClass = entry.getValue();
}
}
}
if (typeConverterClass != null) {
try {
dataFetcher = typeConverterClass.getConstructor(DataFetcher.class).newInstance(dataFetcher);
} catch (Exception ex) {
Throwables.propagate(ex);
}
}
return dataFetcher;
}
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:23,代码来源:GraphQLObjectMapper.java
示例6: newMethodDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
@Override
public DataFetcher newMethodDataFetcher(final IGraphQLObjectMapper graphQLObjectMapper,
final Optional<Object> targetObject,
final Method method,
final String fieldName,
final Class<? extends DataFetcher> dataFetcher) {
DataFetcher dataFetcherObject;
try {
dataFetcherObject = dataFetcher.newInstance();
if (!IMethodDataFetcher.class.isAssignableFrom(dataFetcher)) {
throw new InvalidParameterException("This Data Fetcher Factory only supports IMethodDataFetchers");
}
IMethodDataFetcher methodDataFetcher = (IMethodDataFetcher) dataFetcherObject;
methodDataFetcher.setFieldName(fieldName);
methodDataFetcher.setTypeFactory(graphQLObjectMapper.getTypeFactory());
if (targetObject.isPresent()) {
methodDataFetcher.setTargetObject(targetObject.get());
}
methodDataFetcher.setMethod(method);
} catch (Exception ex) {
throw Throwables.propagate(ex);
}
return dataFetcherObject;
}
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:25,代码来源:DefaultDataFetcherFactory.java
示例7: ResolverDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
public ResolverDataFetcher(DataFetcher fetcher, Resolver resolver, int listDepth) {
this.fetcher = fetcher;
this.resolver = resolver;
this.listDepth = listDepth;
if ( fetcher instanceof BatchedDataFetcher ) {
this.isBatched = true;
} else {
try {
Method getMethod = fetcher.getClass()
.getMethod("get", DataFetchingEnvironment.class);
this.isBatched = null != getMethod.getAnnotation(Batched.class);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(e);
}
}
}
开发者ID:Distelli,项目名称:graphql-apigen,代码行数:17,代码来源:ResolverDataFetcher.java
示例8: isDataFetcherBatched
import graphql.schema.DataFetcher; //导入依赖的package包/类
/**
* Tells whether a given data fetcher supports batching
* {code @Batched} on the get method or instance of {code BatchedDataFetcher}
*
* @param supplied data fetcher
* @return true if batched, false otherwise
*/
public static boolean isDataFetcherBatched(DataFetcher supplied) {
if (supplied instanceof BatchedDataFetcher) {
return true;
}
try {
Method getMethod = supplied.getClass().getMethod("get", DataFetchingEnvironment.class);
Batched batched = getMethod.getAnnotation(Batched.class);
if (batched != null) {
return true;
}
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(e);
}
return false;
}
开发者ID:nfl,项目名称:glitr,代码行数:24,代码来源:ReflectionUtil.java
示例9: gitChangeLogFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher gitChangeLogFetcher() {
return fetcher(
Branch.class,
(DataFetchingEnvironment environment, Branch branch) -> {
String from = GraphqlUtils.getStringArgument(environment, "from").orElseThrow(() -> new IllegalStateException("From argument is required."));
String to = GraphqlUtils.getStringArgument(environment, "to").orElseThrow(() -> new IllegalStateException("To argument is required."));
Build fromBuild = structureService.findBuildByName(branch.getProject().getName(), branch.getName(), from)
.orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), from));
Build toBuild = structureService.findBuildByName(branch.getProject().getName(), branch.getName(), to)
.orElseThrow(() -> new BuildNotFoundException(branch.getProject().getName(), branch.getName(), to));
return gitService.changeLog(
new BuildDiffRequest(
fromBuild.getId(),
toBuild.getId()
)
);
}
);
}
开发者ID:nemerosa,项目名称:ontrack,代码行数:20,代码来源:GitChangeLogBranchGraphQLFieldContributor.java
示例10: projectBranchesFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher projectBranchesFetcher() {
return environment -> {
Object source = environment.getSource();
if (source instanceof Project) {
Project project = (Project) source;
String name = environment.getArgument("name");
// Combined filter
Predicate<Branch> filter = b -> true;
// Name criteria
if (name != null) {
Pattern nameFilter = Pattern.compile(name);
filter = filter.and(branch -> nameFilter.matcher(branch.getName()).matches());
}
return structureService.getBranchesForProject(project.getId()).stream()
.filter(filter)
.collect(Collectors.toList());
} else {
return Collections.emptyList();
}
};
}
开发者ID:nemerosa,项目名称:ontrack,代码行数:22,代码来源:GQLTypeProject.java
示例11: projectEntityPropertiesDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher projectEntityPropertiesDataFetcher(Class<? extends ProjectEntity> projectEntityClass) {
return environment -> {
Object o = environment.getSource();
if (projectEntityClass.isInstance(o)) {
// Filters
Optional<String> typeFilter = GraphqlUtils.getStringArgument(environment, "type");
boolean hasValue = GraphqlUtils.getBooleanArgument(environment, "hasValue", false);
// Gets the raw list
return propertyService.getProperties((ProjectEntity) o).stream()
// Filter by type
.filter(property -> typeFilter
.map(typeFilterName -> StringUtils.equals(
typeFilterName,
property.getTypeDescriptor().getTypeName()
))
.orElse(true)
)
// Filter by value
.filter(property -> !hasValue || !property.isEmpty())
// OK
.collect(Collectors.toList());
} else {
return null;
}
};
}
开发者ID:nemerosa,项目名称:ontrack,代码行数:27,代码来源:GQLProjectEntityPropertyListFieldContributor.java
示例12: branchValidationStampsFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher branchValidationStampsFetcher() {
return environment -> {
Object source = environment.getSource();
Optional<String> name = GraphqlUtils.getStringArgument(environment, "name");
if (source instanceof Branch) {
Branch branch = (Branch) source;
if (name.isPresent()) {
return structureService.findValidationStampByName(
branch.getProject().getName(), branch.getName(), name.get()
)
.map(Collections::singletonList)
.orElse(Collections.emptyList());
} else {
return structureService.getValidationStampListForBranch(branch.getId());
}
} else {
return Collections.emptyList();
}
};
}
开发者ID:nemerosa,项目名称:ontrack,代码行数:21,代码来源:GQLTypeBranch.java
示例13: projectEntityDecorationsDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher projectEntityDecorationsDataFetcher(Class<? extends ProjectEntity> projectEntityClass) {
return environment -> {
Object o = environment.getSource();
if (projectEntityClass.isInstance(o)) {
// Filters
Optional<String> typeFilter = GraphqlUtils.getStringArgument(environment, "type");
// Gets the raw list
return decorationService.getDecorations((ProjectEntity) o).stream()
// Filter by type
.filter(property -> typeFilter
.map(typeFilterName -> StringUtils.equals(
typeFilterName,
property.getDecorationType()
))
.orElse(true)
)
// OK
.collect(Collectors.toList());
} else {
return null;
}
};
}
开发者ID:nemerosa,项目名称:ontrack,代码行数:24,代码来源:GQLProjectEntityDecorationListFieldContributor.java
示例14: stockQuotesSubscriptionFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher stockQuotesSubscriptionFetcher() {
return environment -> {
List<String> arg = environment.getArgument("stockCodes");
List<String> stockCodesFilter = arg == null ? Collections.emptyList() : arg;
if (stockCodesFilter.isEmpty()) {
return STOCK_TICKER_PUBLISHER.getPublisher();
} else {
return STOCK_TICKER_PUBLISHER.getPublisher(stockCodesFilter);
}
};
}
开发者ID:graphql-java,项目名称:graphql-java-subscription-example,代码行数:12,代码来源:StockTickerGraphqlPublisher.java
示例15: getSchemaInstanceCountDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
public DataFetcher getSchemaInstanceCountDataFetcher() {
return env -> {
SchemaDescription schema = env.getSource();
return schemaInstanceRepository.countInstances(new SchemaInstanceKey(
schema.getName(),
schema.getNamespace(),
env.getArgument(INSTANCE_COUNT_INSTANCE_NAMESPACE_ARGUMENT)));
};
}
开发者ID:nfl,项目名称:gold,代码行数:10,代码来源:DataFetcherFactory.java
示例16: getInstanceFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
public DataFetcher<Connection<SchemaInstance>> getInstanceFetcher(String instanceNamespace, String schemaName, String schemaNamespace,
List<FilterConfiguration> filterConfigurations) {
return environment -> {
Map<String, Object> argMap = environment.getArguments();
@SuppressWarnings("unchecked")
List<String> ids = (List<String>) argMap.get("ids");
SchemaInstanceKey instanceKey =
getSchemaInstanceKeyWithLabelArgument(instanceNamespace, schemaName, schemaNamespace, argMap);
preloadInstances(ids, instanceKey, environment.getContext());
List<SchemaInstance> instances = retrieveInstances(ids, instanceKey);
@SuppressWarnings("unchecked")
Map<String, Object> filters =
(Map<String, Object>) argMap.getOrDefault(FILTERS_ARGUMENT, Collections.EMPTY_MAP);
instances = filterInstances(filterConfigurations, instances, filters);
if (environment.getArgument(ORDER_BY_ARGUMENT) != null) {
instances = sortInstances(
instances,
environment.getArgument(ORDER_BY_ARGUMENT),
environment.getArgument(ORDER_BY_DIRECTION_ARGUMENT));
}
return ConnectionWithTotal.create(instances, environment);
};
}
开发者ID:nfl,项目名称:gold,代码行数:30,代码来源:DataFetcherFactory.java
示例17: getDeleteFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
public DataFetcher getDeleteFetcher(final SchemaInstanceKey schemaInstanceKey) {
return environment -> {
Map<String, Object> argMap = environment.getArguments();
Object nameValue = argMap.get(ID);
if (nameValue == null)
return "{}";
SchemaInstanceKey schemaInstanceKeyWithLabel = getSchemaInstanceKeyWithLabelArgument(
schemaInstanceKey.getInstanceNamespace(), schemaInstanceKey.getSchemaName(),
schemaInstanceKey.getSchemaNamespace(), argMap);
return schemaInstanceRepository.deleteInstance(schemaInstanceKeyWithLabel, nameValue.toString());
};
}
开发者ID:nfl,项目名称:gold,代码行数:14,代码来源:DataFetcherFactory.java
示例18: getExternalReferenceDataFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
public DataFetcher getExternalReferenceDataFetcher(String memberFieldName, String authHeader) {
return environment -> {
@SuppressWarnings("unchecked")
Map<String, String> id = (Map<String, String>)
((Map<String, Object>) environment.getSource()).get(memberFieldName);
if (id == null) {
return null;
}
return findExternalById(environment, id, authHeader);
};
}
开发者ID:nfl,项目名称:gold,代码行数:13,代码来源:DataFetcherFactory.java
示例19: buildViewerFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
private DataFetcher buildViewerFetcher(List<RootChild> rootChildren) {
return environment -> {
Map<String, String> rootViewMap = new HashMap<>();
Map<String, Object> retMap = new HashMap<>();
rootChildren.forEach(child -> retMap.put(child.childFieldName(), singletonList(rootViewMap)));
return retMap;
};
}
开发者ID:nfl,项目名称:gold,代码行数:9,代码来源:GraphQLRelayBuilder.java
示例20: idFetcher
import graphql.schema.DataFetcher; //导入依赖的package包/类
public DataFetcher<String> idFetcher() {
return environment -> {
RDFNode thisNode = environment.getSource();
if (thisNode.asResource().isURIResource()) {
return thisNode.asResource().getURI();
} else {
return "_:" + thisNode.asNode().getBlankNodeLabel();
}
};
}
开发者ID:semantic-integration,项目名称:hypergraphql,代码行数:15,代码来源:FetcherFactory.java
注:本文中的graphql.schema.DataFetcher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论