Package graphql.introspection
Class Introspection
java.lang.Object
graphql.introspection.Introspection
GraphQl has a unique capability called Introspection that allow
consumers to inspect the system and discover the fields and types available and makes the system self documented.
Some security recommendations such as OWASP
recommend that introspection be disabled in production. The enabledJvmWide(boolean) method can be used to disable
introspection for the whole JVM or you can place INTROSPECTION_DISABLED into the GraphQLContext of a request
to disable introspection for that request.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GraphQLObjectTypestatic final GraphQLEnumTypestatic final GraphQLObjectTypestatic final GraphQLObjectTypestatic final GraphQLObjectTypestatic final GraphQLObjectTypestatic final GraphQLObjectTypestatic final GraphQLEnumTypestatic final StringPlacing a boolean value under this key in the per requestGraphQLContextwill enable or disable Introspection on that request.static final GraphQLFieldDefinitionstatic final IntrospectionDataFetcher<?> static final GraphQLFieldDefinitionstatic final IntrospectionDataFetcher<?> static final GraphQLFieldDefinitionstatic final IntrospectionDataFetcher<?> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCodeForIntrospectionTypes(GraphQLCodeRegistry.Builder codeRegistry) static GraphQLFieldDefinitionbuildSchemaField(GraphQLObjectType introspectionSchemaType) static GraphQLFieldDefinitionbuildTypeField(GraphQLObjectType introspectionSchemaType) static booleanenabledJvmWide(boolean enabled) This static method will enable / disable Introspection at a JVM wide level.static GraphQLFieldDefinitiongetFieldDef(GraphQLSchema schema, GraphQLCompositeType parentType, String fieldName) This will look up a field definition by name, and understand that fields like __typename and __schema are special and take precedence in field resolution.static GraphQLFieldDefinitiongetFieldDefinition(GraphQLSchema schema, GraphQLFieldsContainer parentType, String fieldName) This will look up a field definition by name, and understand that fields like __typename and __schema are special and take precedence in field resolutionstatic booleanstatic Optional<ExecutionResult> isIntrospectionSensible(MergedSelectionSet mergedSelectionSet, ExecutionContext executionContext) This will look in to the field selection set and see if there are introspection fields, and if there is,it checks if introspection should run, and if not it will return an erroredExecutionResultthat can be returned to the user.static booleanstatic booleanisIntrospectionTypes(String typeName)
-
Field Details
-
INTROSPECTION_DISABLED
Placing a boolean value under this key in the per requestGraphQLContextwill enable or disable Introspection on that request.- See Also:
-
__TypeKind
-
__InputValue
-
__Field
-
__EnumValue
-
__Type
-
__DirectiveLocation
-
__Directive
-
__Schema
-
SchemaMetaFieldDef
-
TypeMetaFieldDef
-
TypeNameMetaFieldDef
-
INTROSPECTION_SYSTEM_FIELDS
-
SchemaMetaFieldDefDataFetcher
-
TypeMetaFieldDefDataFetcher
-
TypeNameMetaFieldDefDataFetcher
-
-
Constructor Details
-
Introspection
public Introspection()
-
-
Method Details
-
enabledJvmWide
public static boolean enabledJvmWide(boolean enabled) This static method will enable / disable Introspection at a JVM wide level.- Parameters:
enabled- the flag indicating the desired enabled state- Returns:
- the previous state of enablement
-
isEnabledJvmWide
public static boolean isEnabledJvmWide()- Returns:
- true if Introspection is enabled at a JVM wide level or false otherwise
-
isIntrospectionSensible
public static Optional<ExecutionResult> isIntrospectionSensible(MergedSelectionSet mergedSelectionSet, ExecutionContext executionContext) This will look in to the field selection set and see if there are introspection fields, and if there is,it checks if introspection should run, and if not it will return an erroredExecutionResultthat can be returned to the user.- Parameters:
mergedSelectionSet- the fields to be executedexecutionContext- the execution context in play- Returns:
- an optional error result
-
addCodeForIntrospectionTypes
-
buildSchemaField
-
buildTypeField
-
isIntrospectionTypes
-
isIntrospectionTypes
-
getFieldDef
public static GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLCompositeType parentType, String fieldName) This will look up a field definition by name, and understand that fields like __typename and __schema are special and take precedence in field resolution. If the parent type is a union type, then the only field allowed is `__typename`.- Parameters:
schema- the schema to useparentType- the type of the parent objectfieldName- the field to look up- Returns:
- a field definition otherwise throws an assertion exception if it's null
-
getFieldDefinition
public static GraphQLFieldDefinition getFieldDefinition(GraphQLSchema schema, GraphQLFieldsContainer parentType, String fieldName) This will look up a field definition by name, and understand that fields like __typename and __schema are special and take precedence in field resolution- Parameters:
schema- the schema to useparentType- the type of the parentGraphQLFieldsContainerfieldName- the field to look up- Returns:
- a field definition otherwise throws an assertion exception if it's null
-