Socket
Socket
Sign inDemoInstall

better-schema-link

Package Overview
Dependencies
37
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    better-schema-link

Apollo Link Schema with context support.


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

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

Last updated on 29 Jun 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc