File: caching.go

package info (click to toggle)
golang-github-graph-gophers-graphql-go 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,452 kB
  • sloc: sh: 373; javascript: 21; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
package caching

import (
	"context"
	"time"

	"github.com/graph-gophers/graphql-go/example/caching/cache"
)

const Schema = `
	schema {
		query: Query
	}

	type Query {
		hello(name: String!): String!
		me: UserProfile!
	}

	type UserProfile {
		name: String!
	}
`

type Resolver struct{}

func (r Resolver) Hello(ctx context.Context, args struct{ Name string }) string {
	cache.AddHint(ctx, cache.Hint{MaxAge: cache.TTL(1 * time.Hour), Scope: cache.ScopePublic})
	return "Hello " + args.Name + "!"
}

func (r Resolver) Me(ctx context.Context) *UserProfile {
	cache.AddHint(ctx, cache.Hint{MaxAge: cache.TTL(1 * time.Minute), Scope: cache.ScopePrivate})
	return &UserProfile{name: "World"}
}

type UserProfile struct {
	name string
}

func (p *UserProfile) Name() string {
	return p.name
}