GraphQL Tools is a deprecated utility library that provides the essential makeExecutableSchema function for creating executable GraphQL schemas from type definitions and resolvers. This package serves as a compatibility wrapper and only exports a single function from the more focused @graphql-tools/schema package.
npm install graphql-tools@graphql-tools/schema instead)import { makeExecutableSchema } from "graphql-tools";For CommonJS:
const { makeExecutableSchema } = require("graphql-tools");import { makeExecutableSchema } from "graphql-tools";
// Define GraphQL type definitions using SDL
const typeDefs = `
type Query {
hello: String
user(id: ID!): User
}
type User {
id: ID!
name: String!
email: String!
}
`;
// Define resolvers for the types
const resolvers = {
Query: {
hello: () => "Hello World!",
user: (parent, args) => ({
id: args.id,
name: "Alice",
email: "alice@example.com"
}),
},
};
// Create executable schema
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
// Use with GraphQL server (Apollo Server example)
// const server = new ApolloServer({ schema });Creates an executable GraphQL schema from type definitions and resolvers, with comprehensive configuration options and validation.
/**
* Creates an executable GraphQL schema from type definitions and resolvers
* @param config - Configuration object containing type definitions, resolvers, and options
* @returns Executable GraphQL schema ready for use with GraphQL servers
*/
function makeExecutableSchema<TContext = any>(
config: IExecutableSchemaDefinition<TContext>
): GraphQLSchema;
interface IExecutableSchemaDefinition<TContext = any> extends BuildSchemaOptions, GraphQLParseOptions {
/** The type definitions used to create the schema */
typeDefs: TypeSource;
/** Object describing the field resolvers for the provided type definitions */
resolvers?: IResolvers<any, TContext> | Array<IResolvers<any, TContext>>;
/** Additional options for validating the provided resolvers */
resolverValidationOptions?: IResolverValidationOptions;
/** GraphQL object types that implement interfaces will inherit any missing resolvers from their interface types defined in the resolvers object */
inheritResolversFromInterfaces?: boolean;
/** Do not create a schema again and use the one from buildASTSchema */
updateResolversInPlace?: boolean;
/** Schema extensions */
schemaExtensions?: SchemaExtensions | Array<SchemaExtensions>;
}Usage Examples:
import { makeExecutableSchema } from "graphql-tools";
import { buildSchema } from "graphql";
// Example 1: Basic schema creation
const schema1 = makeExecutableSchema({
typeDefs: `
type Query {
greeting: String
}
`,
resolvers: {
Query: {
greeting: () => "Hello World!"
}
}
});
// Example 2: Multiple resolver maps
const baseResolvers = {
Query: {
users: () => [{ id: "1", name: "Alice" }]
}
};
const extendedResolvers = {
User: {
email: (user) => `${user.name.toLowerCase()}@example.com`
}
};
const schema2 = makeExecutableSchema({
typeDefs: `
type Query {
users: [User!]!
}
type User {
id: ID!
name: String!
email: String!
}
`,
resolvers: [baseResolvers, extendedResolvers]
});
// Example 3: With validation options
const schema3 = makeExecutableSchema({
typeDefs: `
type Query {
post(id: ID!): Post
}
type Post {
id: ID!
title: String!
}
`,
resolvers: {
Query: {
post: () => ({ id: "1", title: "First Post" })
}
},
resolverValidationOptions: {
requireResolversForResolveType: 'warn',
requireResolversForAllFields: 'warn'
}
});
// Example 4: Using existing GraphQL schema
const existingSchema = buildSchema(`
type Query {
version: String
}
`);
const schema4 = makeExecutableSchema({
typeDefs: existingSchema,
resolvers: {
Query: {
version: () => "1.0.0"
}
}
});/** Union type for various GraphQL type definition formats */
type TypeSource =
| string
| Source
| DocumentNode
| GraphQLSchema
| DefinitionNode
| Array<TypeSource>
| (() => TypeSource);
/** Interface for resolver map structure */
type IResolvers<TSource = any, TContext = any, TArgs = Record<string, any>, TReturn = any> = Record<
string,
| ISchemaLevelResolver<TSource, TContext, TArgs, TReturn>
| IObjectTypeResolver<TSource, TContext>
| IInterfaceTypeResolver<TSource, TContext>
| IUnionTypeResolver
| IScalarTypeResolver
| IEnumTypeResolver
| IInputObjectTypeResolver
>;
// Resolver type definitions (simplified for documentation)
type ISchemaLevelResolver<TSource, TContext, TArgs, TReturn> = (
source: TSource,
args: TArgs,
context: TContext,
info: GraphQLResolveInfo
) => TReturn;
type IObjectTypeResolver<TSource = any, TContext = any> = Record<
string,
IFieldResolver<TSource, TContext> | IFieldResolverOptions<TSource, TContext>
>;
type IFieldResolver<TSource = any, TContext = any> = (
source: TSource,
args: any,
context: TContext,
info: GraphQLResolveInfo
) => any;
// Additional resolver types are internal implementation details
/** Configuration for resolver validation */
interface IResolverValidationOptions {
/** Enable to require a resolver to be defined for any field that has arguments */
requireResolversForArgs?: ValidatorBehavior;
/** Enable to require a resolver to be defined for any field which has a return type that isn't a scalar */
requireResolversForNonScalar?: ValidatorBehavior;
/** Enable to require a resolver for be defined for all fields defined in the schema */
requireResolversForAllFields?: ValidatorBehavior;
/** Enable to require a resolveType() for Interface and Union types */
requireResolversForResolveType?: ValidatorBehavior;
/** Enable to require all defined resolvers to match fields that actually exist in the schema */
requireResolversToMatchSchema?: ValidatorBehavior;
}
/** Validation behavior options */
type ValidatorBehavior = 'error' | 'warn' | 'ignore';
/** Type for schema extension configurations */
type SchemaExtensions = {
schemaExtensions: ExtensionsObject;
types: Record<string, { extensions: ExtensionsObject }>;
};
type ExtensionsObject = Record<string, any>;
/** Extended GraphQL schema with optional context type information */
interface GraphQLSchemaWithContext<TContext> extends GraphQLSchema {
__context?: TContext;
}
/** Standard GraphQL types from graphql-js */
interface GraphQLSchema {
// Core GraphQL schema implementation from graphql-js
}
interface DocumentNode {
// GraphQL AST document node from graphql-js
}
interface DefinitionNode {
// GraphQL AST definition node from graphql-js
}
interface Source {
// GraphQL source from graphql-js
}
interface GraphQLResolveInfo {
// GraphQL resolver info from graphql-js
}
interface BuildSchemaOptions {
/** Whether to assume the SDL is valid */
assumeValidSDL?: boolean;
/** Whether to assume the SDL is already sorted */
assumeValid?: boolean;
}
interface GraphQLParseOptions {
/** Maximum number of tokens to parse */
maxTokens?: number;
/** Whether descriptions are parsed from comments */
commentDescriptions?: boolean;
}
// Additional internal types referenced but not directly exposed
interface IFieldResolverOptions<TSource, TContext> {
// Internal implementation details
}The makeExecutableSchema function can throw the following errors:
resolverValidationOptions to be an object" - when resolverValidationOptions is not an objectresolverValidationOptions settingsThis package displays a deprecation warning when imported:
This package has been deprecated and now it only exports makeExecutableSchema.
And it will no longer receive updates.
We recommend you to migrate to scoped packages such as @graphql-tools/schema, @graphql-tools/utils and etc.
Check out https://www.graphql-tools.com to learn what package you should use instead!For new projects, use @graphql-tools/schema directly:
// Instead of this (deprecated)
import { makeExecutableSchema } from "graphql-tools";
// Use this (recommended)
import { makeExecutableSchema } from "@graphql-tools/schema";