gographql

command module
v0.0.0-...-fad6b65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2019 License: GPL-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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 
  );

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址