introspection
Library for introspecting a GraphQL schema. The entry point method is getSchemaMap.
IntrospectionErrorβ
Defined in: packages/graphql/src/introspection.ts:51
Exampleβ
Extendsβ
Error
Constructorsβ
Constructorβ
new IntrospectionError(message?): IntrospectionError;
Defined in: node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1080
Parametersβ
message?β
string
Returnsβ
Inherited fromβ
Error.constructor;
Constructorβ
new IntrospectionError(message?, options?): IntrospectionError;
Defined in: node_modules/.bun/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1080
Parametersβ
message?β
string
options?β
ErrorOptions
Returnsβ
Inherited fromβ
Error.constructor;
_getFields()β
function _getFields<T, V>(
type,
processor?,
fallback?,
): Record<string, unknown> | V;
Defined in: packages/graphql/src/introspection.ts:312
Internal
Returns the fields from a GraphQL schema type.
see getOperation, getFields
Type Parametersβ
Tβ
T
Vβ
V
Parametersβ
typeβ
T
the GraphQL schema type to parse.
processor?β
(fieldMap) => V
optional callback function to parse the fields map.
fallback?β
V
optional fallback value, undefined if not set.
Returnsβ
Record<string, unknown> | V
a map of fields as k/v records, or fallback value if no fields available.
getDirective()β
function getDirective(entity, directives): GraphQLDirective[];
Defined in: packages/graphql/src/introspection.ts:223
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.
getDirectiveLocationForASTPath()β
function getDirectiveLocationForASTPath(appliedTo): DirectiveLocation;
Defined in: packages/graphql/src/introspection.ts:122
Parametersβ
appliedToβ
Maybe<ASTNode>
Returnsβ
DirectiveLocation
getFields()β
function getFields(type): unknown[];
Defined in: packages/graphql/src/introspection.ts:576
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.
getOperation()β
function getOperation(
operationType?,
operationKind?,
): Record<string, GraphQLOperationType>;
Defined in: packages/graphql/src/introspection.ts:539
Internal
Returns fields map for a GraphQL operation type (query, mutation, subscription...).
see getSchemaMap
Parametersβ
operationType?β
unknown
the operation type to parse.
operationKind?β
Maybe<OperationKind>
optional explicit operation kind.
Returnsβ
Record<string, GraphQLOperationType>
a map of fields as k/v records.
getSchemaMap()β
function getSchemaMap(schema): SchemaMap;
Defined in: packages/graphql/src/introspection.ts:654
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,
// }
// }
getTypeDirectiveArgValue()β
function getTypeDirectiveArgValue(
directive,
node,
argName,
): Maybe<string | Record<string, unknown>>;
Defined in: packages/graphql/src/introspection.ts:284
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
the GraphQL schema type to parse.
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.
getTypeDirectiveValues()β
function getTypeDirectiveValues(
directive,
type,
): Maybe<Record<string, unknown>>;
Defined in: packages/graphql/src/introspection.ts:253
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.
getTypeFromSchema()β
function getTypeFromSchema<T>(schema, type): Maybe<Record<string, T>>;
Defined in: packages/graphql/src/introspection.ts:67
Internal
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β
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β
getTypeName()β
function getTypeName(type, defaultName?): string;
Defined in: packages/graphql/src/introspection.ts:374
Resolves the name of a GraphQL schema type.
Parametersβ
typeβ
unknown
the GraphQL schema type to parse.
defaultName?β
string = ""
optional fallback value if the name resolution fails.
Returnsβ
string
the type's name, or defaultName.
hasAstNode()β
function hasAstNode<T>(node): node is AstNodeType<T>;
Defined in: packages/graphql/src/introspection.ts:115
Internal
Type guard for type with an AST node property.
Type Parametersβ
Tβ
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.
hasDirective()β
function hasDirective(entity, directives, fallback?): boolean;
Defined in: packages/graphql/src/introspection.ts:188
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.
isValidDirectiveLocation()β
function isValidDirectiveLocation(entity, directive): boolean;
Defined in: packages/graphql/src/introspection.ts:167
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.