Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
apollo-link-state
Advanced tools
An Apollo Link to easily manage local state!
The API of this libray is still in flux, for usage patterns check out the test suite, most importantly the client
and advanced
test suite
State management is a problem that nearly every application runs into at some point or another. Application state tends to be a cross of UI interactions and remote data states, this is typically solved by using libraries like redux and MobX, but what if you could keep using GraphQL like you do for your remote data. What if you could merge the two together easily?
Now you can! Apollo State Link allows you to declare resolvers for Queries, Mutations, and types (Subscriptions coming) to augment your server schema or create an entirely local one!
npm install apollo-link-state --save
Apollo Link State is an easy way to manage local application state with GraphQL and Apollo. Setting up local state can be done like so:
import { withClientState } from 'apollo-link-state';
const local = withClientState({
Query: {
// provide an initial state
todos: () => [],
},
Mutation: {
// update values in the store on mutations
addTodo: (_, { message, title }, { cache }) => {
const current = client.readQuery({ query, variables });
const data = {
todos: current.todos.concat([
{ message, title, __typename: 'Todo' }
])
};
cache.writeQuery({ query, variables, data });
return null;
};
},
});
// use the local link to create an Apollo Client instance
// usage with query
const query = gql`
query todos {
todos @client {
message
title
}
}
`
const initial = await client.query({ query });
// { data: { todos: [] } }
const mutation = gql`
mutation addTodo($message: String, $title: String){
addTodo(message: $message, title: $title)
}
`
// add a todo
client.mutate({
mutation,
variables: {
title: 'hello world',
message: 'oh what a world this is'
}
});
const initial = await client.query({ query });
/*
{
data: {
todos: [
{ title: 'hello world', message: 'oh what a world this is' }
]
}
}
*/
FAQs
An easy way to manage local state with Apollo Link
The npm package apollo-link-state receives a total of 21,265 weekly downloads. As such, apollo-link-state popularity was classified as popular.
We found that apollo-link-state demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.