File: example_time_test.go

package info (click to toggle)
golang-github-graph-gophers-graphql-go 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,516 kB
  • sloc: sh: 373; javascript: 21; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package graphql_test

import (
	"context"
	"encoding/json"
	"os"
	"time"

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

type tquery struct{}

func (*tquery) CurrentTime() graphql.Time {
	return graphql.Time{Time: time.Date(2023, 2, 6, 12, 3, 22, 0, time.UTC)}
}

func ExampleTime() {
	const s = `
		scalar Time

		type Query {
			currentTime: Time!
		}
	`
	schema := graphql.MustParseSchema(s, &tquery{})

	const query = "{ currentTime }"
	res := schema.Exec(context.Background(), query, "", nil)

	err := json.NewEncoder(os.Stdout).Encode(res)
	if err != nil {
		panic(err)
	}

	// output:
	// {"data":{"currentTime":"2023-02-06T12:03:22Z"}}
}