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


Java Field类代码示例

本文整理汇总了Java中graphql.language.Field的典型用法代码示例。如果您正苦于以下问题:Java Field类的具体用法?Java Field怎么用?Java Field使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Field类属于graphql.language包,在下文中一共展示了Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSchema

import graphql.language.Field; //导入依赖的package包/类
static Relation buildSchema(String query, String source) {
    for (Definition definition : new Parser().parseDocument(query)
                                             .getDefinitions()) {
        if (definition instanceof OperationDefinition) {
            OperationDefinition operation = (OperationDefinition) definition;
            if (operation.getOperation()
                         .equals(Operation.QUERY)) {
                for (Selection selection : operation.getSelectionSet()
                                                    .getSelections()) {
                    if (selection instanceof Field) {
                        Field field = (Field) selection;
                        if (source.equals(field.getName())) {
                            return buildSchema(field);
                        }
                    }
                }
            }
        }
    }
    throw new IllegalStateException(String.format("Invalid query, cannot find source: %s",
                                                  source));
}
 
开发者ID:ChiralBehaviors,项目名称:Kramer,代码行数:23,代码来源:GraphQlUtil.java

示例2: completeValue

import graphql.language.Field; //导入依赖的package包/类
/**
 * If the result that is returned by the {@link graphql.schema.DataFetcher} is a {@link
 * CompletableFuture}, then wait for it to complete, prior to calling the super method.
 *
 * @return the completed execution result
 */
@Override
protected ExecutionResult completeValue(final ExecutionContext executionContext,
                                        final GraphQLType fieldType,
                                        final List<Field> fields, Object result) {
  if (!(result instanceof CompletableFuture)) {
    return super.completeValue(executionContext, fieldType, fields, result);
  }
  ExecutionStrategy executionStrategy = this;
  return ((CompletableFuture<ExecutionResult>) result)
    .thenComposeAsync(
      (Function<Object, CompletableFuture<ExecutionResult>>)
        completedResult -> completable(
          executionStrategy.completeValue(executionContext, fieldType, fields, completedResult),
          executorService), executorService)
    .exceptionally(throwable -> {
      executionContext.addError(new ExceptionWhileDataFetching(throwable));
      return null;
    })
    .join();
}
 
开发者ID:karthicks,项目名称:graphql-java-async,代码行数:27,代码来源:AsyncExecutionStrategy.java

示例3: completeValueForList

import graphql.language.Field; //导入依赖的package包/类
/**
 * If the result is a list, then it's elements can now potentially be a {@link CompletableFuture}.
 * To reduce the number of tasks in progress, it behooves us to wait for all those completable
 * elements to wrap up.
 *
 * @return the completed execution result
 */
@Override
protected ExecutionResult completeValueForList(ExecutionContext executionContext,
                                               GraphQLList fieldType,
                                               List<Field> fields, Iterable<Object> result) {
  ExecutionResult executionResult =
    super.completeValueForList(executionContext, fieldType, fields, result);
  List<Object> completableResults = (List<Object>) executionResult.getData();
  List<Object> completedResults = new ArrayList<>();
  completableResults.forEach(completedResult -> {
    completedResults.add((completedResult instanceof CompletableFuture) ?
                         ((CompletableFuture) completedResult).join() : completedResult);
  });
  ((ExecutionResultImpl) executionResult).setData(completedResults);
  return executionResult;
}
 
开发者ID:karthicks,项目名称:graphql-java-async,代码行数:23,代码来源:AsyncExecutionStrategy.java

示例4: get

import graphql.language.Field; //导入依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {

	for (Field field : environment.getFields()) {
		if (field.getName().equals(fieldName)) {
			Object[] arguments = new Object[argumentTypeMap.size()];
			int index = 0;
			for (String argumentName : argumentTypeMap.keySet()) {
				arguments[index] = getParamValue(environment, argumentName, argumentTypeMap.get(argumentName));
				index++;
			}
			return invokeMethod(environment, method, targetObject.isPresent() ? targetObject.get() : environment.getSource(), arguments);
		}
	}
	return null;

}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:18,代码来源:DefaultMethodDataFetcher.java

示例5: getArgumentValue

import graphql.language.Field; //导入依赖的package包/类
@Override
public Object getArgumentValue(Object rawInput, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) {
    if (GenericTypeReflector.isSuperType(setOfStrings, type.getType())) {
        return resolutionEnvironment.dataFetchingEnvironment.getSelectionSet().get().keySet();
    }
    Class raw = GenericTypeReflector.erase(type.getType());
    if (Field.class.equals(raw)) {
        return resolutionEnvironment.fields.get(0);
    }
    if (GenericTypeReflector.isSuperType(listOfFields, type.getType())) {
        return resolutionEnvironment.fields;
    }
    if (ValueMapper.class.isAssignableFrom(raw)) {
        return resolutionEnvironment.valueMapper;
    }
    if (ResolutionEnvironment.class.isAssignableFrom(raw)) {
        return resolutionEnvironment;
    }
    throw new IllegalArgumentException("Argument of type " + raw.getName() 
            + " can not be injected via @" + GraphQLEnvironment.class.getSimpleName());
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:22,代码来源:EnvironmentInjector.java

示例6: collectFields

import graphql.language.Field; //导入依赖的package包/类
private ResolvedField collectFields(FieldCollectorParameters parameters, List<ResolvedField> fields) {
    ResolvedField field = fields.get(0);
    if (!fields.stream().allMatch(f -> f.getFieldType() instanceof GraphQLFieldsContainer)) {
        field.setComplexityScore(complexityFunction.getComplexity(field, 0));
        return field;
    }
    List<Field> rawFields = fields.stream().map(ResolvedField::getField).collect(Collectors.toList());
    Map<String, ResolvedField> children = collectFields(parameters, rawFields, (GraphQLFieldsContainer) field.getFieldType());
    ResolvedField node = new ResolvedField(field.getField(), field.getFieldDefinition(), field.getArguments(), children);
    int childScore = children.values().stream().mapToInt(ResolvedField::getComplexityScore).sum();
    int complexityScore = complexityFunction.getComplexity(node, childScore);
    if (complexityScore > maximumComplexity) {
        throw new ComplexityLimitExceededException(complexityScore, maximumComplexity);
    }
    node.setComplexityScore(complexityScore);
    return node;
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:18,代码来源:ComplexityAnalyzer.java

示例7: doExecute

import graphql.language.Field; //导入依赖的package包/类
public ExecutionResult doExecute(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, Map<String, List<Field>> fields) {

        List<Observable<Pair<String, Object>>> observablesResult = new ArrayList<>();
        List<Observable<Double>> observablesComplexity = new ArrayList<>();
        for (String fieldName : fields.keySet()) {
            final List<Field> fieldList = fields.get(fieldName);

            ExecutionResult executionResult = resolveField(executionContext, parentType, source, fieldList);
            observablesResult.add(unwrapExecutionResult(fieldName, executionResult));
            observablesComplexity.add(calculateFieldComplexity(executionContext, parentType, fieldList,
                    executionResult != null ? ((GraphQLRxExecutionResult) executionResult).getComplexityObservable() : Observable.just(0.0)));
        }

        Observable<Map<String, Object>> result =
                Observable.merge(observablesResult)
                        .toMap(Pair::getLeft, Pair::getRight);

        GraphQLRxExecutionResult graphQLRxExecutionResult = new GraphQLRxExecutionResult(result, Observable.just(executionContext.getErrors()), MathObservable.sumDouble(Observable.merge(observablesComplexity)));
        return graphQLRxExecutionResult;
    }
 
开发者ID:oembedler,项目名称:spring-graphql-common,代码行数:21,代码来源:GraphQLDefaultRxExecutionStrategy.java

示例8: calculateFieldComplexity

import graphql.language.Field; //导入依赖的package包/类
protected Observable<Double> calculateFieldComplexity(ExecutionContext executionContext, GraphQLObjectType parentType, List<Field> fields, Observable<Double> childScore) {
    return childScore.flatMap(aDouble -> {
        Observable<Double> result = Observable.just(aDouble + NODE_SCORE);
        GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
        if (fieldDef != null) {
            GraphQLFieldDefinitionWrapper graphQLFieldDefinitionWrapper = getGraphQLFieldDefinitionWrapper(fieldDef);
            if (graphQLFieldDefinitionWrapper != null) {
                Expression expression = graphQLFieldDefinitionWrapper.getComplexitySpelExpression();
                if (expression != null) {
                    Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
                    StandardEvaluationContext context = new StandardEvaluationContext();
                    context.setVariable(GraphQLConstants.EXECUTION_COMPLEXITY_CHILD_SCORE, aDouble);
                    if (argumentValues != null)
                        context.setVariables(argumentValues);
                    result = Observable.just(expression.getValue(context, Double.class));
                }
            }
        }
        return addComplexityCheckObservable(executionContext, result);
    });
}
 
开发者ID:oembedler,项目名称:spring-graphql-common,代码行数:22,代码来源:GraphQLAbstractRxExecutionStrategy.java

示例9: executeOperation

import graphql.language.Field; //导入依赖的package包/类
private ExecutionResult executeOperation(
        ExecutionContext executionContext,
        Object root,
        OperationDefinition operationDefinition) {
    GraphQLObjectType operationRootType = getOperationRootType(executionContext.getGraphQLSchema(), executionContext.getOperationDefinition());

    Map<String, List<Field>> fields = new LinkedHashMap<String, List<Field>>();
    fieldCollector.collectFields(executionContext, operationRootType, operationDefinition.getSelectionSet(), new ArrayList<String>(), fields);

    if (operationDefinition.getOperation() == OperationDefinition.Operation.MUTATION) {
        return new GraphQLDefaultRxExecutionStrategy(graphQLSchemaHolder, maxQueryDepth, maxQueryComplexity)
                                                  .execute(executionContext, operationRootType, root, fields);
    } else {
        return strategy.execute(executionContext, operationRootType, root, fields);
    }
}
 
开发者ID:oembedler,项目名称:spring-graphql-common,代码行数:17,代码来源:RxExecution.java

示例10: completeValueForList

import graphql.language.Field; //导入依赖的package包/类
@Override
protected ExecutionResult completeValueForList(ExecutionContext executionContext, GraphQLList fieldType, List<Field> fields, List<Object> result) {
    Observable<?> resultObservable =
            Observable.from(
                    IntStream.range(0, result.size())
                            .mapToObj(idx -> new ListTuple(idx, result.get(idx)))
                            .toArray(ListTuple[]::new)
            )
            .flatMap(tuple -> {
                ExecutionResult executionResult = completeValue(executionContext, fieldType.getWrappedType(), fields, tuple.result);

                if (executionResult instanceof RxExecutionResult) {
                    return Observable.zip(Observable.just(tuple.index), ((RxExecutionResult)executionResult).getDataObservable(), ListTuple::new);
                }
                return Observable.just(new ListTuple(tuple.index, executionResult.getData()));
            })
            .toList()
            .map(listTuples -> {
                return listTuples.stream()
                        .sorted(Comparator.comparingInt(x -> x.index))
                        .map(x -> x.result)
                        .collect(Collectors.toList());
            });

    return new RxExecutionResult(resultObservable, null);
}
 
开发者ID:nfl,项目名称:graphql-rxjava,代码行数:27,代码来源:RxExecutionStrategy.java

示例11: buildSelections

import graphql.language.Field; //导入依赖的package包/类
private void buildSelections(SelectionSet selectionSet, StringBuilder sb) {
    for (Selection sel : selectionSet.getSelections()) {
        if (sel instanceof Field) {
            Field fieldSel = (Field) sel;
            // Literal
            if (fieldSel.getSelectionSet() == null) {
                sb.append(fieldSel.getName()).append("\n");
            } else { // Object
                sb.append(fieldSel.getName()).append(" {\n");
                buildSelections(fieldSel.getSelectionSet(), sb);
                sb.append("}\n");
            }
        }
    }
}
 
开发者ID:nfl,项目名称:gold,代码行数:16,代码来源:ExternalReferenceRepositoryImpl.java

示例12: instancesOfTypeFetcher

import graphql.language.Field; //导入依赖的package包/类
public  DataFetcher<List<RDFNode>> instancesOfTypeFetcher() {
    return environment -> {
        Field field = (Field) environment.getFields().toArray()[0];
        String predicate = (field.getAlias() != null) ? field.getAlias() : field.getName();
        ModelContainer client = environment.getContext();
        List<RDFNode> subjects = client.getValuesOfObjectProperty(HGQLVocabulary.HGQL_QUERY_URI, HGQLVocabulary.HGQL_QUERY_NAMESPACE + predicate);
        return subjects;
    };
}
 
开发者ID:semantic-integration,项目名称:hypergraphql,代码行数:10,代码来源:FetcherFactory.java

示例13: FetchParams

import graphql.language.Field; //导入依赖的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();
            }
        }
    }
 
开发者ID:semantic-integration,项目名称:hypergraphql,代码行数:14,代码来源:FetchParams.java

示例14: collectField

import graphql.language.Field; //导入依赖的package包/类
private void collectField(FieldCollectorParameters parameters, Map<String, List<ResolvedField>> fields, Field field, GraphQLFieldsContainer parent) {
    if (!conditionalNodes.shouldInclude(parameters.getVariables(), field.getDirectives())) {
        return;
    }
    GraphQLFieldDefinition fieldDefinition = parent.getFieldDefinition(field.getName());
    Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDefinition.getArguments(), field.getArguments(), parameters.getVariables());
    ResolvedField node = new ResolvedField(field, fieldDefinition, argumentValues);
    fields.putIfAbsent(node.getName(), new ArrayList<>());
    fields.get(node.getName()).add(node);
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:11,代码来源:ComplexityAnalyzer.java

示例15: ResolvedField

import graphql.language.Field; //导入依赖的package包/类
public ResolvedField(Field field, GraphQLFieldDefinition fieldDefinition, Map<String, Object> arguments, Map<String, ResolvedField> children) {
    this.name = field.getAlias() != null ? field.getAlias() : field.getName();
    this.field = field;
    this.fieldDefinition = fieldDefinition;
    this.fieldType = (GraphQLOutputType) GraphQLUtils.unwrap(fieldDefinition.getType());
    this.arguments = arguments;
    this.children = children;
    this.resolver = findResolver(fieldDefinition, arguments);
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:10,代码来源:ResolvedField.java


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