graphql-go

module
v0.0.0-...-54a2533 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: Apache-2.0

README

graphql-go

Example API on graphql go using gqlgen https://hasura.io/blog/building-a-graphql-api-with-golang-postgres-and-hasura/

Setups

go install github.com/99designs/gqlgen@latest
# false import
go run github.com/99designs/gqlgen init

Insatll postgres

psql postgres
postgres# CREATE database graphql
CREATE TABLE movies (
	id serial PRIMARY KEY,
	title VARCHAR (50) NOT NULL,
	url VARCHAR (50) NOT NULL,
    release_date timestamp NOT NULL DEFAULT NOW()

);

Run

go run server.go
Request
query getMovies {
  movies {
    title
    url
  }
}
Response
{
  "data": {
    "movies": [
      {
        "title": "Rise of GraphQL Warrior Pt1",
        "url": "https://riseofgraphqlwarriorpt1.com/"
      },
      {
        "title": "Iron Man",
        "url": "https://ironman.com"
      }
    ]
  }
}

Client starts at: localhost:38080

Development

Changes to schema is made in ./graph/schema.graphqls file and then we run go run github.com/99designs/gqlgen generate, to get generate the resolvers in ./graph/schema.resolvers.go file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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