@sharyn/shared

4.5.2 • Public • Published

🌹 @sharyn/shared

npm

This package provides isomorphic / universal utilities than can be used on both the client and the server.

🌹 Install

yarn add @sharyn/shared

🌹 Usage

Switch

import Switch from '@sharyn/shared/Switch'
import FooPage from 'foo/cmp-page/foo-page'
import FooIcon from '@material-ui/icons/Foo'

export const fooRoute: Object = {
  path: '/foo',
  exact: true,
  loggedInOnly: true,
  title: 'Foo',
  Icon: FooIcon,
  inNav: true,
}

const routesAndCmps = [
  { route: fooRoute, component: FooPage }
  { route: barRoute, component: BarPage }
]

const App = () => (
  <Switch routesAndCmps={routesAndCmps} />
)

fetchGraphql (don't use it)

// ...

const query = "query ($id: ID!) { getThing(id: $id) { id } }"
const variables = { id: 123 }

const resp = await fetchGraphql({ query, variables })

/*
  {
    data: {
      getThing: { id: 123 }
    },
    errors: [...]
  }
*/

Options

fetchGraphql(options, fetchOptions)

  • options is an object than can contain:

    • query (required): The GraphQL query.
    • variables: The object of your variables.
    • host: The host (https://www.example.com:12345). Leave this field empty for client-side fetches.
    • path: The GraphQL path (default is /graphql)
    • cookie: A cookie string (useful for server-side fetches).
  • fetchOptions is the native options of fetch in case you need to override the defaults provided by fetchGraphql.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 4.5.2
    26
    • latest

Version History

Package Sidebar

Install

npm i @sharyn/shared

Weekly Downloads

124

Version

4.5.2

License

MIT

Unpacked Size

17.6 kB

Total Files

14

Last publish

Collaborators

  • sharyn