當前位置: 首頁>>代碼示例>>Java>>正文


Java Batched類代碼示例

本文整理匯總了Java中graphql.execution.batched.Batched的典型用法代碼示例。如果您正苦於以下問題:Java Batched類的具體用法?Java Batched怎麽用?Java Batched使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Batched類屬於graphql.execution.batched包,在下文中一共展示了Batched類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildQueryResolvers

import graphql.execution.batched.Batched; //導入依賴的package包/類
private Collection<Resolver> buildQueryResolvers(Object querySourceBean, AnnotatedType beanType, List<Predicate<Member>> filters) {
    Class<?> rawType = ClassUtils.getRawType(beanType.getType());
    if (rawType.isArray() || rawType.isPrimitive()) return Collections.emptyList();
    return Arrays.stream(rawType.getMethods())
            .filter(method -> isPackageAcceptable(method, rawType))
            .filter(this::isQuery)
            .filter(filters.stream().reduce(Predicate::and).orElse(ACCEPT_ALL))
            .map(method -> new Resolver(
                    operationNameGenerator.generateQueryName(method, beanType, querySourceBean),
                    "",
                    method.isAnnotationPresent(Batched.class),
                    querySourceBean == null ? new MethodInvoker(method, beanType) : new SingletonMethodInvoker(querySourceBean, method, beanType),
                    getReturnType(method, beanType),
                    argumentBuilder.buildResolverArguments(method, beanType),
                    method.isAnnotationPresent(GraphQLComplexity.class) ? method.getAnnotation(GraphQLComplexity.class).value() : null
            ))
            .collect(Collectors.toList());
}
 
開發者ID:leangen,項目名稱:graphql-spqr,代碼行數:19,代碼來源:PublicResolverBuilder.java

示例2: buildQueryResolvers

import graphql.execution.batched.Batched; //導入依賴的package包/類
private Collection<Resolver> buildQueryResolvers(Object querySourceBean, AnnotatedType beanType, List<Predicate<Member>> filters) {
    Stream<Resolver> methodInvokers = ClassUtils.getAnnotatedMethods(ClassUtils.getRawType(beanType.getType()), GraphQLQuery.class).stream()
            .filter(filters.stream().reduce(Predicate::and).orElse(ACCEPT_ALL))
            .map(method -> new Resolver(
                    operationNameGenerator.generateQueryName(method, beanType, querySourceBean),
                    method.getAnnotation(GraphQLQuery.class).description(),
                    method.isAnnotationPresent(Batched.class),
                    querySourceBean == null ? new MethodInvoker(method, beanType) : new SingletonMethodInvoker(querySourceBean, method, beanType),
                    getReturnType(method, beanType),
                    argumentBuilder.buildResolverArguments(method, beanType),
                    method.isAnnotationPresent(GraphQLComplexity.class) ? method.getAnnotation(GraphQLComplexity.class).value() : null
            ));
    Stream<Resolver> fieldAccessors = ClassUtils.getAnnotatedFields(ClassUtils.getRawType(beanType.getType()), GraphQLQuery.class).stream()
            .filter(filters.stream().reduce(Predicate::and).orElse(ACCEPT_ALL))
            .map(field -> new Resolver(
                    operationNameGenerator.generateQueryName(field, beanType, querySourceBean),
                    field.getAnnotation(GraphQLQuery.class).description(),
                    false,
                    new FieldAccessor(field, beanType),
                    getFieldType(field, beanType),
                    Collections.emptyList(),
                    field.isAnnotationPresent(GraphQLComplexity.class) ? field.getAnnotation(GraphQLComplexity.class).value() : null
            ));
    return Stream.concat(methodInvokers, fieldAccessors).collect(Collectors.toSet());
}
 
開發者ID:leangen,項目名稱:graphql-spqr,代碼行數:26,代碼來源:AnnotatedResolverBuilder.java

示例3: ResolverDataFetcher

import graphql.execution.batched.Batched; //導入依賴的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

示例4: get

import graphql.execution.batched.Batched; //導入依賴的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);
}
 
開發者ID:Distelli,項目名稱:graphql-apigen,代碼行數:17,代碼來源:ResolverDataFetcher.java

示例5: isDataFetcherBatched

import graphql.execution.batched.Batched; //導入依賴的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

示例6: education

import graphql.execution.batched.Batched; //導入依賴的package包/類
@GraphQLQuery
@Batched
public List<Education> education(@GraphQLContext List<SimpleUser> users) {
    return users.stream()
            .map(u -> u.getEducation(2000 + u.getFullName().charAt(0)))
            .collect(Collectors.toList());
}
 
開發者ID:leangen,項目名稱:graphql-spqr,代碼行數:8,代碼來源:RecService.java

示例7: educations

import graphql.execution.batched.Batched; //導入依賴的package包/類
@Batched
@GraphQLQuery
public List<Education> educations(@GraphQLArgument(name = "users") @GraphQLContext List<SimpleUser> users, @GraphQLRootContext AtomicBoolean flag) {
    assertEquals(3, users.size());
    flag.getAndSet(true);
    return users.stream()
            .map(u -> u.getEducation(2000 + u.getFullName().charAt(0)))
            .collect(Collectors.toList());
}
 
開發者ID:leangen,項目名稱:graphql-spqr,代碼行數:10,代碼來源:BatchingTest.java

示例8: create

import graphql.execution.batched.Batched; //導入依賴的package包/類
public static DataFetcher create(final List<DataFetcher> supplied) {
    checkArgument(supplied != null && !supplied.isEmpty());

    // convert OverrideDataFetcher to batched one if the overrideMethod is @Batched
    List<DataFetcher> fetchers = supplied.stream()
            // filter out all the OverrideDataFetchers that have a null overrideMethod since type registry adds a default overrideDF
            .filter(f -> !(f instanceof OverrideDataFetcher) || ((OverrideDataFetcher)f).getOverrideMethod() != null)
            .map(f -> {
                if (f instanceof OverrideDataFetcher) {
                    OverrideDataFetcher overrideDataFetcher = ((OverrideDataFetcher) f);
                    Method overrideMethod = overrideDataFetcher.getOverrideMethod();
                    Batched batched = overrideMethod.getAnnotation(Batched.class);
                    if (batched != null) {
                        return new UnbatchedDataFetcher(overrideDataFetcher);
                    }
                }
                return f;
    }).collect(Collectors.toList());

    // let's see if there is at least one Batched in the list
    boolean isListContainsBatchedDataFetcher = fetchers.stream()
            .filter(f -> !(f instanceof PropertyDataFetcher) && !(f instanceof FieldDataFetcher))
            .anyMatch(ReflectionUtil::isDataFetcherBatched);

    if (!isListContainsBatchedDataFetcher) {
        return new CompositeDataFetcher(fetchers);
    }

    // are they all batched?
    boolean isListOnlyBatchedDataFetcher = fetchers.stream()
            .filter(f -> !(f instanceof PropertyDataFetcher) && !(f instanceof FieldDataFetcher))
            .allMatch(ReflectionUtil::isDataFetcherBatched);

    if (!isListOnlyBatchedDataFetcher) {
        throw new IllegalArgumentException("Both Batched and Simple data fetchers detected in passed list. " +
                                                   "Batched data fetchers can't mix with simple ones. " + fetchers);
    }

    // convert PropertyDataFetcher to batched one
    List<DataFetcher> batchedDataFetchers = fetchers.stream().map(f -> {
        if (f instanceof PropertyDataFetcher) {
            return new UnbatchedDataFetcher(f);
        }
        return f;
    }).collect(Collectors.toList());
    return new BatchedCompositeDataFetcher(batchedDataFetchers);
}
 
開發者ID:nfl,項目名稱:glitr,代碼行數:48,代碼來源:CompositeDataFetcherFactory.java


注:本文中的graphql.execution.batched.Batched類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。