~bigbes/sr-ht-dolt

ref: 12c7ff77f8281cd0ca61177bcf07b9c031a04c97 sr-ht-dolt/cmd/doltsrht/graphql.go -rw-r--r-- 2.3 KiB
12c7ff77 — Eugene Blikh ci: publish this build's own coverage and benchmarks 2 days ago
                                                                                
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main

import (
	"context"

	"github.com/vaughan0/go-ini"

	"sourcecraft.dev/bigbes/sr-ht-dolt/browse"
	"sourcecraft.dev/bigbes/sr-ht-dolt/graph"
	"sourcecraft.dev/bigbes/sr-ht-dolt/web"
)

// queryRoute is where the GraphQL schema answers. It is core-go's own path,
// because that is where every SourceHut client — hut, api.sr.ht, meta's
// personal-token page — already looks. The file beside it is served by
// ecore's apimeta, at apimeta.Path.
const queryRoute = "/query"

// repoScopeName is the one grant this service defines, spelled as meta.sr.ht
// expects it: the part after the service name in authn.RepoScope
// ("dolt.sr.ht/repos"). meta prefixes the service name itself. The two
// spellings are the same fact written twice, so a test asserts them equal —
// a drift would let a user mint a token meta calls valid and this service does
// not honour.
const repoScopeName = "repos"

// graphBrowseOpener satisfies graph.BrowseOpener over browse.Open, as
// mcpBrowseOpener does for the MCP surface and web.BrowseAdapter for the pages:
// one *browse.DB answers all three method sets, and each package declares the
// seam it consumes rather than importing another's.
type graphBrowseOpener struct{}

var _ graph.BrowseOpener = graphBrowseOpener{}

func (graphBrowseOpener) Open(ctx context.Context, diskPath string) (graph.BrowseSession, error) {
	dbh, err := browse.Open(ctx, diskPath)
	if err != nil {
		return nil, err
	}
	return dbh, nil
}

// newGraphServer assembles /query over the seams the daemon already has: the
// same request-scoped metadata adapter the web pages and the MCP tools read
// through, and the same bare-store reader.
//
// It shares /mcp's credential plane, validator included, so an instance that
// runs no tokens.sr.ht refuses a working token on both surfaces and accepts
// meta PATs and anonymous callers on both. Its failures are fatal for the same
// reason /mcp's are: a surface that answers every query "could not be read"
// because a seam was never wired is a daemon that starts and does not work.
func newGraphServer(conf ini.File) (*graph.Server, error) {
	validator, err := newBearerValidator(conf)
	if err != nil {
		return nil, err
	}
	return graph.New(graph.Options{
		Repos:     web.DBAdapter{},
		Browse:    graphBrowseOpener{},
		Validator: validator,
	})
}