Skip to content

jlum85/graphql-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graphql

Exemple d'utilisation de GraphQL avec Node.js et Express

Dépendances

npm install express graphql express-graphql

Requête

http://localhost:3000/graphql

{
	posts {
	    title
	    description
        author {
            name
            age
        }
	}
}

Résultat

{
  "data": {
    "posts": [
      {
        "title": "First post",
        "description": "Content of the first post",
        "author": {
          "name": "Flavio",
          "age": 36
        }
      },
      {
        "title": "Second post",
        "description": "Content of the second post",
        "author": {
          "name": "Roger",
          "age": 7
        }
      }
    ]
  }
}

Get id

{
	post(id: 0) {
	  title
	  description
	}
}
{
  "data": {
    "post": {
      "title": "First post",
      "description": "Content of the first post"
    }
  }
}

from

https://flaviocopes.com/graphql-node-express/