Skip to content

Instantly share code, notes, and snippets.

@agenthunt
Created April 2, 2018 20:42
Show Gist options
  • Save agenthunt/d895cf57d3161c6c6fe448ae0592f314 to your computer and use it in GitHub Desktop.
Save agenthunt/d895cf57d3161c6c6fe448ae0592f314 to your computer and use it in GitHub Desktop.
export const { types, actions, rootReducer, rootSaga } = createStar({
name: 'blogItem',
log: true,
graphql: {
client: apolloClient,
add: {
getBlogItems: {
query: gql`
query {
allBlogItems {
id
title
author
image
}
}
`
},
getBlogItem: {},
createBlogItem: {},
updateBlogItem: {},
removeBlogItem: {}
}
}
});
// How to invoke a graphql mutation .
const length = (this.props.blogItems.getBlogItems.data.allBlogItems && this.props.blogItems.getBlogItems.data.allBlogItems.length) || 0;
this.props.actions.createBlogItem({
variables: {
title: faker.lorem.words(),
author: faker.name.findName(),
author_image: faker.image.avatar(),
release_date: faker.date.recent(),
image: faker.image.nature(),
short_description: faker.lorem.sentence(),
long_description: faker.lorem.paragraphs(),
id: length
},
mutation: gql`
mutation createBlogItem(
$title: String!
$author: String!
$author_image: String!
$release_date: String!
$image: String!
$short_description: String!
$long_description: String!
$id: ID!
) {
createBlogItem(
title: $title
author: $author
author_image: $author_image
release_date: $release_date
image: $image
short_description: $short_description
long_description: $long_description
id: $id
) {
id
title
author
author_image
release_date
image
short_description
long_description
}
}
`
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment