use of graphql.schema.GraphQLSchemaElement in project graphql-java by graphql-java.
the class StronglyConnectedComponentsTopologicallySorted method stronglyConnect.
private void stronglyConnect(GraphQLSchemaElement v) {
nodeToIndex.put(v, index);
nodeToLowLink.put(v, index);
index++;
stack.push(v);
nodeToOnStack.put(v, true);
List<GraphQLSchemaElement> dependencies = reverseDependencies.get(v);
if (dependencies == null) {
dependencies = new ArrayList<>();
}
if (v instanceof GraphQLNamedType) {
String name = ((GraphQLNamedType) v).getName();
if (typeRefReverseDependencies.containsKey(name)) {
dependencies = new ArrayList<>(dependencies);
dependencies.addAll(typeRefReverseDependencies.get(name));
}
}
for (GraphQLSchemaElement w : dependencies) {
if (nodeToIndex.get(w) == null) {
stronglyConnect(w);
nodeToLowLink.put(v, Math.min(nodeToLowLink.get(v), nodeToLowLink.get(w)));
} else if (Boolean.TRUE.equals(nodeToOnStack.get(w))) {
nodeToLowLink.put(v, Math.min(nodeToLowLink.get(v), nodeToIndex.get(w)));
}
}
if (nodeToLowLink.get(v).equals(nodeToIndex.get(v))) {
Set<GraphQLSchemaElement> newSCC = new LinkedHashSet<>();
GraphQLSchemaElement w;
do {
w = stack.pop();
nodeToOnStack.put(w, false);
newSCC.add(w);
} while (w != v);
result.add(topologicallySort(newSCC));
}
}
use of graphql.schema.GraphQLSchemaElement in project graphql-java by graphql-java.
the class SchemaTransformExamples method example_commands.
void example_commands() {
GraphQLSchemaElement updatedElement = null;
GraphQLSchemaElement newElement = null;
GraphQLTypeVisitorStub visitor = new GraphQLTypeVisitorStub() {
@Override
public TraversalControl visitGraphQLObjectType(GraphQLObjectType objectType, TraverserContext<GraphQLSchemaElement> context) {
// changes the current element in the schema
changeNode(context, updatedElement);
// inserts a new element after the current one in the schema
insertAfter(context, newElement);
// inserts a new element before the current one in teh schema
insertBefore(context, newElement);
// deletes the current element from the schema
deleteNode(context);
return CONTINUE;
}
};
}
use of graphql.schema.GraphQLSchemaElement in project graphql-java by graphql-java.
the class SchemaPrinter method print.
public String print(List<GraphQLSchemaElement> elements) {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
for (GraphQLSchemaElement element : elements) {
if (element instanceof GraphQLDirective) {
out.print(print(((GraphQLDirective) element)));
} else if (element instanceof GraphQLType) {
printSchemaElement(out, element, DEFAULT_FIELD_VISIBILITY);
} else {
Assert.assertShouldNeverHappen("How did we miss a %s", element.getClass());
}
}
return sw.toString();
}
use of graphql.schema.GraphQLSchemaElement in project graphql-java by graphql-java.
the class SchemaPrinter method directiveString.
private String directiveString(GraphQLAppliedDirective directive) {
if (!options.getIncludeSchemaElement().test(directive)) {
return "";
}
if (!options.getIncludeDirective().test(directive.getName())) {
// @deprecated is special - we always print it if something is deprecated
if (!isDeprecatedDirective(directive)) {
return "";
}
}
StringBuilder sb = new StringBuilder();
sb.append("@").append(directive.getName());
Comparator<? super GraphQLSchemaElement> comparator = getComparator(GraphQLAppliedDirective.class, GraphQLAppliedDirectiveArgument.class);
List<GraphQLAppliedDirectiveArgument> args = directive.getArguments();
args = args.stream().filter(arg -> arg.getArgumentValue().isSet()).sorted(comparator).collect(toList());
if (!args.isEmpty()) {
sb.append("(");
for (int i = 0; i < args.size(); i++) {
GraphQLAppliedDirectiveArgument arg = args.get(i);
String argValue = null;
if (arg.hasSetValue()) {
argValue = printAst(arg.getArgumentValue(), arg.getType());
}
if (!isNullOrEmpty(argValue)) {
sb.append(arg.getName());
sb.append(" : ");
sb.append(argValue);
if (i < args.size() - 1) {
sb.append(", ");
}
}
}
sb.append(")");
}
return sb.toString();
}
use of graphql.schema.GraphQLSchemaElement in project graphql-java by graphql-java.
the class SchemaPrinter method argsString.
String argsString(Class<? extends GraphQLSchemaElement> parent, List<GraphQLArgument> arguments) {
boolean hasDescriptions = arguments.stream().anyMatch(this::hasDescription);
String halfPrefix = hasDescriptions ? " " : "";
String prefix = hasDescriptions ? " " : "";
int count = 0;
StringBuilder sb = new StringBuilder();
Comparator<? super GraphQLSchemaElement> comparator = getComparator(parent, GraphQLArgument.class);
arguments = arguments.stream().sorted(comparator).filter(options.getIncludeSchemaElement()).collect(toList());
for (GraphQLArgument argument : arguments) {
if (count == 0) {
sb.append("(");
} else {
sb.append(", ");
}
if (hasDescriptions) {
sb.append("\n");
}
sb.append(printComments(argument, prefix));
sb.append(prefix).append(argument.getName()).append(": ").append(typeString(argument.getType()));
if (argument.hasSetDefaultValue()) {
InputValueWithState defaultValue = argument.getArgumentDefaultValue();
sb.append(" = ");
sb.append(printAst(defaultValue, argument.getType()));
}
DirectivesUtil.toAppliedDirectives(argument).stream().filter(options.getIncludeSchemaElement()).map(this::directiveString).filter(it -> !it.isEmpty()).forEach(directiveString -> sb.append(" ").append(directiveString));
count++;
}
if (count > 0) {
if (hasDescriptions) {
sb.append("\n");
}
sb.append(halfPrefix).append(")");
}
return sb.toString();
}
Aggregations