Skip to content

Commit

Permalink
Add graphql.Time example (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
roaris authored Mar 20, 2022
1 parent 9296b87 commit d48b659
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions example/scalar_time/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"log"
"net/http"
"time"

graphql "github.com/graph-gophers/graphql-go"
"github.com/graph-gophers/graphql-go/relay"
)

type query struct{}

func (_ *query) CurrentTime() graphql.Time {
return graphql.Time{Time: time.Now()}
}

func main() {
s := `
scalar Time
type Query {
currentTime: Time!
}
`
schema := graphql.MustParseSchema(s, &query{})
http.Handle("/query", &relay.Handler{Schema: schema})

log.Println("Listen in port :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}

0 comments on commit d48b659

Please sign in to comment.