private NodePrinter<Type> type() { return (out, node) -> out.print(type(node)); }
private NodePrinter<OperationTypeDefinition> operationTypeDefinition() { String nameTypeSep = compactMode ? ":" : ": "; return (out, node) -> out.printf("%s%s%s", node.getName(), nameTypeSep, type(node.getTypeName())); }
private String type(Type type) { if (type instanceof NonNullType) { NonNullType inner = (NonNullType) type; return wrap("", type(inner.getType()), "!"); } else if (type instanceof ListType) { ListType inner = (ListType) type; return wrap("[", type(inner.getType()), "]"); } else { TypeName inner = (TypeName) type; return inner.getName(); } }
private NodePrinter<VariableDefinition> variableDefinition() { String nameTypeSep = compactMode ? ":" : ": "; String defaultValueEquals = compactMode ? "=" : " = "; return (out, node) -> out.printf("$%s%s%s%s", node.getName(), nameTypeSep, type(node.getType()), wrap(defaultValueEquals, node.getDefaultValue(), "") ); }
private NodePrinter<FragmentDefinition> fragmentDefinition() { return (out, node) -> { String name = node.getName(); String typeCondition = type(node.getTypeCondition()); String directives = directives(node.getDirectives()); String selectionSet = node(node.getSelectionSet()); out.printf("fragment %s on %s ", name, typeCondition); out.printf("%s", directives + selectionSet); }; }
printers.put(InterfaceTypeExtensionDefinition.class, interfaceTypeExtensionDefinition()); printers.put(IntValue.class, value()); printers.put(ListType.class, type()); printers.put(NonNullType.class, type()); printers.put(ObjectField.class, objectField()); printers.put(ObjectTypeDefinition.class, objectTypeDefinition()); printers.put(SelectionSet.class, selectionSet()); printers.put(StringValue.class, value()); printers.put(TypeName.class, type()); printers.put(UnionTypeDefinition.class, unionTypeDefinition()); printers.put(UnionTypeExtensionDefinition.class, unionTypeExtensionDefinition());
private NodePrinter<InputValueDefinition> inputValueDefinition() { String nameTypeSep = compactMode ? ":" : ": "; String defaultValueEquals = compactMode ? "=" : "= "; return (out, node) -> { Value defaultValue = node.getDefaultValue(); out.printf("%s", comments(node)); out.printf("%s", spaced( node.getName() + nameTypeSep + type(node.getType()), wrap(defaultValueEquals, defaultValue, ""), directives(node.getDirectives()) ) ); }; }
private NodePrinter<InlineFragment> inlineFragment() { return (out, node) -> { TypeName typeName = node.getTypeCondition(); //Inline fragments may not have a type condition String typeCondition = typeName == null ? "" : wrap("on ", type(typeName), ""); String directives = directives(node.getDirectives()); String selectionSet = node(node.getSelectionSet()); out.printf("%s", comments(node)); out.printf("%s", spaced( "...", typeCondition, directives, selectionSet )); }; }
private NodePrinter<FieldDefinition> fieldDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { out.printf("%s", comments(node)); String args; if (hasComments(node.getInputValueDefinitions()) && !compactMode) { args = join(node.getInputValueDefinitions(), "\n"); out.printf("%s", node.getName() + wrap("(\n", args, "\n)") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } else { args = join(node.getInputValueDefinitions(), argSep); out.printf("%s", node.getName() + wrap("(", args, ")") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } }; }
private NodePrinter<Type> type() { return (out, node) -> out.print(type(node)); }
private NodePrinter<OperationTypeDefinition> operationTypeDefinition() { String nameTypeSep = compactMode ? ":" : ": "; return (out, node) -> out.printf("%s%s%s", node.getName(), nameTypeSep, type(node.getTypeName())); }
private String type(Type type) { if (type instanceof NonNullType) { NonNullType inner = (NonNullType) type; return wrap("", type(inner.getType()), "!"); } else if (type instanceof ListType) { ListType inner = (ListType) type; return wrap("[", type(inner.getType()), "]"); } else { TypeName inner = (TypeName) type; return inner.getName(); } }
private NodePrinter<VariableDefinition> variableDefinition() { String nameTypeSep = compactMode ? ":" : ": "; String defaultValueEquals = compactMode ? "=" : " = "; return (out, node) -> out.printf("$%s%s%s%s", node.getName(), nameTypeSep, type(node.getType()), wrap(defaultValueEquals, node.getDefaultValue(), "") ); }
private NodePrinter<FragmentDefinition> fragmentDefinition() { return (out, node) -> { String name = node.getName(); String typeCondition = type(node.getTypeCondition()); String directives = directives(node.getDirectives()); String selectionSet = node(node.getSelectionSet()); out.printf("fragment %s on %s ", name, typeCondition); out.printf("%s", directives + selectionSet); }; }
printers.put(InterfaceTypeExtensionDefinition.class, interfaceTypeExtensionDefinition()); printers.put(IntValue.class, value()); printers.put(ListType.class, type()); printers.put(NonNullType.class, type()); printers.put(ObjectField.class, objectField()); printers.put(ObjectTypeDefinition.class, objectTypeDefinition()); printers.put(SelectionSet.class, selectionSet()); printers.put(StringValue.class, value()); printers.put(TypeName.class, type()); printers.put(UnionTypeDefinition.class, unionTypeDefinition()); printers.put(UnionTypeExtensionDefinition.class, unionTypeExtensionDefinition());
private NodePrinter<InputValueDefinition> inputValueDefinition() { String nameTypeSep = compactMode ? ":" : ": "; String defaultValueEquals = compactMode ? "=" : "= "; return (out, node) -> { Value defaultValue = node.getDefaultValue(); out.printf("%s", comments(node)); out.printf("%s", spaced( node.getName() + nameTypeSep + type(node.getType()), wrap(defaultValueEquals, defaultValue, ""), directives(node.getDirectives()) ) ); }; }
private NodePrinter<InlineFragment> inlineFragment() { return (out, node) -> { TypeName typeName = node.getTypeCondition(); //Inline fragments may not have a type condition String typeCondition = typeName == null ? "" : wrap("on ", type(typeName), ""); String directives = directives(node.getDirectives()); String selectionSet = node(node.getSelectionSet()); out.printf("%s", comments(node)); out.printf("%s", spaced( "...", typeCondition, directives, selectionSet )); }; }
private NodePrinter<FieldDefinition> fieldDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { out.printf("%s", comments(node)); String args; if (hasComments(node.getInputValueDefinitions()) && !compactMode) { args = join(node.getInputValueDefinitions(), "\n"); out.printf("%s", node.getName() + wrap("(\n", args, "\n)") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } else { args = join(node.getInputValueDefinitions(), argSep); out.printf("%s", node.getName() + wrap("(", args, ")") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } }; }