Zendro-dev / graphql-server

Skeleton NodeJS project for a graphQL server.
GNU General Public License v3.0
0 stars 1 forks source link

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:

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

Optional (without defaults)

Optional (with sensible defaults)

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.