Apollo GraphQL Utility Library (Abandoned)
The `apollo-graphql` package, last updated as version 0.9.7 around 2019, served as an internal utility library within the Apollo Server monorepo (primarily during the Apollo Server v2 era). It provided foundational GraphQL-related utilities for schema manipulation, such as adding resolvers, merging schemas, concatenating type definitions, and printing schemas with directives. This package is now considered abandoned, with no further updates planned, and its functionalities have been either integrated directly into newer versions of `@apollo/server` or are handled by more modern, actively maintained libraries like `@graphql-tools/schema` or `@apollo/server` itself. Developers are strongly advised not to use `apollo-graphql` for new projects due to its age, lack of updates, potential security vulnerabilities, and incompatibility with modern `graphql` and Node.js environments.
Common errors
-
TypeError: (0 , apollo_graphql_1.addResolversToSchema) is not a function
cause Attempting to import `apollo-graphql` using ESM `import` syntax in an environment that doesn't correctly transpile legacy CommonJS modules, or when the `addResolversToSchema` function is not correctly resolved.fixChange your import statement to use CommonJS `require()`: `const { addResolversToSchema } = require('apollo-graphql');`. -
Cannot find module 'apollo-graphql'
cause The package `apollo-graphql` is not installed, or your module resolver (e.g., Webpack, Node.js) cannot locate it. This often happens if the package name is misspelled, or if it's not present in `node_modules`.fixEnsure the package is installed: `npm install apollo-graphql` or `yarn add apollo-graphql`. Also, verify that your project's module resolution paths are correctly configured. -
npm WARN apollo-graphql@0.9.7 requires a peer of graphql@^14.2.1 || ^15.0.0 but none is installed.
cause You have a version of `graphql` installed that is outside the range specified by `apollo-graphql`'s peer dependencies, or `graphql` is not installed at all.fixInstall a compatible version of `graphql`, for example: `npm install graphql@^15.0.0`. However, the primary recommendation is to remove `apollo-graphql` entirely due to its abandonment.
Warnings
- breaking This package is explicitly abandoned and has not received updates since approximately 2019. It is not compatible with modern Node.js versions (e.g., Node.js 14+ ESM), current `graphql` library versions (v16+), or the latest `@apollo/server` releases.
- gotcha The package primarily targets CommonJS environments. Attempting to use `import` statements directly will likely result in module resolution errors or runtime failures unless a robust transpilation pipeline (e.g., Babel, Webpack) is specifically configured for such legacy modules.
- breaking Security vulnerabilities are highly probable due to the package's age and lack of maintenance. Any reported CVEs or discovered weaknesses will not be patched, posing significant risks to applications that still depend on it.
- gotcha The peer dependency on `graphql` specifies versions `^14.2.1 || ^15.0.0`. Installing this package with `graphql` v16 or higher will trigger peer dependency warnings and likely lead to runtime errors due to API changes in the `graphql` library itself.
Install
-
npm install apollo-graphql -
yarn add apollo-graphql -
pnpm add apollo-graphql
Imports
- addResolversToSchema
import { addResolversToSchema } from 'apollo-graphql';const { addResolversToSchema } = require('apollo-graphql'); - printSchemaWithDirectives
import printSchemaWithDirectives from 'apollo-graphql';
const { printSchemaWithDirectives } = require('apollo-graphql'); - mergeSchemas
import * as ApolloGraphql from 'apollo-graphql';
const { mergeSchemas } = require('apollo-graphql');
Quickstart
const { gql } = require('apollo-server-express');
const { addResolversToSchema } = require('apollo-graphql');
const { makeExecutableSchema } = require('@graphql-tools/schema');
// This example is for illustrative purposes only, showing historical usage.
// It is not recommended for current development.
const typeDefs = gql`
type Query {
hello: String
greet(name: String!): String
}
`;
const resolvers = {
Query: {
hello: () => 'Hello, world!',
greet: (parent, { name }) => `Greetings, ${name}!`,
},
};
// Create a basic executable schema (using modern @graphql-tools for simplicity here)
let schema = makeExecutableSchema({ typeDefs });
// Historically, apollo-graphql's addResolversToSchema would be used.
// Note: This function might not be directly compatible with modern `graphql-tools` Schema types.
// For a truly historical setup, one would need older `graphql` and `graphql-tools` versions.
try {
schema = addResolversToSchema(schema, resolvers);
console.log('Schema with resolvers added (historical emulation):');
// In a real scenario, you'd then pass this schema to Apollo Server v2
// For demonstration, we'll just log a success message.
console.log('Schema successfully augmented using addResolversToSchema.');
console.log(require('graphql').printSchema(schema));
} catch (e) {
console.error('Error attempting to use addResolversToSchema. This package is old and likely incompatible:', e.message);
}
// For current projects, use `@apollo/server` or `@graphql-tools/schema` directly.