UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

1 lines 19.3 kB
{"version":3,"file":"getIntrospectionQuery.js","sourceRoot":"","sources":["../../src/utilities/getIntrospectionQuery.ts"],"names":[],"mappings":"AAuGA,MAAM,UAAU,qBAAqB,CAAC,OAA8B;IAClE,MAAM,kBAAkB,GAAG;QACzB,YAAY,EAAE,IAAI;QAClB,cAAc,EAAE,KAAK;QACrB,qBAAqB,EAAE,KAAK;QAC5B,iBAAiB,EAAE,KAAK;QACxB,qBAAqB,EAAE,KAAK;QAC5B,gCAAgC,EAAE,KAAK;QACvC,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,CAAC;QACZ,GAAG,OAAO;KACX,CAAC;IAEF,MAAM,YAAY,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1E,MAAM,cAAc,GAAG,kBAAkB,CAAC,cAAc;QACtD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,qBAAqB;QACpE,CAAC,CAAC,cAAc;QAChB,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,iBAAiB;QAC5D,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,EAAE,CAAC;IAEP,SAAS,gBAAgB,CAAC,GAAW;QACnC,OAAO,kBAAkB,CAAC,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,CAAC;IACD,SAAS,gCAAgC,CAAC,GAAW;QACnD,OAAO,kBAAkB,CAAC,gCAAgC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACxE,CAAC;IACD,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,SAAS,MAAM,CAAC,KAAa,EAAE,MAAc;QAC3C,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACf,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;QACJ,CAAC;QACD,OAAO;EACT,MAAM;EACN,MAAM;EACN,MAAM,SAAS,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;EAC/C,MAAM,GAAG,CAAC;IACV,CAAC;IAED,OAAO;;;UAGC,iBAAiB;;;;;;;oBAOP,gCAAgC,CAC1C,2BAA2B,CAC5B;;YAEG,YAAY;YACZ,qBAAqB;YACrB,gCAAgC,CAAC,cAAc,CAAC;YAChD,gCAAgC,CAAC,mBAAmB,CAAC;;gBAEjD,gBAAgB,CAAC,2BAA2B,CAAC;;;;;;;;;;QAUrD,YAAY;QACZ,cAAc;QACd,KAAK;;;UAGH,YAAY;cACR,gBAAgB,CAAC,2BAA2B,CAAC;;;;;;;;;mBASxC,gBAAgB,CAAC,2BAA2B,CAAC;;;;;;;;UAQtD,YAAY;;;;;;;;;;;QAWd,YAAY;;;QAGZ,gBAAgB,CAAC,cAAc,CAAC;QAChC,gBAAgB,CAAC,mBAAmB,CAAC;;;;;YAKjC,MAAM,CAAC,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC;;GAEvD,CAAC;AACJ,CAAC","sourcesContent":["/** @category Introspection */\n\nimport type { Maybe } from '../jsutils/Maybe.ts';\n\nimport type { DirectiveLocation } from '../language/directiveLocation.ts';\n\nimport type { TypeKind } from '../type/introspection.ts';\n\n/** Options controlling which fields are included in the introspection query. */\nexport interface IntrospectionOptions {\n /**\n * Whether to include descriptions in the introspection result.\n * Default: true\n */\n descriptions?: boolean;\n\n /**\n * Whether to include `specifiedByURL` in the introspection result.\n * Default: false\n */\n specifiedByUrl?: boolean;\n\n /**\n * Whether to include `isRepeatable` flag on directives.\n * Default: false\n */\n directiveIsRepeatable?: boolean;\n\n /**\n * Whether to include `description` field on schema.\n * Default: false\n */\n schemaDescription?: boolean;\n\n /**\n * Whether target GraphQL server support deprecation of input values.\n * Default: false\n */\n inputValueDeprecation?: boolean;\n\n /**\n * Whether target GraphQL server supports deprecation of directives.\n * Default: false\n */\n experimentalDirectiveDeprecation?: boolean;\n\n /**\n * Whether target GraphQL server supports `@oneOf` input objects.\n * Default: false\n */\n oneOf?: boolean;\n\n /**\n * How deep to recurse into nested types, larger values will result in more\n * accurate results, but have a higher load on the server.\n * Some servers might restrict the maximum query depth or complexity.\n * If that's the case, try decreasing this value.\n *\n * Default: 9\n */\n typeDepth?: number;\n}\n\n/**\n * Produce the GraphQL query recommended for a full schema introspection.\n * Accepts optional IntrospectionOptions.\n * @param options - Optional configuration for this operation.\n * @returns The resolved introspection query.\n * @example\n * ```ts\n * // Generate the default introspection query.\n * import { getIntrospectionQuery } from 'graphql/utilities';\n *\n * const query = getIntrospectionQuery();\n *\n * query; // matches /__schema/\n * query; // matches /description/\n * query; // does not match /specifiedByURL/\n * ```\n * @example\n * ```ts\n * // This variant customizes optional introspection fields and nesting depth.\n * import { getIntrospectionQuery } from 'graphql/utilities';\n *\n * const query = getIntrospectionQuery({\n * descriptions: false,\n * specifiedByUrl: true,\n * directiveIsRepeatable: true,\n * schemaDescription: true,\n * inputValueDeprecation: true,\n * experimentalDirectiveDeprecation: true,\n * oneOf: true,\n * typeDepth: 3,\n * });\n *\n * query; // does not match /description/\n * query; // matches /specifiedByURL/\n * query; // matches /isRepeatable/\n * query; // matches /includeDeprecated: true/\n * query; // matches /isOneOf/\n * (query.match(/ofType/g)?.length ?? 0) > 0; // => true\n * ```\n */\nexport function getIntrospectionQuery(options?: IntrospectionOptions): string {\n const optionsWithDefault = {\n descriptions: true,\n specifiedByUrl: false,\n directiveIsRepeatable: false,\n schemaDescription: false,\n inputValueDeprecation: false,\n experimentalDirectiveDeprecation: false,\n oneOf: false,\n typeDepth: 9,\n ...options,\n };\n\n const descriptions = optionsWithDefault.descriptions ? 'description' : '';\n const specifiedByUrl = optionsWithDefault.specifiedByUrl\n ? 'specifiedByURL'\n : '';\n const directiveIsRepeatable = optionsWithDefault.directiveIsRepeatable\n ? 'isRepeatable'\n : '';\n const schemaDescription = optionsWithDefault.schemaDescription\n ? descriptions\n : '';\n\n function inputDeprecation(str: string) {\n return optionsWithDefault.inputValueDeprecation ? str : '';\n }\n function experimentalDirectiveDeprecation(str: string) {\n return optionsWithDefault.experimentalDirectiveDeprecation ? str : '';\n }\n const oneOf = optionsWithDefault.oneOf ? 'isOneOf' : '';\n function ofType(level: number, indent: string): string {\n if (level <= 0) {\n return '';\n }\n if (level > 100) {\n throw new Error(\n 'Please set typeDepth to a reasonable value between 0 and 100; the default is 9.',\n );\n }\n return `\n${indent}ofType {\n${indent} name\n${indent} kind${ofType(level - 1, indent + ' ')}\n${indent}}`;\n }\n\n return `\n query IntrospectionQuery {\n __schema {\n ${schemaDescription}\n queryType { name kind }\n mutationType { name kind }\n subscriptionType { name kind }\n types {\n ...FullType\n }\n directives${experimentalDirectiveDeprecation(\n '(includeDeprecated: true)',\n )} {\n name\n ${descriptions}\n ${directiveIsRepeatable}\n ${experimentalDirectiveDeprecation('isDeprecated')}\n ${experimentalDirectiveDeprecation('deprecationReason')}\n locations\n args${inputDeprecation('(includeDeprecated: true)')} {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n ${descriptions}\n ${specifiedByUrl}\n ${oneOf}\n fields(includeDeprecated: true) {\n name\n ${descriptions}\n args${inputDeprecation('(includeDeprecated: true)')} {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields${inputDeprecation('(includeDeprecated: true)')} {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n ${descriptions}\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n ${descriptions}\n type { ...TypeRef }\n defaultValue\n ${inputDeprecation('isDeprecated')}\n ${inputDeprecation('deprecationReason')}\n }\n\n fragment TypeRef on __Type {\n kind\n name${ofType(optionsWithDefault.typeDepth, ' ')}\n }\n `;\n}\n\n/** The result shape returned by a full introspection query. */\nexport interface IntrospectionQuery {\n /** The schema. */\n readonly __schema: IntrospectionSchema;\n}\n\n/** The introspection representation of a GraphQL schema. */\nexport interface IntrospectionSchema {\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** The root object type used for query operations. */\n readonly queryType: IntrospectionNamedTypeRef<IntrospectionObjectType>;\n /** The root object type used for mutation operations, if supported. */\n readonly mutationType: Maybe<\n IntrospectionNamedTypeRef<IntrospectionObjectType>\n >;\n /** The root object type used for subscription operations, if supported. */\n readonly subscriptionType: Maybe<\n IntrospectionNamedTypeRef<IntrospectionObjectType>\n >;\n /** Object types that belong to this union type. */\n readonly types: ReadonlyArray<IntrospectionType>;\n /** Directives available in this schema or applied to this AST node. */\n readonly directives: ReadonlyArray<IntrospectionDirective>;\n}\n\n/** Any introspection representation of a GraphQL type. */\nexport type IntrospectionType =\n | IntrospectionScalarType\n | IntrospectionObjectType\n | IntrospectionInterfaceType\n | IntrospectionUnionType\n | IntrospectionEnumType\n | IntrospectionInputObjectType;\n\n/** An introspection type that can appear in output position. */\nexport type IntrospectionOutputType =\n | IntrospectionScalarType\n | IntrospectionObjectType\n | IntrospectionInterfaceType\n | IntrospectionUnionType\n | IntrospectionEnumType;\n\n/** An introspection type that can appear in input position. */\nexport type IntrospectionInputType =\n | IntrospectionScalarType\n | IntrospectionEnumType\n | IntrospectionInputObjectType;\n\n/** The introspection representation of a scalar type. */\nexport interface IntrospectionScalarType {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.SCALAR;\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** URL identifying the behavior specified for this custom scalar. */\n readonly specifiedByURL?: Maybe<string>;\n}\n\n/** The introspection representation of an object type. */\nexport interface IntrospectionObjectType {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.OBJECT;\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Fields declared by this object, interface, input object, or literal. */\n readonly fields: ReadonlyArray<IntrospectionField>;\n /** Interfaces implemented by this object or interface type. */\n readonly interfaces: ReadonlyArray<\n IntrospectionNamedTypeRef<IntrospectionInterfaceType>\n >;\n}\n\n/** The introspection representation of an interface type. */\nexport interface IntrospectionInterfaceType {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.INTERFACE;\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Fields declared by this object, interface, input object, or literal. */\n readonly fields: ReadonlyArray<IntrospectionField>;\n /** Interfaces implemented by this object or interface type. */\n readonly interfaces: ReadonlyArray<\n IntrospectionNamedTypeRef<IntrospectionInterfaceType>\n >;\n /** Object types that may be returned for this abstract type. */\n readonly possibleTypes: ReadonlyArray<\n IntrospectionNamedTypeRef<IntrospectionObjectType>\n >;\n}\n\n/** The introspection representation of a union type. */\nexport interface IntrospectionUnionType {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.UNION;\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Object types that may be returned for this abstract type. */\n readonly possibleTypes: ReadonlyArray<\n IntrospectionNamedTypeRef<IntrospectionObjectType>\n >;\n}\n\n/** The introspection representation of an enum type. */\nexport interface IntrospectionEnumType {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.ENUM;\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Values declared by this enum type. */\n readonly enumValues: ReadonlyArray<IntrospectionEnumValue>;\n}\n\n/** The introspection representation of an input object type. */\nexport interface IntrospectionInputObjectType {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.INPUT_OBJECT;\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Input fields declared by this input object type. */\n readonly inputFields: ReadonlyArray<IntrospectionInputValue>;\n /** Whether this input object uses the experimental OneOf input object semantics. */\n readonly isOneOf: boolean;\n}\n\n/**\n * The introspection representation of a list type reference.\n * @typeParam T - The introspection type reference wrapped by this list type reference.\n */\nexport interface IntrospectionListTypeRef<\n T extends IntrospectionTypeRef = IntrospectionTypeRef,\n> {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.LIST;\n /** The type wrapped by this list or non-null type. */\n readonly ofType: T;\n}\n\n/**\n * The introspection representation of a non-null type reference.\n * @typeParam T - The introspection type reference wrapped by this non-null type reference.\n */\nexport interface IntrospectionNonNullTypeRef<\n T extends IntrospectionTypeRef = IntrospectionTypeRef,\n> {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: typeof TypeKind.NON_NULL;\n /** The type wrapped by this list or non-null type. */\n readonly ofType: T;\n}\n\n/** Any introspection representation of a type reference. */\nexport type IntrospectionTypeRef =\n | IntrospectionNamedTypeRef\n | IntrospectionListTypeRef\n | IntrospectionNonNullTypeRef<\n IntrospectionNamedTypeRef | IntrospectionListTypeRef\n >;\n\n/** An introspection type reference that can appear in output position. */\nexport type IntrospectionOutputTypeRef =\n | IntrospectionNamedTypeRef<IntrospectionOutputType>\n | IntrospectionListTypeRef<IntrospectionOutputTypeRef>\n | IntrospectionNonNullTypeRef<\n | IntrospectionNamedTypeRef<IntrospectionOutputType>\n | IntrospectionListTypeRef<IntrospectionOutputTypeRef>\n >;\n\n/** An introspection type reference that can appear in input position. */\nexport type IntrospectionInputTypeRef =\n | IntrospectionNamedTypeRef<IntrospectionInputType>\n | IntrospectionListTypeRef<IntrospectionInputTypeRef>\n | IntrospectionNonNullTypeRef<\n | IntrospectionNamedTypeRef<IntrospectionInputType>\n | IntrospectionListTypeRef<IntrospectionInputTypeRef>\n >;\n\n/**\n * The introspection representation of a named type reference.\n * @typeParam T - The introspection type represented by this named type reference.\n */\nexport interface IntrospectionNamedTypeRef<\n T extends IntrospectionType = IntrospectionType,\n> {\n /** The introspection kind discriminator for this type reference or type. */\n readonly kind: T['kind'];\n /** The GraphQL name for this schema element. */\n readonly name: string;\n}\n\n/** The introspection representation of a field. */\nexport interface IntrospectionField {\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Arguments accepted by this field or directive. */\n readonly args: ReadonlyArray<IntrospectionInputValue>;\n /** The GraphQL type reference or runtime type for this element. */\n readonly type: IntrospectionOutputTypeRef;\n /** Whether this field, argument, enum value, or input value is deprecated. */\n readonly isDeprecated: boolean;\n /** Reason this element is deprecated, if one was provided. */\n readonly deprecationReason: Maybe<string>;\n}\n\n/** The introspection representation of an argument or input field. */\nexport interface IntrospectionInputValue {\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** The GraphQL type reference or runtime type for this element. */\n readonly type: IntrospectionInputTypeRef;\n /** Default value used when no explicit value is supplied. */\n readonly defaultValue: Maybe<string>;\n /** Whether this field, argument, enum value, or input value is deprecated. */\n readonly isDeprecated?: boolean;\n /** Reason this element is deprecated, if one was provided. */\n readonly deprecationReason?: Maybe<string>;\n}\n\n/** The introspection representation of an enum value. */\nexport interface IntrospectionEnumValue {\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Whether this field, argument, enum value, or input value is deprecated. */\n readonly isDeprecated: boolean;\n /** Reason this element is deprecated, if one was provided. */\n readonly deprecationReason: Maybe<string>;\n}\n\n/** The introspection representation of a directive. */\nexport interface IntrospectionDirective {\n /** The GraphQL name for this schema element. */\n readonly name: string;\n /** Human-readable description for this schema element, if provided. */\n readonly description?: Maybe<string>;\n /** Whether this directive may appear more than once at the same location. */\n readonly isRepeatable?: boolean;\n /** Whether this field, argument, enum value, or input value is deprecated. */\n readonly isDeprecated?: boolean;\n /** Reason this element is deprecated, if one was provided. */\n readonly deprecationReason?: Maybe<string>;\n /** Locations where this directive may be applied. */\n readonly locations: ReadonlyArray<DirectiveLocation>;\n /** Arguments accepted by this field or directive. */\n readonly args: ReadonlyArray<IntrospectionInputValue>;\n}\n"]}