Package graphql.introspection
Class IntrospectionWithDirectivesSupport
- java.lang.Object
-
- graphql.introspection.IntrospectionWithDirectivesSupport
-
@PublicApi public class IntrospectionWithDirectivesSupport extends java.lang.Object
The graphql specification does not allow you to retrieve the directives and their argument values that are present on types, enums, fields and input fields, so this class allows you to change the schema and enhance the Introspection types to contain this information. This allows you to get a directive say like `@example(argName : "someValue")` that is on a field or type at introspection time and act on it. This class takes a predicate that allows you to filter the directives you want to expose to the world. An `appliedDirectives` field is added and this contains extra fields that hold the directives and their applied values. For example the `__Field` type becomes as follows:type __Field { name: String! // other fields ... appliedDirectives: [_AppliedDirective!]! // NEW FIELD } type _AppliedDirective { // NEW INTROSPECTION TYPE name: String! args: [_DirectiveArgument!]! } type _DirectiveArgument { // NEW INTROSPECTION TYPE name: String! value: String! }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
IntrospectionWithDirectivesSupport.DirectivePredicate
A callback which allows you to decide what directives may be included in introspection extensionsstatic interface
IntrospectionWithDirectivesSupport.DirectivePredicateEnvironment
The parameter environment on a call toIntrospectionWithDirectivesSupport.DirectivePredicate
-
Field Summary
Fields Modifier and Type Field Description private IntrospectionWithDirectivesSupport.DirectivePredicate
directivePredicate
private java.util.Set<java.lang.String>
INTROSPECTION_ELEMENTS
private java.lang.String
typePrefix
-
Constructor Summary
Constructors Constructor Description IntrospectionWithDirectivesSupport()
This version lists all directives on a schema elementIntrospectionWithDirectivesSupport(IntrospectionWithDirectivesSupport.DirectivePredicate directivePredicate)
This version allows you to filter what directives are listed via the provided predicateIntrospectionWithDirectivesSupport(IntrospectionWithDirectivesSupport.DirectivePredicate directivePredicate, java.lang.String typePrefix)
This version allows you to filter what directives are listed via the provided predicate Some graphql systems (graphql-js in 2021) cannot cope with extra types starting with `__` so we use a `_` as a prefix by default.
-
Method Summary
-
-
-
Field Detail
-
directivePredicate
private final IntrospectionWithDirectivesSupport.DirectivePredicate directivePredicate
-
typePrefix
private final java.lang.String typePrefix
-
INTROSPECTION_ELEMENTS
private final java.util.Set<java.lang.String> INTROSPECTION_ELEMENTS
-
-
Constructor Detail
-
IntrospectionWithDirectivesSupport
public IntrospectionWithDirectivesSupport()
This version lists all directives on a schema element
-
IntrospectionWithDirectivesSupport
public IntrospectionWithDirectivesSupport(IntrospectionWithDirectivesSupport.DirectivePredicate directivePredicate)
This version allows you to filter what directives are listed via the provided predicate- Parameters:
directivePredicate
- the filtering predicate to decide what directives are shown
-
IntrospectionWithDirectivesSupport
public IntrospectionWithDirectivesSupport(IntrospectionWithDirectivesSupport.DirectivePredicate directivePredicate, java.lang.String typePrefix)
This version allows you to filter what directives are listed via the provided predicate Some graphql systems (graphql-js in 2021) cannot cope with extra types starting with `__` so we use a `_` as a prefix by default. You can supply your own prefix via this constructor. See: https://github.com/graphql-java/graphql-java/pull/2221 for more details- Parameters:
directivePredicate
- the filtering predicate to decide what directives are showntypePrefix
- the prefix to put on the new `AppliedDirectives` type
-
-
Method Detail
-
apply
public GraphQLSchema apply(GraphQLSchema schema)
This will transform the schema to have the new extension shapes- Parameters:
schema
- the original schema- Returns:
- the transformed schema with new extension types and fields in it for Introspection
-
mkDirectiveArgumentType
private GraphQLObjectType mkDirectiveArgumentType(java.lang.String name)
-
mkAppliedDirectiveType
private GraphQLObjectType mkAppliedDirectiveType(java.lang.String name, GraphQLType directiveArgumentType)
-
addDirectiveDefinitionFilter
private GraphQLSchema addDirectiveDefinitionFilter(GraphQLSchema schema)
-
addAppliedDirectives
private GraphQLObjectType addAppliedDirectives(GraphQLObjectType originalType, GraphQLCodeRegistry.Builder codeRegistry, GraphQLObjectType appliedDirectiveType, GraphQLObjectType directiveArgumentType)
-
filterDirectives
private java.util.List<GraphQLDirective> filterDirectives(GraphQLSchema schema, boolean isDefinedDirective, GraphQLDirectiveContainer container, java.util.List<GraphQLDirective> directives)
-
filterAppliedDirectives
private java.util.List<GraphQLAppliedDirective> filterAppliedDirectives(GraphQLSchema schema, boolean isDefinedDirective, GraphQLDirectiveContainer container, java.util.List<GraphQLAppliedDirective> directives)
-
buildDirectivePredicateEnv
@NotNull private @NotNull IntrospectionWithDirectivesSupport.DirectivePredicateEnvironment buildDirectivePredicateEnv(GraphQLSchema schema, boolean isDefinedDirective, GraphQLDirectiveContainer container, java.lang.String directiveName)
-
-