Exemple d'API GraphQL, PostgresQL, en Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Matthieu Lamalle fad6b6536a add jwt auth for future use 1 month ago
config implement config file 1 month ago
mutations first issue 1 month ago
postgres implement config file 1 month ago
queries implement config file 1 month ago
security add jwt auth for future use 1 month ago
types first issue 1 month ago
LICENSE Initial commit 1 month ago
README.md implement config file 1 month ago
graphql implement config file 1 month ago
main.go implement config file 1 month ago

README.md

gographql

Exemple d’API GraphQL, PostgresQL, en Go

go build && go run .

Accéder à l’API :

http://localhost:8383/graphql

Accéder à l’UI graphiql :

http://localhost:8383

Query

Toute rếquete visant à récupérer une donnée est appellée une ‘Query’

# Query via curl

curl -X POST \
    -H 'Content-Type: application/json' \
    -d '{"query": " query { user { id,firstname,lastname,roles{name} } }"}' \
    http://localhost:8383/graphql

# Query via GraphQL

query GetAllUsers {
  user {
    id
    firstname
    lastname
    roles {
      name
    }
  }
}

Mutation

Toute requếte visant à modifier une donnée est appellée une ‘Mutation’

# Mutation via curl

curl -X POST \
    -H 'Content-Type: application/json' \
    -d '{"query": "mutation { createUser(firstname: \"John\", lastname: \"Snow\") { id,firstname,lastname } }"}' \
    http://localhost:8383/graphql

# Mutation via GraphQL

mutation CreateUser($firstname: String!, $lastname: String!) {
  createUser(firstname: $firstname, lastname: $lastname) {
    id
    firstname
    lastname
  }
}

Postgres

Si besoin, lancer un serveur postgres via Docker

mkdir $HOME/docker/postgres/volumes

docker run --rm -d \
     --name postgres \
     -e POSTGRES_PASSWORD=postgres \
     -p 5432:5432 \
     -v $HOME/docker/postgres/volumes:/var/lib/postgresql/data \
     postgres

psql -U postgres -h localhost
> create user graphql;
> alter user graphql with encrypted password 'graphql';
> create database graphql;
> GRANT ALL PRIVILEGES ON DATABASE "graphql" to graphql;
> \exit

psql -U graphql -h localhost
> CREATE TABLE users (
id SERIAL PRIMARY KEY,
firstname TEXT,
lastname TEXT
  );

> CREATE TABLE roles (
id SERIAL PRIMARY KEY,
name TEXT 
  );