graphql
Version:
A Query Language and Runtime which can target any service.
1,575 lines • 144 kB
text/typescript
/** @category Types */
import type { Maybe } from "../jsutils/Maybe.mjs";
import type { ObjMap } from "../jsutils/ObjMap.mjs";
import type { Path } from "../jsutils/Path.mjs";
import type { PromiseOrValue } from "../jsutils/PromiseOrValue.mjs";
import type { ConstValueNode, EnumTypeDefinitionNode, EnumTypeExtensionNode, EnumValueDefinitionNode, FieldDefinitionNode, FieldNode, FragmentDefinitionNode, InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, OperationDefinitionNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode, UnionTypeDefinitionNode, UnionTypeExtensionNode, ValueNode } from "../language/ast.mjs";
import type { GraphQLVariableSignature } from "../execution/getVariableSignature.mjs";
import type { VariableValues } from "../execution/values.mjs";
import type { GraphQLDirective } from "./directives.mjs";
import type { GraphQLSchema } from "./schema.mjs";
/** These are all of the possible kinds of types. */
export type GraphQLType = GraphQLNamedType | GraphQLWrappingType;
/**
* Returns true when the value is any GraphQL type.
* @param type - The GraphQL type to inspect.
* @returns True when the value is any GraphQL type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { GraphQLList, GraphQLString, isType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Query {
* name: String
* }
* `);
*
* isType(GraphQLString); // => true
* isType(new GraphQLList(GraphQLString)); // => true
* isType(schema.getType('Query')); // => true
* isType('String'); // => false
* ```
*/
export declare function isType(type: unknown): type is GraphQLType;
/**
* Returns the value as a GraphQL type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Query {
* name: String
* }
* `);
*
* const queryType = assertType(schema.getType('Query'));
*
* queryType.toString(); // => 'Query'
* assertType('Query'); // throws an error
* ```
*/
export declare function assertType(type: unknown): GraphQLType;
/**
* There are predicates for each kind of GraphQL type.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLScalarType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isScalarType } from 'graphql/type';
*
* const schema = buildSchema(`
* scalar DateTime
*
* type Query {
* createdAt: DateTime
* }
* `);
*
* isScalarType(schema.getType('DateTime')); // => true
* isScalarType(schema.getType('Query')); // => false
* ```
*/
export declare function isScalarType(type: unknown): type is GraphQLScalarType;
/**
* Returns the value as a GraphQLScalarType, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLScalarType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertScalarType } from 'graphql/type';
*
* const schema = buildSchema(`
* scalar DateTime
*
* type Query {
* createdAt: DateTime
* }
* `);
*
* const dateTimeType = assertScalarType(schema.getType('DateTime'));
*
* dateTimeType.name; // => 'DateTime'
* assertScalarType(schema.getType('Query')); // throws an error
* ```
*/
export declare function assertScalarType(type: unknown): GraphQLScalarType;
/**
* Returns true when the value is a GraphQLObjectType.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLObjectType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isObjectType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type User {
* name: String
* }
*
* type Query {
* user: User
* }
* `);
*
* isObjectType(schema.getType('User')); // => true
* isObjectType(schema.getType('ReviewInput')); // => false
* ```
*/
export declare function isObjectType(type: unknown): type is GraphQLObjectType;
/**
* Returns the value as a GraphQLObjectType, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLObjectType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertObjectType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type User {
* name: String
* }
*
* type Query {
* user: User
* }
* `);
*
* const userType = assertObjectType(schema.getType('User'));
*
* Object.keys(userType.getFields()); // => ['name']
* assertObjectType(schema.getType('ReviewInput')); // throws an error
* ```
*/
export declare function assertObjectType(type: unknown): GraphQLObjectType;
/**
* Returns true when the value is a resolved GraphQL field definition.
* @param field - Value to inspect.
* @returns True when the value is a GraphQLField.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isField } from 'graphql/type';
*
* const schema = buildSchema('type Query { greeting: String }');
* const field = schema.getQueryType().getFields().greeting;
*
* isField(field); // => true
* isField(schema.getQueryType()); // => false
* ```
*/
export declare function isField(field: unknown): field is GraphQLField;
/**
* Returns the value as a GraphQLField, or throws if it is not one.
* @param field - Value to inspect.
* @returns The value typed as a GraphQLField.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertField } from 'graphql/type';
*
* const schema = buildSchema('type Query { greeting: String }');
* const field = assertField(schema.getQueryType().getFields().greeting);
*
* field.name; // => 'greeting'
* assertField(schema.getQueryType()); // throws an error
* ```
*/
export declare function assertField(field: unknown): GraphQLField;
/**
* Returns true when the value is a resolved GraphQL argument definition.
* @param arg - Value to inspect.
* @returns True when the value is a GraphQLArgument.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isArgument } from 'graphql/type';
*
* const schema = buildSchema('type Query { greeting(name: String): String }');
* const arg = schema.getQueryType().getFields().greeting.args[0];
*
* isArgument(arg); // => true
* isArgument(schema.getQueryType()); // => false
* ```
*/
export declare function isArgument(arg: unknown): arg is GraphQLArgument;
/**
* Returns the value as a GraphQLArgument, or throws if it is not one.
* @param arg - Value to inspect.
* @returns The value typed as a GraphQLArgument.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertArgument } from 'graphql/type';
*
* const schema = buildSchema('type Query { greeting(name: String): String }');
* const arg = assertArgument(schema.getQueryType().getFields().greeting.args[0]);
*
* arg.name; // => 'name'
* assertArgument(schema.getQueryType()); // throws an error
* ```
*/
export declare function assertArgument(arg: unknown): GraphQLArgument;
/**
* Returns true when the value is a GraphQLInterfaceType.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLInterfaceType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isInterfaceType } from 'graphql/type';
*
* const schema = buildSchema(`
* interface Node {
* id: ID!
* }
*
* type User implements Node {
* id: ID!
* }
*
* type Query {
* node: Node
* }
* `);
*
* isInterfaceType(schema.getType('Node')); // => true
* isInterfaceType(schema.getType('User')); // => false
* ```
*/
export declare function isInterfaceType(type: unknown): type is GraphQLInterfaceType;
/**
* Returns the value as a GraphQLInterfaceType, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLInterfaceType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertInterfaceType } from 'graphql/type';
*
* const schema = buildSchema(`
* interface Node {
* id: ID!
* }
*
* type User implements Node {
* id: ID!
* }
*
* type Query {
* node: Node
* }
* `);
*
* const nodeType = assertInterfaceType(schema.getType('Node'));
*
* nodeType.name; // => 'Node'
* assertInterfaceType(schema.getType('User')); // throws an error
* ```
*/
export declare function assertInterfaceType(type: unknown): GraphQLInterfaceType;
/**
* Returns true when the value is a GraphQLUnionType.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLUnionType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isUnionType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Photo {
* url: String!
* }
*
* type Video {
* url: String!
* }
*
* union Media = Photo | Video
*
* type Query {
* media: [Media]
* }
* `);
*
* isUnionType(schema.getType('Media')); // => true
* isUnionType(schema.getType('Photo')); // => false
* ```
*/
export declare function isUnionType(type: unknown): type is GraphQLUnionType;
/**
* Returns the value as a GraphQLUnionType, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLUnionType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertUnionType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Photo {
* url: String!
* }
*
* type Video {
* url: String!
* }
*
* union Media = Photo | Video
*
* type Query {
* media: [Media]
* }
* `);
*
* const mediaType = assertUnionType(schema.getType('Media'));
*
* mediaType.getTypes().map((type) => type.name); // => ['Photo', 'Video']
* assertUnionType(schema.getType('Photo')); // throws an error
* ```
*/
export declare function assertUnionType(type: unknown): GraphQLUnionType;
/**
* Returns true when the value is a GraphQLEnumType.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLEnumType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isEnumType } from 'graphql/type';
*
* const schema = buildSchema(`
* enum Episode {
* NEW_HOPE
* EMPIRE
* }
*
* type Query {
* favoriteEpisode: Episode
* }
* `);
*
* isEnumType(schema.getType('Episode')); // => true
* isEnumType(schema.getType('Query')); // => false
* ```
*/
export declare function isEnumType(type: unknown): type is GraphQLEnumType;
/**
* Returns the value as a GraphQLEnumType, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLEnumType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertEnumType } from 'graphql/type';
*
* const schema = buildSchema(`
* enum Episode {
* NEW_HOPE
* EMPIRE
* }
*
* type Query {
* favoriteEpisode: Episode
* }
* `);
*
* const episodeType = assertEnumType(schema.getType('Episode'));
*
* episodeType.getValues().map((value) => value.name); // => ['NEW_HOPE', 'EMPIRE']
* assertEnumType(schema.getType('Query')); // throws an error
* ```
*/
export declare function assertEnumType(type: unknown): GraphQLEnumType;
/**
* Returns true when the value is a resolved GraphQL enum value definition.
* @param value - Value to inspect.
* @returns True when the value is a GraphQLEnumValue.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertEnumType, isEnumValue } from 'graphql/type';
*
* const schema = buildSchema(
* 'enum Episode { NEW_HOPE } type Query { episode: Episode }',
* );
* const enumValue = assertEnumType(schema.getType('Episode')).getValues()[0];
*
* isEnumValue(enumValue); // => true
* isEnumValue(schema.getType('Episode')); // => false
* ```
*/
export declare function isEnumValue(value: unknown): value is GraphQLEnumValue;
/**
* Returns the value as a GraphQLEnumValue, or throws if it is not one.
* @param value - Value to inspect.
* @returns The value typed as a GraphQLEnumValue.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertEnumType, assertEnumValue } from 'graphql/type';
*
* const schema = buildSchema(
* 'enum Episode { NEW_HOPE } type Query { episode: Episode }',
* );
* const enumValue = assertEnumValue(
* assertEnumType(schema.getType('Episode')).getValues()[0],
* );
*
* enumValue.name; // => 'NEW_HOPE'
* assertEnumValue(schema.getType('Episode')); // throws an error
* ```
*/
export declare function assertEnumValue(value: unknown): GraphQLEnumValue;
/**
* Returns true when the value is a GraphQLInputObjectType.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLInputObjectType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isInputObjectType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* review(input: ReviewInput): Review
* }
* `);
*
* isInputObjectType(schema.getType('ReviewInput')); // => true
* isInputObjectType(schema.getType('Review')); // => false
* ```
*/
export declare function isInputObjectType(type: unknown): type is GraphQLInputObjectType;
/**
* Returns the value as a GraphQLInputObjectType, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLInputObjectType.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertInputObjectType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* review(input: ReviewInput): Review
* }
* `);
*
* const inputType = assertInputObjectType(schema.getType('ReviewInput'));
*
* Object.keys(inputType.getFields()); // => ['stars']
* assertInputObjectType(schema.getType('Review')); // throws an error
* ```
*/
export declare function assertInputObjectType(type: unknown): GraphQLInputObjectType;
/**
* Returns true when the value is a resolved GraphQL input field definition.
* @param field - Value to inspect.
* @returns True when the value is a GraphQLInputField.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertInputObjectType, isInputField } from 'graphql/type';
*
* const schema = buildSchema(
* 'input ReviewInput { stars: Int } type Query { ok: Boolean }',
* );
* const inputField = assertInputObjectType(
* schema.getType('ReviewInput'),
* ).getFields().stars;
*
* isInputField(inputField); // => true
* isInputField(schema.getQueryType()); // => false
* ```
*/
export declare function isInputField(field: unknown): field is GraphQLInputField;
/**
* Returns the value as a GraphQLInputField, or throws if it is not one.
* @param field - Value to inspect.
* @returns The value typed as a GraphQLInputField.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertInputField, assertInputObjectType } from 'graphql/type';
*
* const schema = buildSchema(
* 'input ReviewInput { stars: Int } type Query { ok: Boolean }',
* );
* const inputField = assertInputField(
* assertInputObjectType(schema.getType('ReviewInput')).getFields().stars,
* );
*
* inputField.name; // => 'stars'
* assertInputField(schema.getQueryType()); // throws an error
* ```
*/
export declare function assertInputField(field: unknown): GraphQLInputField;
/**
* Returns true when the value is a GraphQLList.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLList.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { GraphQLList, GraphQLString, isListType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Query {
* tags: [String!]!
* }
* `);
*
* const tagsField = schema.getQueryType()?.getFields().tags;
*
* isListType(new GraphQLList(GraphQLString)); // => true
* isListType(GraphQLString); // => false
* isListType(tagsField?.type); // => false
* ```
*/
export declare function isListType(type: GraphQLInputType): type is GraphQLList<GraphQLInputType>;
/**
* Returns true when the output type is a GraphQLList.
* @param type - The GraphQL output type to inspect.
* @returns True when the output type is a list type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { getNullableType, isListType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Query {
* tags: [String!]!
* }
* `);
*
* const tagsField = schema.getQueryType()?.getFields().tags;
* const nullableTagsType = getNullableType(tagsField?.type);
*
* isListType(nullableTagsType); // => true
* ```
*/
export declare function isListType(type: GraphQLOutputType): type is GraphQLList<GraphQLOutputType>;
/**
* Returns true when the value is a GraphQLList.
* @param type - The value to inspect.
* @returns True when the value is a list type.
* @example
* ```ts
* import { isListType } from 'graphql/type';
*
* isListType('[String]'); // => false
* isListType(null); // => false
* ```
*/
export declare function isListType(type: unknown): type is GraphQLList<GraphQLType>;
/**
* Returns the value as a GraphQLList, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLList.
* @example
* ```ts
* import { GraphQLList, GraphQLString, assertListType } from 'graphql/type';
*
* const listType = assertListType(new GraphQLList(GraphQLString));
*
* listType.ofType; // => GraphQLString
* assertListType(GraphQLString); // throws an error
* ```
*/
export declare function assertListType(type: unknown): GraphQLList<GraphQLType>;
/**
* Returns true when the value is a GraphQLNonNull.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQLNonNull.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { GraphQLNonNull, GraphQLString, isNonNullType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Query {
* name: String!
* nickname: String
* }
* `);
*
* const fields = schema.getQueryType()?.getFields();
*
* isNonNullType(new GraphQLNonNull(GraphQLString)); // => true
* isNonNullType(fields?.name.type); // => true
* isNonNullType(fields?.nickname.type); // => false
* ```
*/
export declare function isNonNullType(type: GraphQLInputType): type is GraphQLNonNull<GraphQLNullableInputType>;
/**
* Returns true when the output type is a GraphQLNonNull.
* @param type - The GraphQL output type to inspect.
* @returns True when the output type is a non-null type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isNonNullType } from 'graphql/type';
*
* const schema = buildSchema(`
* type Query {
* name: String!
* nickname: String
* }
* `);
*
* const fields = schema.getQueryType()?.getFields();
*
* isNonNullType(fields?.name.type); // => true
* isNonNullType(fields?.nickname.type); // => false
* ```
*/
export declare function isNonNullType(type: GraphQLOutputType): type is GraphQLNonNull<GraphQLNullableOutputType>;
/**
* Returns true when the value is a GraphQLNonNull.
* @param type - The value to inspect.
* @returns True when the value is a non-null type.
* @example
* ```ts
* import { isNonNullType } from 'graphql/type';
*
* isNonNullType('String!'); // => false
* isNonNullType(null); // => false
* ```
*/
export declare function isNonNullType(type: unknown): type is GraphQLNonNull<GraphQLNullableType>;
/**
* Returns the value as a GraphQLNonNull, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQLNonNull.
* @example
* ```ts
* import { GraphQLNonNull, GraphQLString, assertNonNullType } from 'graphql/type';
*
* const nonNullType = assertNonNullType(new GraphQLNonNull(GraphQLString));
*
* nonNullType.ofType; // => GraphQLString
* assertNonNullType(GraphQLString); // throws an error
* ```
*/
export declare function assertNonNullType(type: unknown): GraphQLNonNull<GraphQLNullableType>;
/** These types may be used as input types for arguments and directives. */
export type GraphQLNullableInputType = GraphQLNamedInputType | GraphQLList<GraphQLInputType>;
/** These types may be used as input types for arguments and directives. */
export type GraphQLInputType = GraphQLNullableInputType | GraphQLNonNull<GraphQLNullableInputType>;
/**
* Returns true when the value can be used as a GraphQL input type.
* @param type - The GraphQL type to inspect.
* @returns True when the value can be used as a GraphQL input type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isInputType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* review(input: ReviewInput): Review
* }
* `);
*
* isInputType(schema.getType('ReviewInput')); // => true
* isInputType(schema.getType('Review')); // => false
* ```
*/
export declare function isInputType(type: unknown): type is GraphQLInputType;
/**
* Returns the value as a GraphQL input type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL input type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertInputType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* review(input: ReviewInput): Review
* }
* `);
*
* const inputType = assertInputType(schema.getType('ReviewInput'));
*
* inputType.toString(); // => 'ReviewInput'
* assertInputType(schema.getType('Review')); // throws an error
* ```
*/
export declare function assertInputType(type: unknown): GraphQLInputType;
/** These types may be used as output types as the result of fields. */
export type GraphQLNullableOutputType = GraphQLNamedOutputType | GraphQLList<GraphQLOutputType>;
/** These types may be used as output types as the result of fields. */
export type GraphQLOutputType = GraphQLNullableOutputType | GraphQLNonNull<GraphQLNullableOutputType>;
/**
* Returns true when the value can be used as a GraphQL output type.
* @param type - The GraphQL type to inspect.
* @returns True when the value can be used as a GraphQL output type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isOutputType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* review(input: ReviewInput): Review
* }
* `);
*
* isOutputType(schema.getType('Review')); // => true
* isOutputType(schema.getType('ReviewInput')); // => false
* ```
*/
export declare function isOutputType(type: unknown): type is GraphQLOutputType;
/**
* Returns the value as a GraphQL output type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL output type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertOutputType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* review(input: ReviewInput): Review
* }
* `);
*
* const outputType = assertOutputType(schema.getType('Review'));
*
* outputType.toString(); // => 'Review'
* assertOutputType(schema.getType('ReviewInput')); // throws an error
* ```
*/
export declare function assertOutputType(type: unknown): GraphQLOutputType;
/** These types may describe types which may be leaf values. */
export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType;
/**
* Returns true when the value is a GraphQL scalar or enum type.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQL scalar or enum type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isLeafType } from 'graphql/type';
*
* const schema = buildSchema(`
* enum Episode {
* NEW_HOPE
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* episode: Episode
* review: Review
* }
* `);
*
* isLeafType(schema.getType('Episode')); // => true
* isLeafType(schema.getType('String')); // => true
* isLeafType(schema.getType('Review')); // => false
* ```
*/
export declare function isLeafType(type: unknown): type is GraphQLLeafType;
/**
* Returns the value as a GraphQL leaf type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL leaf type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertLeafType } from 'graphql/type';
*
* const schema = buildSchema(`
* enum Episode {
* NEW_HOPE
* }
*
* type Review {
* stars: Int!
* }
*
* type Query {
* episode: Episode
* review: Review
* }
* `);
*
* const episodeType = assertLeafType(schema.getType('Episode'));
*
* episodeType.toString(); // => 'Episode'
* assertLeafType(schema.getType('Review')); // throws an error
* ```
*/
export declare function assertLeafType(type: unknown): GraphQLLeafType;
/** These types may describe the parent context of a selection set. */
export type GraphQLCompositeType = GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType;
/**
* Returns true when the value is a GraphQL object, interface, or union type.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQL object, interface, or union type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isCompositeType } from 'graphql/type';
*
* const schema = buildSchema(`
* interface Node {
* id: ID!
* }
*
* type User implements Node {
* id: ID!
* }
*
* union SearchResult = User
*
* type Query {
* node: Node
* search: [SearchResult]
* }
* `);
*
* isCompositeType(schema.getType('User')); // => true
* isCompositeType(schema.getType('Node')); // => true
* isCompositeType(schema.getType('SearchResult')); // => true
* isCompositeType(schema.getType('String')); // => false
* ```
*/
export declare function isCompositeType(type: unknown): type is GraphQLCompositeType;
/**
* Returns the value as a GraphQL composite type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL composite type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertCompositeType } from 'graphql/type';
*
* const schema = buildSchema(`
* interface Node {
* id: ID!
* }
*
* type User implements Node {
* id: ID!
* }
*
* type Query {
* node: Node
* }
* `);
*
* const userType = assertCompositeType(schema.getType('User'));
*
* userType.toString(); // => 'User'
* assertCompositeType(schema.getType('String')); // throws an error
* ```
*/
export declare function assertCompositeType(type: unknown): GraphQLCompositeType;
/** These types may describe the parent context of a selection set. */
export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType;
/**
* Returns true when the value is a GraphQL interface or union type.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQL interface or union type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { isAbstractType } from 'graphql/type';
*
* const schema = buildSchema(`
* interface Node {
* id: ID!
* }
*
* type User implements Node {
* id: ID!
* }
*
* union SearchResult = User
*
* type Query {
* node: Node
* search: [SearchResult]
* }
* `);
*
* isAbstractType(schema.getType('Node')); // => true
* isAbstractType(schema.getType('SearchResult')); // => true
* isAbstractType(schema.getType('User')); // => false
* ```
*/
export declare function isAbstractType(type: unknown): type is GraphQLAbstractType;
/**
* Returns the value as a GraphQL abstract type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL abstract type.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { assertAbstractType } from 'graphql/type';
*
* const schema = buildSchema(`
* interface Node {
* id: ID!
* }
*
* type User implements Node {
* id: ID!
* }
*
* type Query {
* node: Node
* }
* `);
*
* const nodeType = assertAbstractType(schema.getType('Node'));
*
* nodeType.toString(); // => 'Node'
* assertAbstractType(schema.getType('User')); // throws an error
* ```
*/
export declare function assertAbstractType(type: unknown): GraphQLAbstractType;
/**
* List Type Wrapper
*
* A list is a wrapping type which points to another type.
* Lists are often created within the context of defining the fields of
* an object type.
* @typeParam T - The GraphQL type wrapped by this list type.
* @example
* ```ts
* const PersonType = new GraphQLObjectType({
* name: 'Person',
* fields: () => ({
* parents: { type: new GraphQLList(PersonType) },
* children: { type: new GraphQLList(PersonType) },
* }),
* });
* ```
*/
export declare class GraphQLList<T extends GraphQLType> implements GraphQLSchemaElement {
/** The type wrapped by this list or non-null type. */
readonly ofType: T;
private readonly __GraphQLListTypeBrand;
/**
* Creates a GraphQLList instance.
* @param ofType - The type to wrap.
* @example
* ```ts
* import { GraphQLList, GraphQLString } from 'graphql/type';
*
* const stringList = new GraphQLList(GraphQLString);
*
* stringList.ofType; // => GraphQLString
* String(stringList); // => '[String]'
* ```
*/
constructor(ofType: T);
/**
* Returns the value used by `Object.prototype.toString`.
* @returns The built-in string tag for this object.
*/
get [Symbol.toStringTag](): string;
/**
* Returns this wrapping type as a GraphQL type-reference string.
* @returns The GraphQL type-reference string.
* @example
* ```ts
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
*
* const stringList = new GraphQLList(GraphQLString);
* const requiredStringList = new GraphQLList(new GraphQLNonNull(GraphQLString));
*
* stringList.toString(); // => '[String]'
* requiredStringList.toString(); // => '[String!]'
* ```
*/
toString(): string;
/**
* Returns the JSON representation used when this object is serialized.
* @returns The JSON-serializable representation.
* @example
* ```ts
* import { GraphQLList, GraphQLString } from 'graphql/type';
*
* const stringList = new GraphQLList(GraphQLString);
*
* stringList.toJSON(); // => '[String]'
* JSON.stringify({ type: stringList }); // => '{"type":"[String]"}'
* ```
*/
toJSON(): string;
}
/**
* Non-Null Type Wrapper
*
* A non-null is a wrapping type which points to another type.
* Non-null types enforce that their values are never null and can ensure
* an error is raised if this ever occurs during a request. It is useful for
* fields which you can make a strong guarantee on non-nullability, for example
* usually the id field of a database row will never be null.
* @typeParam T - The nullable GraphQL type wrapped by this non-null type.
* @example
* ```ts
* const RowType = new GraphQLObjectType({
* name: 'Row',
* fields: () => ({
* id: { type: new GraphQLNonNull(GraphQLString) },
* }),
* });
* ```
*
* Note: the enforcement of non-nullability occurs within the executor.
*/
export declare class GraphQLNonNull<T extends GraphQLNullableType> implements GraphQLSchemaElement {
/** The type wrapped by this list or non-null type. */
readonly ofType: T;
private readonly __GraphQLNonNullTypeBrand;
/**
* Creates a GraphQLNonNull instance.
* @param ofType - The type to wrap.
* @example
* ```ts
* import { GraphQLNonNull, GraphQLString } from 'graphql/type';
*
* const requiredString = new GraphQLNonNull(GraphQLString);
*
* requiredString.ofType; // => GraphQLString
* String(requiredString); // => 'String!'
* ```
*/
constructor(ofType: T);
/**
* Returns the value used by `Object.prototype.toString`.
* @returns The built-in string tag for this object.
*/
get [Symbol.toStringTag](): string;
/**
* Returns this wrapping type as a GraphQL type-reference string.
* @returns The GraphQL type-reference string.
* @example
* ```ts
* import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
*
* const requiredString = new GraphQLNonNull(GraphQLString);
* const requiredStringList = new GraphQLNonNull(new GraphQLList(GraphQLString));
*
* requiredString.toString(); // => 'String!'
* requiredStringList.toString(); // => '[String]!'
* ```
*/
toString(): string;
/**
* Returns the JSON representation used when this object is serialized.
* @returns The JSON-serializable representation.
* @example
* ```ts
* import { GraphQLNonNull, GraphQLString } from 'graphql/type';
*
* const requiredString = new GraphQLNonNull(GraphQLString);
*
* requiredString.toJSON(); // => 'String!'
* JSON.stringify({ type: requiredString }); // => '{"type":"String!"}'
* ```
*/
toJSON(): string;
}
/** These types wrap and modify other types */
export type GraphQLWrappingType = GraphQLList<GraphQLType> | GraphQLNonNull<GraphQLNullableType>;
/**
* Returns true when the value is a GraphQL list or non-null wrapper type.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQL list or non-null wrapper type.
* @example
* ```ts
* import {
* GraphQLList,
* GraphQLNonNull,
* GraphQLString,
* isWrappingType,
* } from 'graphql/type';
*
* isWrappingType(new GraphQLList(GraphQLString)); // => true
* isWrappingType(new GraphQLNonNull(GraphQLString)); // => true
* isWrappingType(GraphQLString); // => false
* ```
*/
export declare function isWrappingType(type: unknown): type is GraphQLWrappingType;
/**
* Returns the value as a GraphQL wrapping type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL wrapping type.
* @example
* ```ts
* import { GraphQLList, GraphQLString, assertWrappingType } from 'graphql/type';
*
* const wrappingType = assertWrappingType(new GraphQLList(GraphQLString));
*
* wrappingType.toString(); // => '[String]'
* assertWrappingType(GraphQLString); // throws an error
* ```
*/
export declare function assertWrappingType(type: unknown): GraphQLWrappingType;
/** These types can all accept null as a value. */
export type GraphQLNullableType = GraphQLNamedType | GraphQLList<GraphQLType>;
/**
* Returns true when the value is a GraphQL type that can accept null.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQL type that can accept null.
* @example
* ```ts
* import { GraphQLNonNull, GraphQLString, isNullableType } from 'graphql/type';
*
* isNullableType(GraphQLString); // => true
* isNullableType(new GraphQLNonNull(GraphQLString)); // => false
* isNullableType(null); // => false
* ```
*/
export declare function isNullableType(type: unknown): type is GraphQLNullableType;
/**
* Returns the value as a nullable GraphQL type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a nullable GraphQL type.
* @example
* ```ts
* import {
* GraphQLNonNull,
* GraphQLString,
* assertNullableType,
* } from 'graphql/type';
*
* const nullableType = assertNullableType(GraphQLString);
*
* nullableType; // => GraphQLString
* assertNullableType(new GraphQLNonNull(GraphQLString)); // throws an error
* ```
*/
export declare function assertNullableType(type: unknown): GraphQLNullableType;
/**
* Returns the nullable type.
* @param type - The GraphQL type to inspect.
* @returns The nullable type after removing one non-null wrapper, if present.
* @example
* ```ts
* import { getNullableType } from 'graphql/type';
*
* getNullableType(null); // => undefined
* getNullableType(undefined); // => undefined
* ```
*/
export declare function getNullableType(type: undefined | null): void;
/**
* Returns the nullable type after removing one non-null wrapper.
* @param type - A nullable type or non-null wrapper.
* @returns The nullable type after removing one non-null wrapper, if present.
* @typeParam T - The nullable GraphQL type returned after removing one non-null wrapper.
* @example
* ```ts
* import {
* GraphQLList,
* GraphQLNonNull,
* GraphQLString,
* getNullableType,
* } from 'graphql/type';
*
* const requiredString = new GraphQLNonNull(GraphQLString);
* const stringList = new GraphQLList(GraphQLString);
*
* getNullableType(requiredString); // => GraphQLString
* getNullableType(stringList); // => stringList
* ```
*/
export declare function getNullableType<T extends GraphQLNullableType>(type: T | GraphQLNonNull<T>): T;
/**
* Returns the nullable type after removing one non-null wrapper.
* @param type - The GraphQL type to inspect.
* @returns The nullable type after removing one non-null wrapper, if present.
* @example
* ```ts
* import {
* GraphQLList,
* GraphQLNonNull,
* GraphQLString,
* getNullableType,
* } from 'graphql/type';
*
* const requiredStringList = new GraphQLNonNull(new GraphQLList(GraphQLString));
*
* getNullableType(requiredStringList).toString(); // => '[String]'
* getNullableType(GraphQLString); // => GraphQLString
* ```
*/
export declare function getNullableType(type: Maybe<GraphQLType>): GraphQLNullableType | undefined;
/** These named types do not include modifiers like List or NonNull. */
export type GraphQLNamedType = GraphQLNamedInputType | GraphQLNamedOutputType;
/** A named GraphQL type that can be used as an input type. */
export type GraphQLNamedInputType = GraphQLScalarType | GraphQLEnumType | GraphQLInputObjectType;
/** A named GraphQL type that can be used as an output type. */
export type GraphQLNamedOutputType = GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType;
/**
* Returns true when the value is a GraphQL named type.
* @param type - The GraphQL type to inspect.
* @returns True when the value is a GraphQL named type.
* @example
* ```ts
* import { GraphQLList, GraphQLString, isNamedType } from 'graphql/type';
*
* isNamedType(GraphQLString); // => true
* isNamedType(new GraphQLList(GraphQLString)); // => false
* isNamedType(null); // => false
* ```
*/
export declare function isNamedType(type: unknown): type is GraphQLNamedType;
/**
* Returns the value as a GraphQL named type, or throws if it is not one.
* @param type - The GraphQL type to inspect.
* @returns The value typed as a GraphQL named type.
* @example
* ```ts
* import { GraphQLList, GraphQLString, assertNamedType } from 'graphql/type';
*
* const namedType = assertNamedType(GraphQLString);
*
* namedType.name; // => 'String'
* assertNamedType(new GraphQLList(GraphQLString)); // throws an error
* ```
*/
export declare function assertNamedType(type: unknown): GraphQLNamedType;
/**
* Returns the named type.
* @param type - The GraphQL type to inspect.
* @returns The named type after unwrapping all list and non-null wrappers.
* @example
* ```ts
* import { getNamedType } from 'graphql/type';
*
* getNamedType(null); // => undefined
* getNamedType(undefined); // => undefined
* ```
*/
export declare function getNamedType(type: undefined | null): void;
/**
* Returns the named input type after unwrapping all list and non-null wrappers.
* @param type - The GraphQL input type to inspect.
* @returns The named input type after unwrapping all wrappers.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { getNamedType } from 'graphql/type';
*
* const schema = buildSchema(`
* input ReviewInput {
* stars: Int!
* }
*
* type Query {
* review(input: [ReviewInput!]!): Boolean
* }
* `);
*
* const inputArg = schema.getQueryType()?.getFields().review.args[0];
*
* getNamedType(inputArg?.type).toString(); // => 'ReviewInput'
* ```
*/
export declare function getNamedType(type: GraphQLInputType): GraphQLNamedInputType;
/**
* Returns the named output type after unwrapping all list and non-null wrappers.
* @param type - The GraphQL output type to inspect.
* @returns The named output type after unwrapping all wrappers.
* @example
* ```ts
* import { buildSchema } from 'graphql/utilities';
* import { getNamedType } from 'graphql/type';
*
* const schema = buildSchema(`
* type User {
* name: String
* }
*
* type Query {
* users: [User!]!
* }
* `);
*
* const usersField = schema.getQueryType()?.getFields().users;
*
* getNamedType(usersField?.type).toString(); // => 'User'
* ```
*/
export declare function getNamedType(type: GraphQLOutputType): GraphQLNamedOutputType;
/**
* Returns the named type after unwrapping all list and non-null wrappers.
* @param type - The GraphQL type to inspect.
* @returns The named type after unwrapping all wrappers.
* @example
* ```ts
* import {
* GraphQLList,
* GraphQLNonNull,
* GraphQLString,
* getNamedType,
* } from 'graphql/type';
*
* const nestedType = new GraphQLNonNull(
* new GraphQLList(new GraphQLNonNull(GraphQLString)),
* );
*
* getNamedType(nestedType); // => GraphQLString
* ```
*/
export declare function getNamedType(type: GraphQLType): GraphQLNamedType;
/**
* Returns the named type after unwrapping all list and non-null wrappers.
* @param type - The GraphQL type to inspect.
* @returns The named type after unwrapping all wrappers, or undefined for nullish input.
* @example
* ```ts
* import { GraphQLList, GraphQLString, getNamedType } from 'graphql/type';
*
* getNamedType(new GraphQLList(GraphQLString)); // => GraphQLString
* getNamedType(undefined); // => undefined
* ```
*/
export declare function getNamedType(type: Maybe<GraphQLType>): GraphQLNamedType | undefined;
/**
* An interface for all Schema Elements.
*
* @internal
*/
export interface GraphQLSchemaElement {
toString: () => string;
toJSON: () => string;
}
/**
* Used while defining GraphQL types to allow for circular references in
* otherwise immutable type definitions.
* @typeParam T - The element type returned by the thunk or array.
*/
export type ThunkReadonlyArray<T> = (() => ReadonlyArray<T>) | ReadonlyArray<T>;
/**
* A thunk that resolves to an object map.
* @typeParam T - Value type stored in the object map.
*/
export type ThunkObjMap<T> = (() => ObjMap<T>) | ObjMap<T>;
/**
* Resolves a thunked readonly array.
* @param thunk - The thunk or value to resolve.
* @returns The resolved readonly array.
* @typeParam T - The element type resolved from the thunk or array.
* @example
* ```ts
* import { GraphQLString, resolveReadonlyArrayThunk } from 'graphql/type';
*
* const lazyFields = resolveReadonlyArrayThunk(() => [GraphQLString]);
* const fields = resolveReadonlyArrayThunk([GraphQLString]);
*
* lazyFields; // => [GraphQLString]
* fields; // => [GraphQLString]
* ```
*/
export declare function resolveReadonlyArrayThunk<T>(thunk: ThunkReadonlyArray<T>): ReadonlyArray<T>;
/**
* Resolves a thunked object map.
* @param thunk - The thunk or value to resolve.
* @returns The resolved object map.
* @typeParam T - The object-map value type resolved from the thunk or map.
* @example
* ```ts
* import { GraphQLString, resolveObjMapThunk } from 'graphql/type';
*
* const lazyFields = resolveObjMapThunk(() => ({ name: GraphQLString }));
* const fields = resolveObjMapThunk({ name: GraphQLString });
*
* lazyFields.name; // => GraphQLString
* fields.name; // => GraphQLString
* ```
*/
export declare function resolveObjMapThunk<T>(thunk: ThunkObjMap<T>): ObjMap<T>;
/**
* Custom extensions
* @remarks
* Use a unique identifier name for your extension, for example the name of
* your library or project. Do not use a shortened identifier as this increases
* the risk of conflicts. We recommend you add at most one extension field,
* an object which can contain all the values you need.
*/
export interface GraphQLScalarTypeExtensions {
[attributeName: string | symbol]: unknown;
}
/**
* Scalar Type Definition
*
* Scalar types define the leaf values of a GraphQL response and the input
* values accepted by arguments and input object fields. A scalar type has a
* name and coercion functions that validate and convert runtime values and
* GraphQL literals.
*
* If a type's coerceOutputValue function returns `null` or does not return a
* value (i.e. it returns `undefined`) then an error will be raised and a
* `null` value will be returned in the response. Prefer validating inputs
* before execution so clients receive input diagnostics before result coercion
* fails.
* Custom scalar behavior is defined via the following functions:
*
* - coerceOutputValue(value): Implements "Result Coercion". Given an internal value,
* produces an external value valid for this type. Returns undefined or
* throws an error to indicate invalid values.
*
* - coerceInputValue(value): Implements "Input Coercion" for values. Given an
* external value (for example, variable values), produces an internal value
* valid for this type. Returns undefined or throws an error to indicate
* invalid values.
*
* - coerceInputLiteral(ast): Implements "Input Coercion" for constant literals.
* Given a GraphQL literal (AST) (for example, an argument value), produces
* an internal value valid for this type. Returns undefined or throws an
* error to indicate invalid values.
*
* - valueToLiteral(value): Converts an external value to a GraphQL
* literal (AST). Returns undefined or throws an error to indicate
* invalid values.
*
* Deprecated, to be removed in v18:
*
* - serialize(value): Implements "Result Coercion". Renamed to
* `coerceOutputValue()`.
*
* - parseValue(value): Implements "Input Coercion" for values. Renamed to
* `coerceInputValue()`.
*
* - parseLiteral(ast): Implements "Input Coercion" for literals including
* non-specified replacement of variables embedded within complex scalars.
* Replaced by the combination of the `replaceVariables()` utility and the
* `coerceInputLiteral()` method.
* @typeParam TInternal - Internal runtime representation for this scalar.
* @typeParam TExternal - External representation accepted from or returned to callers.
* @example
* ```ts
* import { GraphQLScalarType, Kind } from 'graphql';
*
* const ensureOdd = (value) => {
* if (!Number.isFinite(value)) {
* throw new Error(
* `Scalar "Odd" cannot represent "${value}" since it is not a finite number.`,
* );
* }
*
* if (value % 2 === 0) {
* throw new Error(
* `Scalar "Odd" cannot represent "${value}" since it is even.`,
* );
* }
*
* return value;
* };
*
* const OddType = new GraphQLScalarType({
* name: 'Odd',
* coerceOutputValue: (value) => {
* return ensureOdd(value);
* },
* coerceInputValue: (value) => {
* return ensureOdd(value);
* },
* valueToLiteral: (value) => {
* return { kind: Kind.INT, value: String(ensureOdd(value)) };
* },
* });
* ```
*/
export declare class GraphQLScalarType<TInternal = unknown, TExternal = TInternal> implements GraphQLSchemaElement {
/** The GraphQL name for this schema element. */
name: string;
/** Human-readable description for this schema element, if provided. */
description: Maybe<string>;
/** URL identifying the behavior specified for this custom scalar. */
specifiedByURL: Maybe<string>;
/**
* Deprecated legacy serializer used to convert internal values for response
* output. Use `coerceOutputValue()` instead.
* @deprecated use `coerceOutputValue()` instead, `serialize()` will be removed in v18
*/
serialize: GraphQLScalarSerializer<TExternal>;
/**
* Deprecated legacy parser used to convert externally provided input values.
* Use `coerceInputValue()` instead.
* @deprecated use `coerceInputValue()` instead, `parseValue()` will be removed in v18
*/
parseValue: GraphQLScalarValueParser<TInternal>;
/**
* Deprecated legacy parser used to convert externally provided input
* literals. Use `replaceVari