GithubHelp home page GithubHelp logo

honerlaw / fruits-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from franqsanz/fruits-api

0.0 0.0 0.0 324 KB

🍎 A GraphQL API with fruit tree data. Built with 🚀 Apollo Server Lambda + Netlify Lambda.

Home Page: https://fruits-api.netlify.app/graphql

License: MIT License

JavaScript 99.67% Dockerfile 0.33%

fruits-api's Introduction

Fruits API

Open in Visual Studio Code Netlify Status License License GitHub Pull Requests GitHub contributors

Leer en Español

GraphQL API with fruit tree data. This API is built with Apollo Server Lambda + Netlify Lambda.

In this project I am not using a database. The data is in data.js, in case you want to add more information :)

Contribute

Read the CONTRIBUTING.md file or check if there are any issues, all PRs are welcome.

URLs

Playground: https://fruits-api.netlify.app/graphql

Web: https://fruit-api.netlify.app/

Get the code for this project

  1. Clone repository:
git clone https://github.com/Franqsanz/fruits-api.git
  1. Enter to the repository directory:
cd fruits-api
  1. Install all dependencies:
npm install

# Or with yarn
yarn
  1. Once all the dependencies are installed run the following command:
npm start

yarn start
  1. Run Testing (optional):
npm test

yarn test

As an alternative, you can use Docker

  1. Open your terminal/command line
  2. Run docker-compose up

Once the API is executed, if all goes well you should see in your terminal the following message: Lambda server is listening on 9000, open your browser and put in the URL http://localhost:9000/graphql and this will load the GraphQL Playground, you should see the following:

playground

Obviously the playground will be empty, you should make the queries.

Intruduction

This documentation will help you become familiar with the Fruits API resources and show you how to make different queries.

API Schema

Key Type Description
id ID Tree ID
scientific_name String Scientific name of the tree
tree_name String Tree name
fruit_name String Fruit name
family String Tree family type
origin String Tree origin
description String Brief tree description
bloom String Flowering date of the tree
maturation_fruit String Fruit ripening date
life_cycle String Tree life cycle
climatic_zone String Tree climate zone
producing_countries Array Countries that produce fruit trees.

Type Query

Get all trees

You can access the trees list with the following query

Query example:

query allFruits {
  fruits {
    id
    scientific_name
    fruit_name
    description
    producing_countries {
      country
    }
  }
}

Response:

{
  "data": {
    "fruits": [
      {
        "id": "1",
        "scientific_name": "Malus domestica",
        "fruit_name": "Apple",
        "description": "The apple is the fruit of the apple tree, a tree of the rosaceae family. It is a pome fruit with a round shape and a more or less sweet flavor, depending on the variety. The apple is a deciduous tree, generally 2 to 4.5 m (6 to 15 ft) tall in cultivation and up to 9 m (30 ft) in the wild..",
        "producing_countries": [
          {
            "country": "China",
          },
          {
            "country": "United States",
          },
          // ...
        ]
      },
      {
        "id": "2",
        "scientific_name": "Pyrus Communis",
        "fruit_name": "Pear",
        "description": "The pear is the fruit of the pear tree, a tree of the rosaceae family. The fruit is an edible knob of brownish green. It is a species of deciduous tree, generally 2 to 20 m high.",
        "producing_countries": [
          {
            "country": "China",
          },
          {
            "country": "Italy",
          },
          // ...
        ]
      },

      // ...
    ]
  }
}

Get a single tree

You can get a single tree by adding the id as parameter: (id: 5).

Query example:

query oneFruit {
  fruit(id: 5) {
    id
    scientific_name
    tree_name
    fruit_name
    family
  }
}

Response:

{
  "data": {
    "fruit": {
      "id": "5",
      "scientific_name": "Citrus x Tangerina",
      "tree_name": "Tangerine",
      "fruit_name": "Tangerine",
      "family": "Rutaceae"
    }
  }
}

Tree filtering

You can also filter trees by family or origin, for example: (family: "Rosaceae") or (origin: "Asia").

Query example:

query filterFruit {
 filterFruitsFam(family: "Rosaceae") {
    id
    tree_name
    fruit_name
    family
  }
}

Response:

{
  "data": {
    "filterFruitsFam": [
      {
        "id": "1",
        "tree_name": "Apple",
        "fruit_name": "Apple",
        "family": "Rosaceae"
      },
      {
        "id": "2",
        "tree_name": "Pear",
        "fruit_name": "Pear",
        "family": "Rosaceae"
      }
    ]
  }
}

Type Mutation

In this API you can make Mutations, although the data will not be stored persistently. You can add, update and delete.

All fields are required.

How to add a tree

mutation addFruit {
 addFruit(
    id: 1
    scientific_name: "Malus Domestica"
    tree_name: "Apple"
    fruit_name: "Apple"
    family: "Rosaceae"
    origin: "Asia Central"
    description: "The Rosaceae apple is the fruit of the apple tree, a tree of the Rosaceae family. It is a pome-shaped fruit"
    bloom: "Spring"
    maturation_fruit: "Late summer or fall"
    life_cycle: "60-80 years"
    climatic_zone: "cold"
 ) {
    id
    scientific_name
    tree_name
    fruit_name
    family
    origin
    description
    bloom
    maturation_fruit
    life_cycle
    climatic_zone
 }
}

How to upgrade a tree

mutation updateFruit {
  updateFruit(
    id: 1
    scientific_name: "Malus Domestica"
    tree_name: "Apple"
    fruit_name: "Apple"
    family: "Rosaceae"
    origin: "Central Asia"
    description: "The Rosaceae apple is the fruit of the apple tree, a tree of the Rosaceae family. It is a pome-shaped fruit"
    bloom: "Spring"
    maturation_fruit: "Late summer or fall"
    life_cycle: "60-80 years"
    climatic_zone: "Cold"
 ) {
    id
    scientific_name
    tree_name
    fruit_name
    family
    origin
    description
    bloom
    maturation_fruit
    life_cycle
    climatic_zone
 }
}

How to delete a tree

mutation deleteFruit {
 deleteFruit(id: 9) {
   id
   scientific_name
 }
}

Made with ❤ by Franco Andrés Sánchez

fruits-api's People

Contributors

cmjchrisjones avatar emmebravo avatar evertcode avatar fonta22 avatar franqsanz avatar gastonarevalo avatar germanruzca avatar ingrid-e avatar ishukrpathak avatar jatin41 avatar mtrunt avatar nohelybc avatar paoladaft avatar rjrishika avatar satyamrs00 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.