Skip to content

Instantly share code, notes, and snippets.

@dbayarchyk
dbayarchyk / promiseCatchWithAwait.js
Created October 1, 2019 13:14
Async/await without try/catch in JavaScript
async function fetchAndUpdatePosts() {
const posts = await fetchPosts().catch(() => {
console.log('error in fetching posts');
});
if (posts) {
doSomethingWithPosts(posts);
}
}
@dbayarchyk
dbayarchyk / combineCatchHandler.js
Last active October 1, 2019 11:45
Async/await without try/catch in JavaScript - combineCatchHandler.js
async function fetchAndUpdatePosts() {
let posts;
try {
posts = await fetchPosts();
doSomethingWithPosts(posts); // throws an error
} catch {
// Now it handles errors from fetchPosts and doSomthingWithPosts.
console.log('error in fetching posts');
@dbayarchyk
dbayarchyk / oldFetchAndUpdatePosts.js
Last active October 1, 2019 13:22
Async/await without try/catch in JavaScript
function fetchAndUpdatePosts() {
fetchPosts()
.then((posts) => {
updatePosts(posts)
.catch((err) => {
console.log('error in updating posts');
});
})
.catch(() => {
console.log('error in fetching posts');
@dbayarchyk
dbayarchyk / regularAsyncAwaitExample.js
Last active October 1, 2019 13:23
Async/await without try/catch in JavaScript
async function fetchAndUpdatePosts() {
let posts;
try {
posts = await fetchPosts();
} catch {
console.log('error in fetching posts');
}
if (!posts) {
@dbayarchyk
dbayarchyk / extendedRemovePostPayload.gql
Created September 22, 2019 10:50
Improve your GraphQL schema with the Relay Specification - extendedRemovePostPayload.gql
type RemovePostPayload {
removedPost: Post
removedComments: CommentConnection
}
@dbayarchyk
dbayarchyk / removePostSchemaWithPayload.gql
Created September 22, 2019 10:48
Improve your GraphQL schema with the Relay Specification - removePostSchemaWithPayload.gql
type Mutation {
removePost(id: ID!): RemovePostPayload!
}
type RemovePostPayload {
removedPost: Post
}
@dbayarchyk
dbayarchyk / removePostData.json
Last active September 22, 2019 09:51
Improve your GraphQL schema with the Relay Specification - removePostData.json
{
"data": {
"removePost": {
"id": "UG9zdDo1Y2ZiZjZjNmE2OWU5NDc2OGQ5ODQ1Mzc=",
"title": "What is GraphQL",
}
}
}
@dbayarchyk
dbayarchyk / removePostSchema.gql
Last active September 22, 2019 09:42
Improve your GraphQL schema with the Relay Specification - removePostSchema.gql
type Mutation {
removePost(id: ID!): Post
}
@dbayarchyk
dbayarchyk / postsQueryData.json
Last active September 22, 2019 09:32
Improve your GraphQL schema with the Relay Specification - postsQueryData.json
{
"data": {
"posts": {
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": false
},
"edges": [
{
"cursor": "5cfbf6c6a69e94768d984537",
@dbayarchyk
dbayarchyk / postsQuery.gql
Last active September 22, 2019 09:32
Improve your GraphQL schema with the Relay Specification - PostsQuery.gql
query PostsQuery {
posts(first: 1) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
id