本文整理汇总了Java中graphql.schema.DataFetcher类的典型用法代码示例。如果您正苦于以下问题:Java DataFetcher类的具体用法?Java DataFetcher怎么用?Java DataFetcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataFetcher类属于graphql.schema包,在下文中一共展示了DataFetcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
};
}
};
}
示例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;
};
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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()
)
);
}
);
}
示例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();
}
};
}
示例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;
}
};
}
示例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();
}
};
}
示例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;
}
};
}
示例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)));
};
}