rajington / apollo-client-restated

Add common functionality to apollo-link-state via clientside schema directives

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This project practices README-driven development

apollo-client-restated

Add common functionality to Apollo local state via clientside schema directives.

Install

import restated from 'apollo-client-restated'

const schema = makeExecutableSchema({
  typeDefs,
  schemaDirectives: {
    restated,
  }
})

Examples

increment/decrement

type Query {
  page: Int! @restated(default: 1, actions: [INCREMENT, DECREMENT])
}

# GENERATED
type Mutation {
  pageIncrement
  pageDecrement
}

toggle

type Query {
  visible: Boolean! @restated(default: false, actions: [TOGGLE])
}

# GENERATED
type Mutation {
  visibleToggle
}

set

type Query {
  name: String @restated(actions: [SET])
}

# GENERATED
type Mutation {
  nameSet(name: String)
}

custom actions

type Query {
  sign: String @restated(actions: [INVERT])
}

# GENERATED
type Mutation {
  signInvert
}
const schema = makeExecutableSchema({
  typeDefs,
  schemaDirectives: {
    restated({
      invert: sign => -sign,
    }),
  }
})

About

Add common functionality to apollo-link-state via clientside schema directives

License:MIT License