4.0.1 • Published 4 years ago

@usercentric/uc-design-system-apollo v4.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

UCDS Apollo

Provides out of the box support for GraphQL, powered by Apollo.

yarn add @usercentric/uc-design-system-apollo

This package relies on GraphQL related packages to also be installed.

yarn add graphql graphql-tag

Setup

Initialize the package to create an Apollo client. The following option settings may be passed to customize this package.

  • links (ApolloLink[]) - Collection of Apollo links (middleware) to apply to the client.
import Apollo, { HttpLink } from '@usercentric/uc-design-system-apollo'

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

Apollo.initialize({
  links: [httpLink],
})

The client can be accessed with Apollo.getClient().

Usage

Once the Apollo client has been created, we can make it available to our queries and mutations by wrapping our application in a provider.

import { Provider } from '@usercentric/uc-design-system-apollo'

function Root() {
  return (
    <Provider>
      <App />
    </Provider>
  )
}