Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-schema-link

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-schema-link

Apollo Link Schema with context support.

  • 0.0.1
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
apollo styled logo

Size badge NPM

Apollo SchemaLink with context support. Useful for Next.js apps with universal Apollo GraphQL client that require context (for example field authorization).

Install

pnpm i better-schema-link @apollo/client graphql

Example

import { ApolloClient, InMemoryCache, ApolloLink, ServerError } from '@apollo/client'

const createIsomorphLink = () => {
  if (typeof window === 'undefined') {
    // Works on the server
    const { SchemaLink } = require('better-schema-link')
    const { schema } = require('../graphql/schema')
    const context = require('../graphql/context')
    return new SchemaLink({ schema, context })
  } else {
    // Works on the client
    const { HttpLink } = require('@apollo/client/link/http')

    return new HttpLink({
      uri: '/api/graphql',
      credentials: 'same-origin'
    })
  }
}

// Now your client works on both server and client!
export const createApolloClient = () =>
  new ApolloClient({
    ssrMode: typeof window === 'undefined',
    link: createIsomorphLink(),
    cache: new InMemoryCache()
  })

Keywords

FAQs

Package last updated on 29 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc