本文整理了Java中graphql.language.Field.getSelectionSet()
方法的一些代码示例,展示了Field.getSelectionSet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Field.getSelectionSet()
方法的具体详情如下:
包路径:graphql.language.Field
类名称:Field
方法名:getSelectionSet
暂无
代码示例来源:origin: graphql-java/graphql-java
public MergedSelectionSet collectFields(FieldCollectorParameters parameters, MergedField mergedField) {
Map<String, MergedField> subFields = new LinkedHashMap<>();
List<String> visitedFragments = new ArrayList<>();
for (Field field : mergedField.getFields()) {
if (field.getSelectionSet() == null) {
continue;
}
this.collectFields(parameters, field.getSelectionSet(), visitedFragments, subFields);
}
return newMergedSelectionSet().subFields(subFields).build();
}
代码示例来源:origin: graphql-java/graphql-java
@Override
public void checkField(Field field) {
GraphQLOutputType type = getValidationContext().getOutputType();
if (type == null) return;
if (isLeaf(type)) {
if (field.getSelectionSet() != null) {
String message = String.format("Sub selection not allowed on leaf type %s of field %s", type.getName(), field.getName());
addError(ValidationErrorType.SubSelectionNotAllowed, field.getSourceLocation(), message);
}
} else {
if (field.getSelectionSet() == null) {
String message = String.format("Sub selection required for type %s of field %s", type.getName(), field.getName());
addError(ValidationErrorType.SubSelectionRequired, field.getSourceLocation(), message);
}
}
}
}
代码示例来源:origin: graphql-java/graphql-java
return new Conflict(responseName, reason, fieldA, fieldB);
SelectionSet selectionSet1 = fieldA.getSelectionSet();
SelectionSet selectionSet2 = fieldB.getSelectionSet();
if (selectionSet1 != null && selectionSet2 != null) {
Set<String> visitedFragmentSpreads = new LinkedHashSet<>();
代码示例来源:origin: graphql-java/graphql-java
private Builder(Field existing) {
this.sourceLocation = existing.getSourceLocation();
this.comments = existing.getComments();
this.name = existing.getName();
this.alias = existing.getAlias();
this.arguments = existing.getArguments();
this.directives = existing.getDirectives();
this.selectionSet = existing.getSelectionSet();
this.ignoredChars = existing.getIgnoredChars();
}
代码示例来源:origin: graphql-java/graphql-java
@Override
public TraversalControl visitField(Field node, TraverserContext<Node> context) {
Field changedNode = node.transform(builder -> {
builder.arguments(sort(node.getArguments(), comparing(Argument::getName)));
builder.directives(sort(node.getDirectives(), comparing(Directive::getName)));
builder.selectionSet(sortSelectionSet(node.getSelectionSet()));
});
return changeNode(context, changedNode);
}
代码示例来源:origin: graphql-java/graphql-java
private NodePrinter<Field> field() {
final String argSep = compactMode ? "," : ", ";
final String aliasSuffix = compactMode ? ":" : ": ";
return (out, node) -> {
String alias = wrap("", node.getAlias(), aliasSuffix);
String name = node.getName();
String arguments = wrap("(", join(node.getArguments(), argSep), ")");
String directives = directives(node.getDirectives());
String selectionSet = node(node.getSelectionSet());
out.printf("%s", spaced(
alias + name + arguments,
directives,
selectionSet
));
};
}
代码示例来源:origin: com.introproventures/graphql-jpa-query-schema
protected final boolean hasSelectionSet(Field field) {
return field.getSelectionSet() != null;
}
代码示例来源:origin: com.introproventures/graphql-jpa-query-schema
protected final Stream<Field> selections(Field field) {
SelectionSet selectionSet = field.getSelectionSet() != null
? field.getSelectionSet()
: new SelectionSet(Collections.emptyList());
return selectionSet.getSelections()
.stream()
.filter(it -> it instanceof Field)
.map(it -> (Field) it);
}
代码示例来源:origin: com.introproventures/graphql-jpa-query-schema
protected final Stream<Field> flatten(Field field) {
SelectionSet selectionSet = field.getSelectionSet() != null
? field.getSelectionSet()
: new SelectionSet(Collections.emptyList());
return Stream.concat(
Stream.of(field),
selectionSet.getSelections()
.stream()
.filter(it -> it instanceof Field)
.flatMap(selection -> this.flatten((Field) selection))
);
}
代码示例来源:origin: com.introproventures/graphql-jpa-query-schema
protected final Optional<Field> getSelectionField(Field field, String fieldName) {
return field.getSelectionSet().getSelections().stream()
.filter(it -> it instanceof Field)
.map(it -> (Field) it)
.filter(it -> fieldName.equals(it.getName()))
.findFirst();
}
代码示例来源:origin: yahoo/elide
public static boolean requestContainsPageInfo(Field field) {
return field.getSelectionSet().getSelections().stream()
.anyMatch(f -> f instanceof Field
&& ConnectionContainer.PAGE_INFO_KEYWORD.equals(((Field) f).getName()));
}
}
代码示例来源:origin: com.yahoo.elide/elide-graphql
public static boolean requestContainsPageInfo(Field field) {
return field.getSelectionSet().getSelections().stream()
.anyMatch(f -> f instanceof Field
&& ConnectionContainer.PAGE_INFO_KEYWORD.equals(((Field) f).getName()));
}
}
代码示例来源:origin: com.yahoo.elide/elide-graphql
/**
* log current context for debugging
* @param operation Current operation
* @param environment Environment encapsulating graphQL's request environment
*/
private void logContext(RelationshipOp operation, Environment environment) {
List<Field> children = (environment.field.getSelectionSet() != null)
? (List) environment.field.getSelectionSet().getChildren()
: new ArrayList<>();
String requestedFields = environment.field.getName() + (children.size() > 0
? "(" + children.stream().map(Field::getName).collect(Collectors.toList()) + ")" : "");
GraphQLType parent = environment.parentType;
if (log.isDebugEnabled()) {
log.debug("{} {} fields with parent {}<{}>",
operation, requestedFields, EntityDictionary.getSimpleName(parent.getClass()), parent.getName());
}
}
代码示例来源:origin: yahoo/elide
/**
* log current context for debugging
* @param operation Current operation
* @param environment Environment encapsulating graphQL's request environment
*/
private void logContext(RelationshipOp operation, Environment environment) {
List<Field> children = (environment.field.getSelectionSet() != null)
? (List) environment.field.getSelectionSet().getChildren()
: new ArrayList<>();
String requestedFields = environment.field.getName() + (children.size() > 0
? "(" + children.stream().map(Field::getName).collect(Collectors.toList()) + ")" : "");
GraphQLType parent = environment.parentType;
if (log.isDebugEnabled()) {
log.debug("{} {} fields with parent {}<{}>",
operation, requestedFields, EntityDictionary.getSimpleName(parent.getClass()), parent.getName());
}
}
代码示例来源:origin: com.graphql-java/graphql-java
public MergedSelectionSet collectFields(FieldCollectorParameters parameters, MergedField mergedField) {
Map<String, MergedField> subFields = new LinkedHashMap<>();
List<String> visitedFragments = new ArrayList<>();
for (Field field : mergedField.getFields()) {
if (field.getSelectionSet() == null) {
continue;
}
this.collectFields(parameters, field.getSelectionSet(), visitedFragments, subFields);
}
return newMergedSelectionSet().subFields(subFields).build();
}
代码示例来源:origin: castlemock/castlemock
private GraphQLRequestField getField(Field field){
final GraphQLRequestField requestField = new GraphQLRequestField();
final List<GraphQLRequestField> fields = new ArrayList<>();
final List<GraphQLRequestArgument> arguments = new ArrayList<>();
requestField.setName(field.getName());
requestField.setFields(fields);
if(field.getSelectionSet() != null && field.getSelectionSet().getSelections() != null){
for(Selection selection : field.getSelectionSet().getSelections()){
if(selection instanceof Field){
Field subField = (Field) selection;
GraphQLRequestField subRequestField = getField(subField);
fields.add(subRequestField);
}
}
}
for(Argument argument : field.getArguments()){
GraphQLRequestArgument requestArgument = getArgument(argument);
arguments.add(requestArgument);
}
return requestField;
}
代码示例来源:origin: com.graphql-java/graphql-java
@Override
public void checkField(Field field) {
GraphQLOutputType type = getValidationContext().getOutputType();
if (type == null) return;
if (isLeaf(type)) {
if (field.getSelectionSet() != null) {
String message = String.format("Sub selection not allowed on leaf type %s of field %s", type.getName(), field.getName());
addError(ValidationErrorType.SubSelectionNotAllowed, field.getSourceLocation(), message);
}
} else {
if (field.getSelectionSet() == null) {
String message = String.format("Sub selection required for type %s of field %s", type.getName(), field.getName());
addError(ValidationErrorType.SubSelectionRequired, field.getSourceLocation(), message);
}
}
}
}
代码示例来源:origin: com.graphql-java/graphql-java
@Override
public TraversalControl visitField(Field node, TraverserContext<Node> context) {
Field changedNode = node.transform(builder -> {
builder.arguments(sort(node.getArguments(), comparing(Argument::getName)));
builder.directives(sort(node.getDirectives(), comparing(Directive::getName)));
builder.selectionSet(sortSelectionSet(node.getSelectionSet()));
});
return changeNode(context, changedNode);
}
代码示例来源:origin: com.graphql-java/graphql-java
private Builder(Field existing) {
this.sourceLocation = existing.getSourceLocation();
this.comments = existing.getComments();
this.name = existing.getName();
this.alias = existing.getAlias();
this.arguments = existing.getArguments();
this.directives = existing.getDirectives();
this.selectionSet = existing.getSelectionSet();
this.ignoredChars = existing.getIgnoredChars();
}
代码示例来源:origin: com.graphql-java/graphql-java
private NodePrinter<Field> field() {
final String argSep = compactMode ? "," : ", ";
final String aliasSuffix = compactMode ? ":" : ": ";
return (out, node) -> {
String alias = wrap("", node.getAlias(), aliasSuffix);
String name = node.getName();
String arguments = wrap("(", join(node.getArguments(), argSep), ")");
String directives = directives(node.getDirectives());
String selectionSet = node(node.getSelectionSet());
out.printf("%s", spaced(
alias + name + arguments,
directives,
selectionSet
));
};
}
内容来源于网络,如有侵权,请联系作者删除!