nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
955 stars 198 forks source link

Use a SchemaLink instead of a HttpLink #412

Open vincentwinkel opened 3 years ago

vincentwinkel commented 3 years ago

[disclaimer] I cannot create my issue from https://cmty.app/nuxt/issues/new?repo=apollo-module since this website is down.

Is it possible to use a SchemaLink instead of a HttpLink, being able to use local mocks? I would like to do something like this:

import { makeExecutableSchema } from '@graphql-tools/schema';
import { addMocksToSchema } from '@graphql-tools/mock';
import { SchemaLink } from '@apollo/client/link/schema';
import typeDefs from './mock/schema';
import resolvers from './mock/resolvers';

const schema = makeExecutableSchema({ typeDefs, resolvers });
const schemaMock = addMocksToSchema({ schema });
const schemaLink = new SchemaLink({ schema: schemaMock });

export default (context) => ({ schemaLink });