本文整理汇总了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));
}
示例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();
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
});
}
示例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);
}
}
示例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);
}
示例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");
}
}
}
}
示例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;
};
}
示例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();
}
}
}
示例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);
}
示例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);
}