@sharyn/shared

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

Usage no npm install needed!

<script type="module">
  import sharynShared from 'https://cdn.skypack.dev/@sharyn/shared';
</script>

README

🌹 @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.