feat: initial commit
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
package ctl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/Khan/genqlient@main ./genqlient.yaml
|
||||
|
||||
func Publish(apiKey, schemaRef, service, sdl string, url, wsUrl *url.URL, schemasUrl url.URL) (*SubGraph, error) {
|
||||
client := graphql.NewClient(schemasUrl.String(), &http.Client{Transport: NewTransport(http.DefaultTransport, apiKey)})
|
||||
var urlString *string
|
||||
if url != nil {
|
||||
temp := url.String()
|
||||
urlString = &temp
|
||||
}
|
||||
var wsUrlString *string
|
||||
if wsUrl != nil {
|
||||
temp := wsUrl.String()
|
||||
wsUrlString = &temp
|
||||
}
|
||||
response, err := UpdateSubGraph(context.Background(), client, &InputSubGraph{
|
||||
Ref: schemaRef,
|
||||
Service: service,
|
||||
Url: urlString,
|
||||
WsUrl: wsUrlString,
|
||||
Sdl: sdl,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SubGraph{
|
||||
Service: response.UpdateSubGraph.Service,
|
||||
URL: response.UpdateSubGraph.Url,
|
||||
WSUrl: response.UpdateSubGraph.WsUrl,
|
||||
ChangedBy: response.UpdateSubGraph.ChangedBy,
|
||||
ChangedAt: response.UpdateSubGraph.ChangedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func List(apiKey, schemaRef, service string, schemasUrl url.URL) ([]*SubGraph, error) {
|
||||
client := graphql.NewClient(schemasUrl.String(), &http.Client{Transport: NewTransport(http.DefaultTransport, apiKey)})
|
||||
response, err := SubGraphs(context.Background(), client, schemaRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subGraphs := make([]*SubGraph, len(response.SubGraphs))
|
||||
for i, subGraph := range response.SubGraphs {
|
||||
subGraphs[i] = &SubGraph{
|
||||
Service: subGraph.Service,
|
||||
URL: subGraph.Url,
|
||||
WSUrl: subGraph.WsUrl,
|
||||
ChangedBy: subGraph.ChangedBy,
|
||||
ChangedAt: subGraph.ChangedAt,
|
||||
}
|
||||
}
|
||||
return subGraphs, nil
|
||||
}
|
||||
Reference in New Issue
Block a user