Zendro-dev / graphql-server

Skeleton NodeJS project for a graphQL server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zendro GraphQL Server

Skeleton NodeJS project for a graphQL server.

This package provides a scaffold to be completed with contents generated by the code-generator.

Set up

Clone the repository and use the Code-generator to dynamically generate the contents of four folders with the models information:

  • models
  • schemas
  • resolvers
  • migrations

After getting ready the generated code for the models, proceed with the server set up.

$ npm install
$ bash migrateDbAndStartServer.sh
$ npm start

The script $ migrateDbAndStartServer.sh will create the tables specified in the migrations folder of each database configuration, using the credentials specified in config/data_models_storage_config.json file.

NOTE: Databases should be already configured locally in config/data_models_storage_config.json.

Environment Variables

Create a .env file with your desired environment variables.

Mandatory

  • ALLOW_ORIGIN - Sets the Access-Control-Allow-Origin header to the specified value.
  • JWT_SECRET - The secret string used to sign authorization tokens.

Optional (without defaults)

  • MAIL_SERVICE - For bulk add operations, the email service to use for sending progress reports.
  • MAIL_HOST - Email service host (usually SMTP config).
  • MAIL_ACCOUNT - Sender email account address.
  • MAIL_PASSWORD - Sender email account password.

Optional (with sensible defaults)

  • ERROR_LOG - Debug logs verbosity. Can be either "verbose" or "compact". Default value is compact.
  • EXPORT_TIME_OUT - Maximum amount of time in milliseconds before the server throws a timeout error when exporting data. Default is 3600.
  • LIMIT_RECORDS - Maximum number of records that each request can return, default value is 10000.
  • PORT - The port where the app is listening, default value is 3000
  • POST_REQUEST_MAX_BODY_SIZE - Maximum size of the GraphQL request in MB. Default is 1mb.
  • MAX_TIME_OUT - Maximum number of milliseconds that a zendro server will wait to connect with another zendro server. Default value is 2000.
  • REQUIRE_SIGN_IN - Boolean to toggle the required sign in to the graphql server. Default is true.
  • SALT_ROUNDS - Number of salt rounds when hashing a new password. Default is 10.

Examples

If you followed the example for generating the code described here, you can try the next queries and mutations. Otherwise, just adapt the same queries and mutations for your own models generated.

We will add the next 4 people to our table people.

Name (firstName) Last Name (lastName) Email (email)
Albert Einstein albert.einstein@science.com
Thomas Edison thomas.edison@science.com
Vincent van Gogh vicent.vanGogh@art.com
Ludwig Beethoven ludwing.beethoven@art.com

CREATE PERSON

curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql' -d 'mutation M { addPerson(firstName: "Albert", lastName: "Einstein", email: "albert.einstein@science.com"){ firstName email } }'

As result we will get firsName and email of the person just created:

{
  "data": {
    "addPerson": {
      "firstName": "Albert",
      "email": "albert.einstein@science.com"
    }
  }
}

In the same way we add the next 3 people:

curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql' -d 'mutation M { addPerson(firstName: "Thomas", lastName: "Edison", email: "thomas.edison@science.com") { firstName email } }'

curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql' -d 'mutation M { addPerson(firstName: "Vicent", lastName: "van Gogh", email: "vicent.vanGogh@art.com"){ firstName email } }'

curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql' -d 'mutation M { addPerson(firstName: "Ludwig", lastName: "Beethoven", email: "ludwig.beethoven@art.com"){ firstName email } }'

SEARCH PEOPLE WITH FILTER

We'll search people with 'science' as substring of their email and as result we'll get only their name and last name.

curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql' -d '{ people(search:{field:email, value:{value:"%science%"}, operator:like}){ firstName lastName}}'

The result will be:

{
  "data": {
    "searchPerson": [
      {
        "firstName": "Albert",
        "lastName": "Einstein"
      },
      {
        "firstName": "Thomas",
        "lastName": "Edison"
      }
    ]
  }
}

Contributions

Zendro is the product of a joint effort between the Forschungszentrum Jülich, Germany and the Comisión Nacional para el Conocimiento y Uso de la Biodiversidad, México, to generate a tool that allows efficiently building data warehouses capable of dealing with diverse data generated by different research groups in the context of the FAIR principles and multidisciplinary projects. The name Zendro comes from the words Zenzontle and Drossel, which are Mexican and German words denoting a mockingbird, a bird capable of “talking” different languages, similar to how Zendro can connect your data warehouse from any programming language or data analysis pipeline.

Zendro contributors in alphabetical order

Francisca Acevedo1, Vicente Arriaga1, Katja Dohm3, Constantin Eiteneuer2, Sven Fahrner2, Frank Fischer4, Asis Hallab2, Alicia Mastretta-Yanes1, Roland Pieruschka2, Alejandro Ponce1, Yaxal Ponce2, Francisco Ramírez1, Irene Ramos1, Bernardo Terroba1, Tim Rehberg3, Verónica Suaste1, Björn Usadel2, David Velasco2, Thomas Voecking3, Dan Wang2

Author affiliations

  1. CONABIO - Comisión Nacional para el Conocimiento y Uso de la Biodiversidad, México
  2. Forschungszentrum Jülich - Germany
  3. auticon - www.auticon.com
  4. InterTech - www.intertech.de

Zendro author contributions

Asis Hallab and Alicia Mastretta-Yanes coordinated the project. Asis Hallab designed the software. Programming of code generators, the browser based single page application interface, and the GraphQL application programming interface was done by Katja Dohm, Constantin Eiteneuer, Francisco Ramírez, Tim Rehberg, Veronica Suaste, David Velasco, Thomas Voecking, and Dan Wang. Counselling and use case definitions were contributed by Francisca Acevedo, Vicente Arriaga, Frank Fischer, Roland Pieruschka, Alejandro Ponce, Irene Ramos, and Björn Usadel. User experience and application of Zendro on data management projects was carried out by Asis Hallab, Alicia Mastretta-Yanes, Yaxal Ponce, Irene Ramos, Verónica Suaste, and David Velasco. Logo design was made by Bernardo Terroba.

About

Skeleton NodeJS project for a graphQL server.

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%