How to use apollo-link-schema - 10 common examples

To help you get started, we’ve selected a few apollo-link-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuex-orm / plugin-graphql / test / support / helpers.ts View on Github external
export function createStore(entities: Array, headers?: any, adapter?: Adapter) {
  const database = new Database();

  entities.forEach(entity => {
    database.register(entity.model, entity.module || {});
  });

  // @ts-ignore
  const executableSchema = makeExecutableSchema({
    typeDefs,
    resolvers
  });

  link = new SchemaLink({ schema: executableSchema });

  VuexORM.use(VuexORMGraphQLPlugin, {
    database: database,
    link,
    headers,
    adapter
  });

  const store = new Vuex.Store({
    plugins: [VuexORM.install(database)]
  });

  return [store, VuexORMGraphQLPlugin.instance];
}
github VulcanJS / Vulcan / packages / vulcan-lib / lib / server / apollo-ssr / apolloClient.js View on Github external
export const createClient = async ({ req, computeContext }) => {
  // init
  // stateLink will init the client internal state
  const cache = new InMemoryCache();
  const stateLink = createStateLink({ cache });
  // schemaLink will fetch data directly based on the executable schema
  const schema = GraphQLSchema.getExecutableSchema();
  // this is the resolver context
  const context = await computeContext(req);
  const schemaLink = new SchemaLink({ schema, context });
  const client = new ApolloClient({
    ssrMode: true,
    link: ApolloLink.from([stateLink, schemaLink]),
    // @see https://www.apollographql.com/docs/react/features/server-side-rendering.html#local-queries
    // Remember that this is the interface the SSR server will use to connect to the
    // API server, so we need to ensure it isn't firewalled, etc
    //link: createHttpLink({
    //    uri: 'http://localhost:3000',
    //    credentials: 'same-origin',
    //    headers: {
    //        // NOTE: this is a Connect req, not an Express req,
    //        // so req.header is not defined
    //        // cookie: req.header('Cookie'),
    //        cookie: req.headers['cookie'],
    //    },
    //    // need to explicitely pass fetch server side
github MadRabbit / graphql-mock / src / client.ts View on Github external
constructor(typeDefs: string | GraphQLSchema, mocks?: any, resolvers?: any) {
    const schema =
      typeof typeDefs === 'string' ? makeExecutableSchema({ typeDefs, resolvers }) : typeDefs;

    addMockFunctionsToSchema({ schema, mocks });

    const cache = new InMemoryCache((window as any).__APOLLO_STATE__); // eslint-disable-line
    const link = new SchemaLink({ schema });

    super({ link, cache, resolvers: {} });
  }
github the-road-to-graphql / react-apollo-client-mocking-example / src / index.js View on Github external
},
  });

  const schema = await introspectSchema(httpLink);

  const executableSchema = makeExecutableSchema({
    typeDefs: printSchema(schema),
    // typeDefs: schema,
    resolvers,
    resolverValidationOptions: {
      requireResolversForResolveType: false,
    },
  });

  const client = new ApolloClient({
    link: new SchemaLink({ schema: executableSchema }),
    cache,
  });

  ReactDOM.render(
    
      
    ,
    document.getElementById('root'),
  );
}
github withspectrum / spectrum / hyperion / renderer / index.js View on Github external
const renderer = (req: express$Request, res: express$Response) => {
  res.setHeader('Content-Type', 'text/html; charset=utf-8');

  if (IN_MAINTENANCE_MODE) {
    res.status(500);
    res.send(
      `<title>Spectrum</title> <style>body{margin: 0;}html{-webkit-font-smoothing: antialiased; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';}h1, p{line-height: 1.5;}.container{background: rgb(56,24,229);background: linear-gradient(90deg, rgba(56,24,229,1) 0%, rgba(56,24,229,0.8029586834733894) 52%, rgba(56,24,229,1) 100%); width: 100%; display: flex; height: 100vh; justify-content: center;}.item{color: white; font-weight: bold; align-self: center; text-align: center;}a{color: white;}span{font-size: 40px; padding: 0; margin: 0;}</style> <div class="container"> <div class="item"> <span>🛠</span> <h1>We are currently undergoing maintenance.</h1> <p>We'll be back shortly. Follow <a href="https://twitter.com/withspectrum">@withspectrum on Twitter</a> to stay up to date. </p></div></div>`
    );
    return;
  }

  debug(`server-side render ${req.url}`);
  debug(`querying API at https://${req.hostname}/api`);
  const schemaLink = new SchemaLink({
    schema,
    context: {
      user: req.user || null,
      loaders: createLoaders(),
    },
  });

  const cache = new InMemoryCache({
    fragmentMatcher: new IntrospectionFragmentMatcher({
      introspectionQueryResultData,
    }),
    ...getSharedApolloClientOptions(),
  });

  // Get the nonce attached to every request
  // This nonce is generated by our security middleware
github fusionjs / fusionjs / fusion-plugin-apollo / src / __tests__ / server.node.js View on Github external
app.register(ApolloClientToken, ctx => {
    return new ApolloClient({
      ssrMode: true,
      cache: new InMemoryCache().restore({}),
      link: new SchemaLink({
        schema,
        context: ctx,
      }),
    });
  });
  return app;
github thetribeio / node-react-starter-kit / api / utils / createApolloClient.js View on Github external
export default function createApolloClient(schema) {
    const link = from([
        onError(({ graphQLErrors, networkError }) => {
            if (graphQLErrors) {
                graphQLErrors.map(({ message, locations, path }) => console.warn(
                    `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
                ));
            }

            if (networkError) {
                console.warn(`[Network error]: ${networkError}`);
            }
        }),
        new SchemaLink({ ...schema }),
    ]);

    return new ApolloClient({
        link,
        cache: new InMemoryCache({ addTypename: false }),
        ssrMode: true,
        queryDeduplication: true,
    });
}
github OpenNeuroOrg / openneuro / packages / openneuro-client / src / __mocks__ / client.js View on Github external
const createClient = uri => {
  const cache = new InMemoryCache()
  const link = new SchemaLink({ schema })
  return new ApolloClient({ uri, link, cache })
}
github zeit / next.js / examples / api-routes-apollo-server-and-client / apollo / client.js View on Github external
function createIsomorphLink() {
  if (typeof window === 'undefined') {
    const { SchemaLink } = require('apollo-link-schema')
    const { schema } = require('./schema')
    return new SchemaLink({ schema })
  } else {
    const { HttpLink } = require('apollo-link-http')
    return new HttpLink({
      uri: '/api/graphql',
      credentials: 'same-origin',
    })
  }
}
github hanpama / girin / examples / todolist-apollo / src / client.ts View on Github external
import { ApolloClient } from 'apollo-client';
import { SchemaLink } from 'apollo-link-schema';
import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory';

import { schema } from './schema';

export const client: ApolloClient = new ApolloClient({
  link: new SchemaLink({ schema }),
  cache: new InMemoryCache(),
});

apollo-link-schema

Use a GraphQL Schema to request data

MIT
Latest version published 5 years ago

Package Health Score

62 / 100
Full package analysis

Popular apollo-link-schema functions

Similar packages