godo

package module
v0.0.0-...-8f9a181 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: MIT Imports: 5 Imported by: ? 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

Learn GraphQL with Golang

Installation

We need to install the graphql package github.com/graph-gophers/graphql-go. Install the package using go get -u github.com/graph-gophers/graphql-go

Setting up the schema

We will build out the schema for our trivial todo app GraphQL API. Therefore we will be defining our schema and resolvers in schema.go and resolver.go respectively. The graphql-go will parse and validate the schema and resolvers for us. It will panic in case of any errors.

Setting up the server

We will setup the graphql endpoints and register their respective handlers.

Test

Run the main binary found inside cmd directory, it wil start a GraphQL API server on port :8080. You can use the sample curl request to test that it is responding to graphql queries as expected.

 curl -X POST -H "Content-Type: application/json" --data '{ "query": "{ tasks {id name description startDate endDate done} }" }' http://localhost:8080/tasks

Documentation

Index

Constants

View Source
const Schema = `` /* 320-byte string literal not displayed */

Variables

This section is empty.

Functions

This section is empty.

Types

type Resolver

type Resolver struct{}

func (*Resolver) Task

func (r *Resolver) Task(ctx context.Context, args struct {
	ID graphql.ID
}) (*taskResolver, error)

func (*Resolver) Tasks

func (r *Resolver) Tasks(ctx context.Context) []*taskResolver

type Task

type Task struct {
	ID          graphql.ID   `json:"id"`
	Name        string       `json:"name"`
	Description string       `json:"description"`
	StartDate   graphql.Time `json:"startDate"`
	EndDate     graphql.Time `json:"endDate"`
	Done        bool         `json:"done"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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