Registry / testing / apollo-link-schema

apollo-link-schema

JSON →
library1.2.5jsnpmunverified

Apollo Link for executing GraphQL operations against a local schema, useful for server-side rendering and mocking. Current stable version is 1.2.5. This package allows you to bypass network calls by using a provided GraphQL schema directly, often within a Node.js server for SSR or with mock data. It is part of the Apollo Link ecosystem and integrates with Apollo Client. The schema link uses the graphql execution layer (via graphql-js). Key differentiators: enables SSR without network overhead, and supports mocking via graphql-tools. However, it is recommended to use apollo-link-state for client-side state management as graphql-js is heavy for clients. Release cadence is low; no recent updates. Note: peer dependency on graphql versions 0.11-15.

npm install apollo-link-schema
INSTALL
IMPORT
SIG · APOLLO-LINK-SCHEMA
A
apollo-link-schema
testingjavascriptv1.2.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SchemaLink
import { SchemaLink } from 'apollo-link-schema'
import SchemaLink from 'apollo-link-schema'
Named export, not default export. Works with both ESM and CJS.
SchemaLink
const { SchemaLink } = require('apollo-link-schema')
const SchemaLink = require('apollo-link-schema')
Using require with destructuring is required for CommonJS.
SchemaLink (type export)
import { SchemaLink } from 'apollo-link-schema'
TypeScript types are bundled; can be used for type annotations. Example: const link: SchemaLink = ...

Demonstrates creating a SchemaLink with a local executable schema and using it with Apollo Client for server-side rendering.

import { ApolloClient } from 'apollo-client'; import { InMemoryCache } from 'apollo-cache-inmemory'; import { SchemaLink } from 'apollo-link-schema'; import { makeExecutableSchema } from 'graphql-tools'; const typeDefs = ` type Query { hello: String } `; const resolvers = { Query: { hello: () => 'Hello world!' } }; const schema = makeExecutableSchema({ typeDefs, resolvers }); const client = new ApolloClient({ ssrMode: true, cache: new InMemoryCache(), link: new SchemaLink({ schema }) }); client.query({ query: gql`{ hello }` }).then(result => console.log(result));
Debug
Known issues
deprecatedConsider using @apollo/client's local state management instead of this link for client-side state.
fix
Use @apollo/client `Reactive Variables` or `apollo-link-state` for client-side state.
affects: >=1.0.0
gotchagraphql-js execution layer is heavy; not recommended for client-side use.
fix
Use apollo-link-state or local resolvers in Apollo Client 3+ for client-only operations.
affects: >=1.0.0
breakingPeer dependency graphql must be version 0.11 - 15; incompatible with graphql 16+.
fix
If using graphql 16, consider upgrading to Apollo Client 3 or using a different link.
affects: >=1.0.0
gotchaWhen using with TypeScript, ensure strict typing of context and rootValue.
fix
Define context and rootValue types explicitly; use `context: (operation) => ({...})` for dynamic context.
affects: >=1.0.0
deprecatedThe `graphql-tools` package has been deprecated; use `@graphql-tools/schema` instead.
fix
Replace `graphql-tools` with `@graphql-tools/schema` for makeExecutableSchema.
affects: >=1.0.0
gotchaSchemaLink expects an executable schema; using a GraphQL schema language string alone will fail.
fix
Ensure schema is executable via makeExecutableSchema or a schema object with resolvers.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot use GraphQLSchema "<schema>" from another module or realm. Ensure that there is only one instance of "graphql" in the node_modules directory.
Multiple copies of graphql installed in node_modules (e.g., from different packages).
fix
Run `npm dedupe` or use `resolutions` in package.json to pin a single graphql version.
TypeError: (0 , _graphql.execute) is not a function
Using an incompatible version of graphql (e.g., graphql 16).
fix
Downgrade graphql to version 0.15 or earlier, or upgrade to Apollo Client 3 which supports graphql 15+.
Invariant Violation: SchemaLink must be initialized with a schema.
Calling `new SchemaLink()` without passing a schema object.
fix
Pass a schema object: `new SchemaLink({ schema })` where schema is an executable GraphQLSchema.
GraphQLError: Syntax Error: Expected Name, found "{"
Passing a non-executable schema string to SchemaLink; schema must be constructed with resolvers.
fix
Use `makeExecutableSchema({ typeDefs, resolvers })` to create an executable schema first.
Upgrade
Version history
1.2.5latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency required for schema execution; graphql-js execution layer is used internally.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources