Package graphql.schema.usage
Class SchemaUsage
- java.lang.Object
-
- graphql.schema.usage.SchemaUsage
-
@PublicApi public class SchemaUsage extends java.lang.Object
This class shows schema usage information. There are two aspects to this. To be strongly referenced, a schema element (directive or type) must some how be connected back to the root query, mutation or subscription type. It's possible to define types that reference other types but if they do not get used by a field / interface or union that itself leads back to the root types then it is not considered strongly references. Its reference counts however might be non-zero yet not be strongly referenced. For example given `type A { f : B } type B { f : A }` both types A and B will have non-zero counts but if no other type points to A or B that leads back to the root types then they are not strongly referenced types. Such types could be removed from the schema because there is no way to ever consume these types in a query. A common use case for this class is to find the types and directives in a schema that could in theory be removed because they are not useful.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Integer>
getArgumentReferenceCounts()
This shows how many times a type is referenced by an argument.java.util.Map<java.lang.String,java.lang.Integer>
getDirectiveReferenceCounts()
This shows how many times a directive is applied on some other schema element.java.util.Map<java.lang.String,java.lang.Integer>
getFieldReferenceCounts()
This shows how many times a type is referenced by either an input or output field.java.util.Map<java.lang.String,java.lang.Integer>
getInputFieldReferenceCounts()
This shows how many times a type is referenced by an input field.java.util.Map<java.lang.String,java.lang.Integer>
getInterfaceReferenceCounts()
This shows how many times an interface type is referenced as a member in some other object or interface type.java.util.Map<java.lang.String,java.lang.Integer>
getOutputFieldReferenceCounts()
This shows how many times a type is referenced by an output field.java.util.Map<java.lang.String,java.lang.Integer>
getUnionReferenceCounts()
This shows how many times an object type is referenced as a member in some other union type.java.util.Set<GraphQLNamedSchemaElement>
getUnReferencedElements(GraphQLSchema schema)
This returns all the unreferenced named elements in a schema.boolean
isStronglyReferenced(GraphQLSchema schema, java.lang.String elementName)
Returns true if the named element is strongly reference somewhere in the schema back to the root types such as the schema query, mutation or subscription types.
-
-
-
Method Detail
-
getFieldReferenceCounts
public java.util.Map<java.lang.String,java.lang.Integer> getFieldReferenceCounts()
This shows how many times a type is referenced by either an input or output field.- Returns:
- a map of type name to field reference counts
-
getOutputFieldReferenceCounts
public java.util.Map<java.lang.String,java.lang.Integer> getOutputFieldReferenceCounts()
This shows how many times a type is referenced by an output field.- Returns:
- a map of type name to output field reference counts
-
getInputFieldReferenceCounts
public java.util.Map<java.lang.String,java.lang.Integer> getInputFieldReferenceCounts()
This shows how many times a type is referenced by an input field.- Returns:
- a map of type name to input field reference counts
-
getArgumentReferenceCounts
public java.util.Map<java.lang.String,java.lang.Integer> getArgumentReferenceCounts()
This shows how many times a type is referenced by an argument.- Returns:
- a map of type name to argument reference counts
-
getInterfaceReferenceCounts
public java.util.Map<java.lang.String,java.lang.Integer> getInterfaceReferenceCounts()
This shows how many times an interface type is referenced as a member in some other object or interface type.- Returns:
- a map of interface type name to object or interface type reference counts
-
getUnionReferenceCounts
public java.util.Map<java.lang.String,java.lang.Integer> getUnionReferenceCounts()
This shows how many times an object type is referenced as a member in some other union type.- Returns:
- a map of object type name to union membership reference counts
-
getDirectiveReferenceCounts
public java.util.Map<java.lang.String,java.lang.Integer> getDirectiveReferenceCounts()
This shows how many times a directive is applied on some other schema element.- Returns:
- a map of directive name to applied directive counts
-
isStronglyReferenced
public boolean isStronglyReferenced(GraphQLSchema schema, java.lang.String elementName)
Returns true if the named element is strongly reference somewhere in the schema back to the root types such as the schema query, mutation or subscription types. Graphql specified scalar types, introspection types and directives are always counted as referenced, even if not used explicitly. Directives that are defined but never applied on any schema elements will not report as referenced.- Parameters:
schema
- the schema that contains the name typeelementName
- the element name to check- Returns:
- true if the element could be referenced
-
getUnReferencedElements
public java.util.Set<GraphQLNamedSchemaElement> getUnReferencedElements(GraphQLSchema schema)
This returns all the unreferenced named elements in a schema.- Parameters:
schema
- the schema to check- Returns:
- a set of the named schema elements where
isStronglyReferenced(GraphQLSchema, String)
returns false
-
-