teleren/devto huggingface dataset:
How to build a GraphQL server with Nodejs and Express
Tags: beginners, graphql, node
Published: 2022-08-21 16:43:00

---

Being able to work with APIs and write queries is critical to any developer today. As more developers and teams opt to use GraphQL when working with APIs.

In this article, we shall learn how to build a GraphQL server with Nodejs and Express and write a query to check its working. The code in this project is on [Github](https://github.com/mine-martin/qraphql_express).

Some of the advantages of GraphQL are:- 

* Responses are decided by the client rather than the server itself. This returns exactly what the client needs.

* Facilitates the cut down of your request by allowing you to send specific requests making it to be fast.

* Each level relates to a specific type where each type describes a bunch of available fields. Allows descriptive error messages prior to executing a query.

 How about we begin

Let's start by creating an empty folder. 
```
mkdir graphqlserver
```
then 

```
cd graphqlserver
```

Change directory to _graphqlserver_ and initiate the folder by the following npm code

```
npm init
```

Create a new file _app.js_ and finally install the following packages _express_, _graphql_, and _express-graphql_

```
touch app.js

npm i express graphql express-graphql
```

The project is now set up and it's time to add our code to *app.js* file.

```
require('dotenv').config();
const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');

// GraphQL schema
const schema = buildSchema(`
  type Query {
      message: String
  }`);

//Root resolver
const root = {
  message: () => 'Welcome to GraphQL server with Nodejs and Express',
};

// Create an express server and a GraphQL endpoint

const app = express();

const Port = process.env.Port || 8080;

app.use(
  '/graphql',
  graphqlHTTP({
    schema: schema,
    rootValue: root,
    graphiql: true,
  })
);

app.listen(Port, (req, res) => {
  console.log(`Graphql Express Server is up on localhost:${Port}/graphql`);
});
```

At first, is to make sure all dependencies needed are imported *express*, *express-graphql*, and *buildSchema* function from *graphql*. Next is to create an express server with *express* instance stored in the app variable.

We create a GraphQL schema that is describing the API system. The API system includes data and how a client can access that data. Each time the API is called it is validated against the schema. It's only executed when the action proves valid else an error is returned.

Finally *app.listen* is called to start the server process on port 8000 as included on the *.env* file else on port 8080.

The Node server is ready and can be started using the below code 

`node start`

or

`node app.js`

If you don't need to keep restating your app *nodemon* will watch for any changes in the file, make sure is installed as a global dependency.

`nodemon`

<u>Graphql Express Server is up on localhost:8000/graphql</u>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a970zga0u6jc5bim49v1.png)
Communication Models of Distributed Systems
Published: 2022-08-21 16:07:00

## Introduction
In a standard distributed computing environment, the presence of message-delaying attackers (Communication delays or failures) introduces communication uncertainty. Three communication models are broadly defined for the distributed systems consensus problem. 

## Synchronous Communication model
The synchronous model defines a known finite time range ⊿ for message delivery, and an attacker can only cause a delay of at most ⊿ in the delivery of a message. In other words, when a sender sends a message, it is guaranteed to be received by the other party within a certain time ⊿. This ⊿ is known to all participants.

In real systems, this synchronization model is impractical. The reason for this is that there is known to be no upper bound on delays and temporary failures.

## Asynchronous Communication model
In the asynchronous model, only final delivery is guaranteed for message delivery, and an attacker can delay message delivery for any finite amount of time.

This asynchronous model does not allow for any assumptions to be made in the consensus algorithm. Some consensus algorithms are available for the asynchronous model, but they have very strict restrictions.

## Partial synchronous communication model
The partial synchronous model lies between the synchronous and asynchronous models. In addition to the known finite time range ⊿, there is an event called GST (global stabilization time). In the partial synchronous model, a message sent at time t will be stabilized at time max(x,GST)+⊿. In other words, the system operates in the asynchronous model up to GST and in the synchronous model after GST. The GST event must occur after an unknown finite time for the attack. 

In other words, this partial synchronization model behaves the same as the synchronization model in most cases. However, sometimes network delays, temporary failures, or clock errors mean that the upper bound is exceeded. We do not know how long the network will wait if network delays, temporary failures, or clock errors occur (equal to the asynchronous model).
I made a Personal Voice Assistant but it...(worked/failed)
Tags: python, beginners, tutorial, programming
Published: 2022-08-21 16:07:00

I searched a lot, spent 10 to 20 hours, and finally got to know this was use___

Welcome everyone
Today I will tell you the python libraries used for your voice assistant using python. Also, some important things to keep in mind will be told in the next tutorial.

Used libraries are:

```
pyttsx3
speech_recognition
os
time
wikipedia
pyfiglet
datetime
webbrowser
```

Also, we will try to make a code for a personal voice assistant in android and Java.

Thanks, A Lot
Stay Tuned
500 Stars on GitHub
Tags: contributorswanted, finance, opensource, showdev
Published: 2022-08-21 15:53:38

[Ghostfolio](https://ghostfol.io), the web-based personal finance management software, is celebrating 500 stars on GitHub. This is a major milestone for this open source project and a good time for another recap.

## Growing Community

The Ghostfolio community is growing on various platforms and has recently passed 100 members on [Slack](https://join.slack.com/t/ghostfolio/shared_invite/zt-vsaan64h-F_I0fEo5M0P88lP9ibCxFg) as well as 100 followers on [Twitter](https://twitter.com/ghostfolio_). If you have not joined yet, this is a good time to make sure you do not miss out on any future updates.

## Message Queue: Asynchronous Processing

Overall [stability and robustness](https://status.ghostfol.io) has increased significantly since the introduction of a [message queue](https://github.com/OptimalBits/bull). The workers of this robust queue system process jobs, namely gathering historical market data, asynchronously in the background to not bother the main service.

## Ready for Web 3.0

The [recent integration of Internet Identity](https://ghostfol.io/en/blog/2022/07/ghostfolio-meets-internet-identity), a blockchain authentication system, makes Ghostfolio ready for Web3. This third iteration of the World Wide Web is the vision of a new and better Internet based on decentralized blockchains to give power back to the users. Internet Identity created by the [Dfinity Foundation](https://dfinity.org) enables you to sign in securely and anonymously to Ghostfolio without an email address, username, or a password. All you need is your device with built-in biometric authentication.

## Break-even Point

Despite the complicated [economic situation](https://ghostfol.io/en/markets) at this time, the goal set at the beginning of the year to build a sustainable business and reach break-even with the SaaS offering ([Ghostfolio Premium](https://ghostfol.io/en/markets)) has been achieved. We will continue to leverage the revenue to further improve the fully managed cloud offering for our paying customers. A new goal we have set for ourselves is to become profitable.

## Outlook

Besides all the positive accomplishments during the last months, there is still a lot of room for improvement. It would be great to onboard more contributors who are actively involved in software engineering to realize the full potential of open source software. If you are a web developer and interested in personal finance, please get in touch by email via hi@ghostfol.io or on Twitter [@ghostfolio_](https://twitter.com/ghostfolio_). We are happy to discuss ideas.

We would like to say thank you for all your feedback and support since the beginning of this project.

Off to the next 500 stars!
Thomas from Ghostfolio
Which ORM do you use in Golang, gorm, xorm,sqlx, bun or sql, is there a recommended scaffold generation code?
Tags: go, generation, mysql
Published: 2022-08-21 15:29:22

---
title: Which ORM do you use in Golang, gorm, xorm,sqlx, bun or sql,  is there a recommended scaffold generation code?
published: true
description: 
tags: [golang, generation, mysql]
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---

https://github.com/anqiansong/sqlgen

From the github, the golang orm with the top number of stars are gorm, xorm, sqlx, bun, etc. Although gorm provides a supporting scaffolding, but its difficulty is discouraging, xorm, sqlx, bun has not found a supporting scaffolding, we know that sqlc provides rich model generation functions, but its sql annotation rules are relatively rich, there are learning costs, but its rich functionality can cover most of the business queries, which is worth affirming, I refer to sqlc also wrote a sqlgen scaffolding, sql annotation rules are very simple, can also meet most of the scenarios, currently supports gorm, xorm, sqlx, bun and native sql code generation, which makes me use orm to greatly reduce the learning and development costs and improve the development efficiency. Share out welcome to build and learn together.
React.js task list with cool annimations
Tags: react, javascript, front, end
Published: 2022-08-21 15:15:36

Making a simple task list with react.js.
Using useState() hook.

Github Source: https://github.com/0xMALVEE/react-tasklist
Video Making it : https://youtu.be/CFmPWx_Ilbc

Beginner React.js project.
Table Trigger | SQL
Tags: sql, dmltrigger, sqltrigger, updatestatement
Published: 2022-10-11 21:49:15

---
title: Table Trigger | SQL
published: true
date: 2022-08-21 15:12:55 UTC
tags: SQL,DMLTrigger,SQLTrigger,UpdateStatement
canonical_url: 
---

Let’s continue to improve our sample database, now by adding a table trigger on one of our tables.

The triggers can be either INSERT, UPDATE or DELETE clause when we speak in terms of **D** ata **M** anipulation **L** anguage. Its execution part usually contains a store procedure or a batch.

For demonstration purposes, let’s add two new columns to our customer table on our sample Database. (If you want to follow the next step and you missed the table creation, please check the following [post](https://dev.to/toolgbrmaker/create-a-table-sql-1hh4)).

![](https://toolgbrmaker.files.wordpress.com/2022/05/image-10.png?w=412)
_Current Customer’s Table schema_

![](https://toolgbrmaker.files.wordpress.com/2022/05/image-13.png?w=1024)
_ALTER TABLE to add columns to Customer’s table_

Now that we have two new columns it’s time to add our table trigger, it will be a simple one that will update **LastModificationDate** column every time an update is performed for this table.

![](https://toolgbrmaker.files.wordpress.com/2022/05/image-14.png?w=931)
_CREATE TRIGGER statement – example_

![](https://toolgbrmaker.files.wordpress.com/2022/08/image-4.png?w=267)
_Object Explorer View_

I’ll now import a few more Customers to my table by using the CSV importation already learned here in this [post](https://dev.to/toolgbrmaker/importing-data-by-csv-sql-i0k). (Please have a look if you missed that one!)

![](https://toolgbrmaker.files.wordpress.com/2022/05/image-15.png?w=706)
_Data belonging to the CSV file to be imported_

![](https://toolgbrmaker.files.wordpress.com/2022/08/image-1.png?w=694)
_All the dataset from the Customer’s table_

Now that we have these two new columns and our new DML trigger, let’s test it by changing something on one of our rows. I think that nowadays Portuguese president should be annoyed by my mistake on his last name and is looking forward to the correction from “Sousa” to “de Sousa”. **( Sorry Professor :D)**.

![](https://toolgbrmaker.files.wordpress.com/2022/08/image-2.png?w=317)
_UPDATE customer_

After running our column update, if we select all table rows we’ll be able to find that LastModificationDate is now updated for the update execution DateTime.

![](https://toolgbrmaker.files.wordpress.com/2022/08/image-3.png?w=734)
_All the dataset from the Customer’s table_

Let me know if any doubt remained and stay safe!
This is why your React state might not be updating!
Tags: javascript, react, tutorial
Published: 2022-08-21 14:58:04

Hi guys! Today I'd like to share a simple bug that I have found all the time when I first start learning React😅. Although the state is not updating on re-render, there is nothing related to virtual DOM or react-related concepts here. Instead this is a mistake that you might come across when coding in VanillaJS‼️

---

## Goal
Let say you have a list of numerous items, each item has a button and increment its value when being clicked

## My attempts
My state looks like this:
```javascript
const [Test, setTest] = useState([
    {
      name: 'Eric',
      value: 0
    },
    {
      name: 'Frank',
      value: 20
    },
    // and more....
  ])
```
Rendering part looks like this:

```javascript
<div className="App">
      {
        Test.map((item, idx) => (
          <button
          key={idx}
            onClick={(e) => {
              e.preventDefault()
              setTest((value) => {
                value.find(element => element.name === item.name).value += 1
                return value
              })
            }}
          >
            {
              item.name + ': ' + item.value
            }
          </button>
        ))
      }
    </div>
```
Let's see...

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vb88dogpb4mjaxv9w5rb.gif)

## Second attempt (90% of the time I make this mistake😷)
I've learnt that I should use an updater of setState, however it seems I have use it the wrong way🤒 **I have mutated the state directly**. Let's fix that by creating a new copy of the previous state.

```javascript
//...
    <button
      key={idx}
      onClick={(e) => {
        e.preventDefault()
        setTest((value) => {
          let temp = value
          temp.find(element => element.name === item.name).value += 1
          return temp
        })
      }}
    >
      {
        item.name + ': ' + item.value
      }
    </button>
//...
```
## My Solution
The code that does the job:

```javascript
//... 
  setTest((value) => {
    let temp = [...value] 
    temp.find(element => element.name === item.name).value += 1
    return temp
  })
//...
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5sy5117zz861yl5n7zg.gif)
Spread operator`...` does help create a copy of the original state so that we don't mutate the original state, but this is just a **one level shallow copy**, it is **still not recommended** when dealing with nested object. <br>
In our case, the element of state array is an object, which means the elements are **reference**, mutating them is still mutating the original state.<br>
Moreover, nested state is not the intended use of React state, if you find yourself making a heavily nested state, you are not using it correctly!🦥 <br>
What do you think about it? Do you know any better solution? Did you come up with this problem and how do you solve it? Let me know in the comment!🙈 <br>Cheers!
My Reading Bookmarks
Tags: beginners
Published: 2022-08-21 14:48:11

These are my bookmarks I hope who ever sees this find it useful 
Note: these are not sorted i guess you would find it tedious :) 
https://www.careercliff.com/situational-interview-questions-and-answers/
https://www.lifesimile.com/i-want-to-change-my-life/
https://www.seafishpool.com/angler-fish-reproduction/
https://www.dogdwell.com/thai-ridgeback/
https://www.birdbaron.com/spixs-macaw/
https://www.hippohaven.com/lake-tahoe-hotels/
https://www.rhinorest.com/things-to-do-in-zanzibar/
https://www.primatespark.com/best-type-of-monkey-for-a-pet/
https://www.quotesmuse.com/short-new-year-wishes/
https://www.triviaquestionquiz.com/world-history-trivia-questions-and-answers/
https://www.biographyicon.com/nelson-mandela-motivational-quotes/
https://www.countryfaq.com/nordic-countries-list/
https://www.inventiongen.com/inventions-in-the-80s/
https://www.mammalage.com/eurasian-badger/
https://www.howtoripe.com/benefits-of-eating-dark-chocolates/
https://www.catbounty.com/characteristics-of-a-good-manager/
https://www.horserule.com/importance-of-fitness-and-nutrition/
https://www.teafame.com/benefits-of-drinking-moringa-leaf-tea/
https://ask7wh.blogspot.com/
https://indexc.blogspot.com/
https://sportsfacts247.blogspot.com/
https://bodymassagehabit.blogspot.com/
https://painreliefadvice.blogspot.com/
https://motivationtoday01.blogspot.com/
https://riceandducks.blogspot.com/
https://famouspeopletruth.blogspot.com/
https://horserover.blogspot.com/
https://answermyquestion247.blogspot.com/
https://buymydeal.blogspot.com/
https://techgadgetduniya.blogspot.com/
https://catbreedslab.blogspot.com/
https://fishrover.blogspot.com/
https://quotewishstatus.blogspot.com/
https://quizonlinequestions.blogspot.com/
https://howdoyoublog365.blogspot.com/
https://8whfacts.blogspot.com/
https://onlinemoneymakingclue.blogspot.com/
https://besthostinghints.blogspot.com/
https://guestpostingsiteinfo.blogspot.com/
https://beautytipstoday365.blogspot.com/
https://digitalmarketinghook.blogspot.com/
https://englishlearnadvice.blogspot.com/
https://selfdevelopmentgoal.blogspot.com/
https://careercliff.blogspot.com/
https://growreadinghabit.blogspot.com/
https://aitoautomation.blogspot.com/
https://startuproar.blogspot.com/
https://digitaltrustsolutions.blogspot.com/
https://travelandsnacks.blogspot.com/
https://10bestfacts.blogspot.com/
https://rightgiftidea.blogspot.com/
https://parentingaz.blogspot.com/
https://microniche100ideas.blogspot.com/
https://factinquest.blogspot.com/
https://infographics4.blogspot.com/
Typescript Series - Awaited Type
Tags: javascript, webdev, programming, typescript
Published: 2022-08-21 14:44:48

I'd like to start by saying that I am doing this series to learn and understand better Typescript, so feel free to correct me or contact me.

**If we have a type which is wrapped type like Promise. How we can get a type which is inside the wrapped type?**

Let's see a couple of examples 

```
type Example1 = Promise<string>
type Example2 = Promise<{ field: number }>
type Example3 = Promise<Promise<string | number>>


type Result1 = MyAwaited<Example1> // string
type Result2 = MyAwaited<Example2> // { field: number }
type Result3 = MyAwaited<Example3> // string | number

```

Worth noticing here, that we should also take nested promises into account.

How would this type would look like?

```
type MyAwaited<Type> = Type extends Promise<infer K> 
? MyAwaited<K> : Type;
```

### Understanding the infer keyword
The infer keyword can be used within a condition in a conditional type to put the inferred type into a variable. That inferred variable can then be used within the conditional branches.

Let's break it down:

`Type extends Promise<infer K>` Here we check if Type extends a Promise type and we **infer** the type that is wrapped inside.

If it does extend it, meaning our Type is of type Promise (ex: Promise<Promise<string | number>>), then  we use recursion to check again `MyAwaited<K>` 

if it does **not** extend it, then we just simply return the Type

Thank you!

you can find me here [My Twitter] (https://twitter.com/sarmunbustillo?t=pztqXmT7DH2pa9lDLjfrdQ&s=09)
Difference Between Error and Exception With Examples
Tags: javascript, webdev, programming, discuss
Published: 2022-08-21 14:32:00

Errors occur when something wrong or invalid happens in the code or the program's environment in which it is running. It can be syntax, logical or runtime errors, and from the environment, it can be a lack of resources or version incompatibilities etc.
**Exceptions** are thrown by a programmer when certain conditions in the code are being met by using the throw keyword. And we can catch the exception by using the try and catch block.

## Errors

1. Serious problems you should not try to catch or handle them
2. It is not possible to recover from an error.
3. Errors occur at runtime. That is why they are unknown to a compiler. Hence they are classified as “unchecked exceptions.”
4. Unknown to a programmer

## Exceptions

1. Known to a programmer and can be guessed
2. Caused by the application itself
3. Exceptions can be “checked” or “unchecked.”
4. The try and catch blocks can handle exceptions and recover the application from them.

```javascript
//You can copy and paste the code into your console tab
//You can throw a string, object or even error

//Throwing string message
try {
    throw "throwing string"
} catch (ex) {
    console.log(ex);
}

//VM54:4 throwing string

//Throwing an error
try {
    throw new Error("throwing string")
} catch (ex) {
    console.log(ex);
}

/*VM158:4 Error: throwing string
    at <anonymous>:2:11
*/

//As of Echma 2022 we can use the cause with error
try {
    throw new Error("throwing string", {cause: "Just like that"})
} catch (ex) {
    console.log(ex, ex.cause);
}

/*VM342:4 Error: throwing string
    at <anonymous>:2:11 'Just like that'
*/

//throwing object
try {
    throw {msg: "Condition met"}
} catch (ex) {
    console.log(ex);
}

//VM517:4 {msg: 'Condition met'}

//Of course we can use finally too

try {
    throw "With finally"
} catch (ex) {
    console.log(ex);
} finally {
    console.log("I'm going to run no matter what!")
}

/*VM5528:4 With finally
VM5528:6 I'm going to run no matter what!*/
```

Please comment if you want to discuss it further or if I missed something.

Thanks for reading.