docs/source/api/link/apollo-link-schema.mdx
<DocBlock canonicalReference="@apollo/client/link/schema!SchemaLink:class" customOrder={["summary", "remarks", "example"]} />
constructor(
options: SchemaLink.Options
): SchemaLink
When performing SSR on the same server, you can use this library to avoid making network calls.
import { ApolloClient, InMemoryCache } from "@apollo/client";
import { SchemaLink } from "@apollo/client/link/schema";
import schema from "./path/to/your/schema";
const graphqlClient = new ApolloClient({
cache: new InMemoryCache(),
ssrMode: true,
link: new SchemaLink({ schema }),
});
For more detailed information about mocking, refer to the graphql-tools documentation.
import { ApolloClient, InMemoryCache } from '@apollo/client';
import { SchemaLink } from '@apollo/client/link/schema';
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
const typeDefs = `
Query {
...
}
`;
const mocks = {
Query: () => ...,
Mutation: () => ...
};
const schema = makeExecutableSchema({ typeDefs });
const schemaWithMocks = addMockFunctionsToSchema({
schema,
mocks
});
const apolloCache = new InMemoryCache(window.__APOLLO_STATE__);
const graphqlClient = new ApolloClient({
cache: apolloCache,
link: new SchemaLink({ schema: schemaWithMocks })
});
<InterfaceDetails canonicalReference="@apollo/client/link/schema!SchemaLink.Options:interface" headingLevel={3} displayName="SchemaLink.Options" />
SchemaLink.ResolverContexttype ResolverContext = Record<string, any>;
<FunctionDetails canonicalReference="@apollo/client/link/schema!SchemaLink.SchemaLinkDocumentationTypes.ResolverContextFunction:function(1)" headingLevel={3} result={false} displayName="SchemaLink.ResolverContextFunction" />