Apollo GraphQL Utility Library (Abandoned)
raw JSON →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
error TypeError: (0 , apollo_graphql_1.addResolversToSchema) is not a function ↓
require(): const { addResolversToSchema } = require('apollo-graphql');. error Cannot find module 'apollo-graphql' ↓
npm install apollo-graphql or yarn add apollo-graphql. Also, verify that your project's module resolution paths are correctly configured. error npm WARN apollo-graphql@0.9.7 requires a peer of graphql@^14.2.1 || ^15.0.0 but none is installed. ↓
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 wrong
import { addResolversToSchema } from 'apollo-graphql';correctconst { addResolversToSchema } = require('apollo-graphql'); - printSchemaWithDirectives wrong
import printSchemaWithDirectives from 'apollo-graphql';correctconst { printSchemaWithDirectives } = require('apollo-graphql'); - mergeSchemas wrong
import * as ApolloGraphql from 'apollo-graphql';correctconst { 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.