introspection
Library for introspecting a GraphQL schema. The entry point method is getSchemaMap.
IntrospectionErrorβ
Extendsβ
Error
Constructorsβ
new IntrospectionError()β
new IntrospectionError(message?): IntrospectionError
Parametersβ
β’ message?: string
Returnsβ
Inherited fromβ
Error.constructor
Defined inβ
node_modules/typescript/lib/lib.es5.d.ts:1082
new IntrospectionError()β
new IntrospectionError(message?, options?): IntrospectionError
Parametersβ
β’ message?: string
β’ options?: ErrorOptions
Returnsβ
Inherited fromβ
Error.constructor
Defined inβ
node_modules/typescript/lib/lib.es5.d.ts:1082
_getFields()β
function _getFields<T, V>(
type,
processor?,
fallback?): GraphQLFieldMap<unknown, unknown> | GraphQLInputFieldMap | V | GraphQLObjectType<any, any>
Returns the fields from a GraphQL schema type.
see getOperation, getFields
Type Parametersβ
β’ T
β’ V
Parametersβ
β’ type: T
the GraphQL schema type to parse.
β’ processor?
optional callback function to parse the fields map.
β’ fallback?: V
optional fallback value, undefined
if not set.
Returnsβ
GraphQLFieldMap
<unknown
, unknown
> | GraphQLInputFieldMap
| V
| GraphQLObjectType
<any
, any
>
a map of fields as k/v records, or fallback
value if no fields available.
Defined inβ
packages/graphql/src/introspection.ts:317
getDirective()β
function getDirective(entity, directives): GraphQLDirective[]
Returns a schema entity's list of directives matching a defined set.
Parametersβ
β’ entity: unknown
a GraphQL schema entity.
β’ directives: Maybe
<GraphQLDirective
[]>
a directive name or a list of directive names.
Returnsβ
GraphQLDirective
[]
a list of GraphQL directives matching the set, else false
.
Defined inβ
packages/graphql/src/introspection.ts:226
getDirectiveLocationForASTPath()β
function getDirectiveLocationForASTPath(appliedTo): DirectiveLocation
Parametersβ
β’ appliedTo: Maybe
<ASTNode
>
Returnsβ
DirectiveLocation
Defined inβ
packages/graphql/src/introspection.ts:113
getFields()β
function getFields(type): unknown[]
Returns fields map for a GraphQL schema type.
see getSchemaMap
Parametersβ
β’ type: unknown
the GraphQL schema type to parse.
Returnsβ
unknown
[]
a list of fields of type object.
Defined inβ
packages/graphql/src/introspection.ts:386
getOperation()β
function getOperation(operationType?): Record<string, GraphQLOperationType>
Returns fields map for a GraphQL operation type (query, mutation, subscription...).
see getSchemaMap
Parametersβ
β’ operationType?: unknown
the operation type to parse.
Returnsβ
Record
<string
, GraphQLOperationType
>
a map of fields as k/v records.
Defined inβ
packages/graphql/src/introspection.ts:362
getSchemaMap()β
function getSchemaMap(schema): SchemaMap
Returns an introspection map of the GraphQL schema. This is the entry point for GraphQL-Markdown schema parsing features.
Parametersβ
β’ schema: Maybe
<GraphQLSchema
>
a GraphQL schema.
Returnsβ
SchemaMap
a schema map by GraphQL entities (see SchemaEntity).
Exampleβ
import { buildSchema } from "graphql";
import { getSchemaMap } from "@graphql-markdown/utils/graphql";
const schema = buildSchema(`
interface Record {
id: String!
}
type StudyItem implements Record {
id: String!
subject: String!
duration: Int!
}
type Query {
getStudyItems(subject: String): [StudyItem!]
getStudyItem(id: String!): StudyItem
}
type Mutation {
addStudyItem(subject: String!, duration: Int!): StudyItem
}
type Subscription {
listStudyItems: [StudyItem!]
}
`);
const schemaTypeMap = getSchemaMap(schema);
// expected result: {
// queries: {
// getStudyItems: GraphQLField,
// getStudyItem: GraphQLField,
// },
// mutations: {
// addStudyItem: GraphQLField,
// },
// subscriptions: {
// listStudyItems: GraphQLField,
// }
// directives: {
// include: GraphQLDirective,
// skip: GraphQLDirective,
// deprecated: GraphQLDirective,
// specifiedBy: GraphQLDirective,
// objects: {
// StudyItem: GraphQLObjectType,
// unions: {},
// interfaces: {
// Record: GraphQLInterfaceType,
// enums: {},
// inputs: {},
// scalars: {
// String: GraphQLScalarType,
// Int: GraphQLScalarType,
// Boolean: GraphQLScalarType,
// }
// }
Defined inβ
packages/graphql/src/introspection.ts:496
getTypeDirectiveArgValue()β
function getTypeDirectiveArgValue(
directive,
node,
argName): Maybe<string | Record<string, unknown>>
Returns one directive's argument's value linked to a GraphQL schema type. It calls getTypeDirectiveValues and returns a matching record.
Parametersβ
β’ directive: GraphQLDirective
a GraphQL directive defined in the schema.
β’ node: unknown
β’ argName: string
the name of the GraphQL directive argument to fetch the value from.
Returnsβ
Maybe
<string
| Record
<string
, unknown
>>
a record k/v with argName
as key and the argument's value.
Defined inβ
packages/graphql/src/introspection.ts:289
getTypeDirectiveValues()β
function getTypeDirectiveValues(directive, type): Maybe<Record<string, unknown>>
Returns all directive's arguments' values linked to a GraphQL schema type.
Parametersβ
β’ directive: GraphQLDirective
a GraphQL directive defined in the schema.
β’ type: unknown
the GraphQL schema type to parse.
Returnsβ
Maybe
<Record
<string
, unknown
>>
a record k/v with arguments' name as keys and arguments' value.
Defined inβ
packages/graphql/src/introspection.ts:258
getTypeFromSchema()β
function getTypeFromSchema<T>(schema, type): Maybe<Record<string, T>>
Returns a map of GraphQL named types from a schema for a defined GraphQL type.
When parsing the entities, internal GraphQL entities (starting with __
) are excluded.
Type Parametersβ
β’ T
Parametersβ
β’ schema: Maybe
<GraphQLSchema
>
a GraphQL schema.
β’ type: unknown
a GraphQL type, eg GraphQLObjectType
.
Returnsβ
Maybe
<Record
<string
, T
>>
a map of GraphQL named types for the matching GraphQL type, or undefined if no match.
Seeβ
Defined inβ
packages/graphql/src/introspection.ts:61
getTypeName()β
function getTypeName(type, defaultName): string
Resolves the name of a GraphQL schema type.
Parametersβ
β’ type: unknown
β’ defaultName: string
= ""
optional fallback value if the name resolution fails.
Returnsβ
string
the type's name, or defaultName
.
Defined inβ
packages/graphql/src/introspection.ts:409
hasAstNode()β
function hasAstNode<T>(node): node is AstNodeType<T>
Type guard for type with an AST node property.
Type Parametersβ
β’ T
Parametersβ
β’ node: T
a GraphQL schema named type.
Returnsβ
node is AstNodeType<T>
true
if the entity has an AST node property, else false
.
Defined inβ
packages/graphql/src/introspection.ts:109
hasDirective()β
function hasDirective(
entity,
directives,
fallback): boolean
Checks if a schema entity as a directive belonging to a defined set.
Parametersβ
β’ entity: unknown
a GraphQL schema entity.
β’ directives: Maybe
<GraphQLDirective
[]>
a directive name or a list of directive names.
β’ fallback: boolean
= false
default value if the entity type is not a valid location for directives.
Returnsβ
boolean
true
if the entity has at least one directive matching, else false
.
Defined inβ
packages/graphql/src/introspection.ts:188
isValidDirectiveLocation()β
function isValidDirectiveLocation(entity, directive): boolean
Check if a directive can be applied to specific schema entity location.
Parametersβ
β’ entity: unknown
a GraphQL schema entity.
β’ directive: GraphQLDirective
a directive name.
Returnsβ
boolean
true
if the entity is a valid directive location, else false
.
Defined inβ
packages/graphql/src/introspection.ts:167