Package graphql.schema.idl
Class SchemaPrinter
- java.lang.Object
-
- graphql.schema.idl.SchemaPrinter
-
@PublicApi public class SchemaPrinter extends java.lang.Object
This can print an in memory GraphQL schema back to a logical schema definition
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SchemaPrinter.Options
Options to use when printing a schemaprivate static interface
SchemaPrinter.SchemaElementPrinter<T>
-
Field Summary
Fields Modifier and Type Field Description static java.util.function.Predicate<java.lang.String>
ExcludeGraphQLSpecifiedDirectivesPredicate
This predicate excludes all directives which are specified by the GraphQL Specification.private SchemaPrinter.Options
options
private java.util.Map<java.lang.Class<?>,SchemaPrinter.SchemaElementPrinter<?>>
printers
-
Constructor Summary
Constructors Constructor Description SchemaPrinter()
SchemaPrinter(SchemaPrinter.Options options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<GraphQLAppliedDirective>
addDeprecatedDirectiveIfNeeded(GraphQLDirectiveContainer directiveContainer)
(package private) java.lang.String
argsString(java.lang.Class<? extends GraphQLSchemaElement> parent, java.util.List<GraphQLArgument> arguments)
(package private) java.lang.String
argsString(java.util.List<GraphQLArgument> arguments)
private java.lang.String
comments(java.util.List<Comment> comments)
(package private) java.lang.String
description(java.lang.String runtimeDescription, Description descriptionAst)
private java.lang.String
directiveDefinition(GraphQLDirective directive)
private SchemaPrinter.SchemaElementPrinter<GraphQLDirective>
directivePrinter()
(package private) java.lang.String
directivesString(java.lang.Class<? extends GraphQLSchemaElement> parentType, boolean isDeprecated, GraphQLDirectiveContainer directiveContainer)
java.lang.String
directivesString(java.lang.Class<? extends GraphQLSchemaElement> parentType, GraphQLDirectiveContainer directiveContainer)
private java.lang.String
directivesString(java.lang.Class<? extends GraphQLSchemaElement> parentType, java.util.List<GraphQLAppliedDirective> directives)
private java.lang.String
directiveString(GraphQLAppliedDirective directive)
private SchemaPrinter.SchemaElementPrinter<GraphQLEnumType>
enumPrinter()
private java.lang.String
getAstDefinitionComments(java.lang.Object commentHolder)
private java.util.Comparator<? super GraphQLSchemaElement>
getComparator(java.lang.Class<? extends GraphQLSchemaElement> parentType, java.lang.Class<? extends GraphQLSchemaElement> elementType)
private java.lang.String
getDeprecationReason(GraphQLDirectiveContainer directiveContainer)
private java.lang.String
getDescription(java.lang.Object descriptionHolder)
private java.util.List<GraphQLDirective>
getSchemaDirectives(GraphQLSchema schema)
private boolean
hasAstDefinitionComments(java.lang.Object commentHolder)
private boolean
hasDeprecatedDirective(java.util.List<GraphQLAppliedDirective> directives)
private boolean
hasDescription(java.lang.Object descriptionHolder)
private SchemaPrinter.SchemaElementPrinter<GraphQLInputObjectType>
inputObjectPrinter()
private SchemaPrinter.SchemaElementPrinter<GraphQLInterfaceType>
interfacePrinter()
private boolean
isDeprecatedDirective(GraphQLAppliedDirective directive)
private boolean
isIntrospectionType(GraphQLNamedType type)
private static boolean
isNullOrEmpty(java.lang.String s)
private SchemaPrinter.SchemaElementPrinter<GraphQLObjectType>
objectPrinter()
java.lang.String
print(Document schemaIDL)
This can print an in memory GraphQL IDL document back to a logical schema definition.java.lang.String
print(GraphQLDirective graphQLDirective)
java.lang.String
print(GraphQLSchema schema)
This can print an in memory GraphQL schema back to a logical schema definitionjava.lang.String
print(GraphQLType type)
java.lang.String
print(java.util.List<GraphQLSchemaElement> elements)
private void
printAsAst(java.io.PrintWriter out, TypeDefinition<?> definition, java.util.List<? extends TypeDefinition<?>> extensions)
This will print out a runtime graphql schema element using its contained AST type definition.private static java.lang.String
printAst(InputValueWithState value, GraphQLInputType type)
private void
printComments(java.io.PrintWriter out, java.lang.Object graphQLType, java.lang.String prefix)
private java.lang.String
printComments(java.lang.Object graphQLType, java.lang.String prefix)
private <T> SchemaPrinter.SchemaElementPrinter<T>
printer(java.lang.Class<?> clazz)
private void
printFieldDefinitions(java.io.PrintWriter out, java.util.Comparator<? super GraphQLSchemaElement> comparator, java.util.List<GraphQLFieldDefinition> fieldDefinitions)
private void
printMultiLineDescription(java.io.PrintWriter out, java.lang.String prefix, java.util.List<java.lang.String> lines)
private void
printMultiLineHashDescription(java.io.PrintWriter out, java.lang.String prefix, java.util.List<java.lang.String> lines)
private void
printSchemaElement(java.io.PrintWriter out, GraphQLSchemaElement schemaElement, GraphqlFieldVisibility visibility)
private void
printSingleLineDescription(java.io.PrintWriter out, java.lang.String prefix, java.lang.String s)
private SchemaPrinter.SchemaElementPrinter<GraphQLScalarType>
scalarPrinter()
private SchemaPrinter.SchemaElementPrinter<GraphQLSchema>
schemaPrinter()
private boolean
shouldPrintAsAst(TypeDefinition<?> definition)
This will return true if the options say to use the AST and we have an AST elementprivate static java.lang.String
trimNewLineChars(java.lang.String s)
(package private) java.lang.String
typeString(GraphQLType rawType)
private SchemaPrinter.SchemaElementPrinter<GraphQLUnionType>
unionPrinter()
-
-
-
Field Detail
-
ExcludeGraphQLSpecifiedDirectivesPredicate
public static final java.util.function.Predicate<java.lang.String> ExcludeGraphQLSpecifiedDirectivesPredicate
This predicate excludes all directives which are specified by the GraphQL Specification. Printing these directives is optional.
-
printers
private final java.util.Map<java.lang.Class<?>,SchemaPrinter.SchemaElementPrinter<?>> printers
-
options
private final SchemaPrinter.Options options
-
-
Constructor Detail
-
SchemaPrinter
public SchemaPrinter()
-
SchemaPrinter
public SchemaPrinter(SchemaPrinter.Options options)
-
-
Method Detail
-
print
public java.lang.String print(Document schemaIDL)
This can print an in memory GraphQL IDL document back to a logical schema definition. If you want to turn a Introspection query result into a Document (and then into a printed schema) then useIntrospectionResultToSchema.createSchemaDefinition(java.util.Map)
first to get theDocument
and then print that.- Parameters:
schemaIDL
- the parsed schema IDL- Returns:
- the logical schema definition
-
print
public java.lang.String print(GraphQLSchema schema)
This can print an in memory GraphQL schema back to a logical schema definition- Parameters:
schema
- the schema in play- Returns:
- the logical schema definition
-
isIntrospectionType
private boolean isIntrospectionType(GraphQLNamedType type)
-
scalarPrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLScalarType> scalarPrinter()
-
enumPrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLEnumType> enumPrinter()
-
printFieldDefinitions
private void printFieldDefinitions(java.io.PrintWriter out, java.util.Comparator<? super GraphQLSchemaElement> comparator, java.util.List<GraphQLFieldDefinition> fieldDefinitions)
-
interfacePrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLInterfaceType> interfacePrinter()
-
unionPrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLUnionType> unionPrinter()
-
directivePrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLDirective> directivePrinter()
-
objectPrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLObjectType> objectPrinter()
-
inputObjectPrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLInputObjectType> inputObjectPrinter()
-
shouldPrintAsAst
private boolean shouldPrintAsAst(TypeDefinition<?> definition)
This will return true if the options say to use the AST and we have an AST element- Parameters:
definition
- the AST type definition- Returns:
- true if we should print using AST nodes
-
printAsAst
private void printAsAst(java.io.PrintWriter out, TypeDefinition<?> definition, java.util.List<? extends TypeDefinition<?>> extensions)
This will print out a runtime graphql schema element using its contained AST type definition. This must be guarded by a called toshouldPrintAsAst(TypeDefinition)
- Parameters:
out
- the output writerdefinition
- the AST type definitionextensions
- a list of type definition extensions
-
printAst
private static java.lang.String printAst(InputValueWithState value, GraphQLInputType type)
-
schemaPrinter
private SchemaPrinter.SchemaElementPrinter<GraphQLSchema> schemaPrinter()
-
getSchemaDirectives
private java.util.List<GraphQLDirective> getSchemaDirectives(GraphQLSchema schema)
-
typeString
java.lang.String typeString(GraphQLType rawType)
-
argsString
java.lang.String argsString(java.util.List<GraphQLArgument> arguments)
-
argsString
java.lang.String argsString(java.lang.Class<? extends GraphQLSchemaElement> parent, java.util.List<GraphQLArgument> arguments)
-
directivesString
public java.lang.String directivesString(java.lang.Class<? extends GraphQLSchemaElement> parentType, GraphQLDirectiveContainer directiveContainer)
-
directivesString
java.lang.String directivesString(java.lang.Class<? extends GraphQLSchemaElement> parentType, boolean isDeprecated, GraphQLDirectiveContainer directiveContainer)
-
directivesString
private java.lang.String directivesString(java.lang.Class<? extends GraphQLSchemaElement> parentType, java.util.List<GraphQLAppliedDirective> directives)
-
directiveString
private java.lang.String directiveString(GraphQLAppliedDirective directive)
-
isDeprecatedDirective
private boolean isDeprecatedDirective(GraphQLAppliedDirective directive)
-
hasDeprecatedDirective
private boolean hasDeprecatedDirective(java.util.List<GraphQLAppliedDirective> directives)
-
addDeprecatedDirectiveIfNeeded
private java.util.List<GraphQLAppliedDirective> addDeprecatedDirectiveIfNeeded(GraphQLDirectiveContainer directiveContainer)
-
getDeprecationReason
private java.lang.String getDeprecationReason(GraphQLDirectiveContainer directiveContainer)
-
directiveDefinition
private java.lang.String directiveDefinition(GraphQLDirective directive)
-
printer
private <T> SchemaPrinter.SchemaElementPrinter<T> printer(java.lang.Class<?> clazz)
-
print
public java.lang.String print(GraphQLType type)
-
print
public java.lang.String print(java.util.List<GraphQLSchemaElement> elements)
-
print
public java.lang.String print(GraphQLDirective graphQLDirective)
-
printSchemaElement
private void printSchemaElement(java.io.PrintWriter out, GraphQLSchemaElement schemaElement, GraphqlFieldVisibility visibility)
-
printComments
private java.lang.String printComments(java.lang.Object graphQLType, java.lang.String prefix)
-
printComments
private void printComments(java.io.PrintWriter out, java.lang.Object graphQLType, java.lang.String prefix)
-
printMultiLineHashDescription
private void printMultiLineHashDescription(java.io.PrintWriter out, java.lang.String prefix, java.util.List<java.lang.String> lines)
-
printMultiLineDescription
private void printMultiLineDescription(java.io.PrintWriter out, java.lang.String prefix, java.util.List<java.lang.String> lines)
-
printSingleLineDescription
private void printSingleLineDescription(java.io.PrintWriter out, java.lang.String prefix, java.lang.String s)
-
hasAstDefinitionComments
private boolean hasAstDefinitionComments(java.lang.Object commentHolder)
-
getAstDefinitionComments
private java.lang.String getAstDefinitionComments(java.lang.Object commentHolder)
-
comments
private java.lang.String comments(java.util.List<Comment> comments)
-
hasDescription
private boolean hasDescription(java.lang.Object descriptionHolder)
-
getDescription
private java.lang.String getDescription(java.lang.Object descriptionHolder)
-
description
java.lang.String description(java.lang.String runtimeDescription, Description descriptionAst)
-
getComparator
private java.util.Comparator<? super GraphQLSchemaElement> getComparator(java.lang.Class<? extends GraphQLSchemaElement> parentType, java.lang.Class<? extends GraphQLSchemaElement> elementType)
-
trimNewLineChars
private static java.lang.String trimNewLineChars(java.lang.String s)
-
isNullOrEmpty
private static boolean isNullOrEmpty(java.lang.String s)
-
-