Skip to content

Commit ebcbd1f

Browse files
authored
Merge pull request #1091 from CircleCI-Public/develop
Remove introspection query from `setup` & `diagnostic` commands
2 parents 591d7b2 + cb22920 commit ebcbd1f

File tree

13 files changed

+209
-542
lines changed

13 files changed

+209
-542
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ orbs:
88
executors:
99
go:
1010
docker:
11-
- image: cimg/go:1.21.5
11+
- image: cimg/go:1.23.4
1212
resource_class: large
1313
environment:
1414
CGO_ENABLED: 0
@@ -103,8 +103,8 @@ jobs:
103103
steps:
104104
- checkout
105105
- run: |
106-
curl -OL https://go.dev/dl/go1.21.5.darwin-arm64.pkg
107-
sudo installer -pkg ./go1.21.5.darwin-arm64.pkg -target /
106+
curl -OL https://go.dev/dl/go1.23.4.darwin-arm64.pkg
107+
sudo installer -pkg ./go1.23.4.darwin-arm64.pkg -target /
108108
echo 'export PATH="/usr/local/go/bin:$PATH"' >> ~/.bash_profile
109109
- gomod
110110
- run: make test
@@ -177,7 +177,7 @@ jobs:
177177

178178
lint:
179179
docker:
180-
- image: golangci/golangci-lint:v1.51.0-alpine
180+
- image: golangci/golangci-lint:v1.63.4-alpine
181181
resource_class: large
182182
steps:
183183
- checkout

.golangci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
service:
3-
golangci-lint-version: 1.46.x
3+
golangci-lint-version: 1.63.x
44

55
linters:
66
enable:
7-
- deadcode
87
- errcheck
98
- goconst
109
- gofmt
@@ -18,12 +17,10 @@ linters:
1817
- nakedret
1918
# - revive
2019
- staticcheck
21-
- structcheck
2220
- typecheck
2321
- unconvert
2422
# - unparam
2523
- unused
26-
- varcheck
2724
- vet
2825
- vetshadow
2926

api/api.go

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,6 @@ type GQLResponseError struct {
6363
Type string
6464
}
6565

66-
// IntrospectionResponse matches the result from making an introspection query
67-
type IntrospectionResponse struct {
68-
Schema struct {
69-
MutationType struct {
70-
Name string
71-
}
72-
QueryType struct {
73-
Name string
74-
}
75-
Types []struct {
76-
Description string
77-
Fields []struct {
78-
Name string
79-
}
80-
Kind string
81-
Name string
82-
}
83-
} `json:"__schema"`
84-
}
85-
8666
// ConfigResponse is a structure that matches the result of the GQL
8767
// query, so that we can use mapstructure to convert from
8868
// nested maps to a strongly typed struct.
@@ -1457,7 +1437,7 @@ query ListOrbs ($after: String!, $certifiedOnly: Boolean!) {
14571437
err := yaml.Unmarshal([]byte(edge.Node.Versions[0].Source), &edge.Node)
14581438

14591439
if err != nil {
1460-
l.Printf(errors.Wrapf(err, "Corrupt Orb %s %s", edge.Node.Name, v.Version).Error())
1440+
l.Printf("%s", errors.Wrap(err, fmt.Sprintf("Corrupt Orb %s %s", edge.Node.Name, v.Version)).Error())
14611441
continue Orbs
14621442
}
14631443

@@ -1626,7 +1606,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType
16261606

16271607
err := yaml.Unmarshal([]byte(edge.Node.Versions[0].Source), &edge.Node)
16281608
if err != nil {
1629-
l.Printf(errors.Wrapf(err, "Corrupt Orb %s %s", edge.Node.Name, v.Version).Error())
1609+
l.Printf("%s", errors.Wrap(err, fmt.Sprintf("Corrupt Orb %s %s", edge.Node.Name, v.Version)).Error())
16301610
continue NamespaceOrbs
16311611
}
16321612
} else {
@@ -1644,38 +1624,6 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType
16441624
return &orbs, nil
16451625
}
16461626

1647-
// IntrospectionQuery makes a query on the API asking for bits of the schema
1648-
// This query isn't intended to get the entire schema, there are better tools for that.
1649-
func IntrospectionQuery(cl *graphql.Client) (*IntrospectionResponse, error) {
1650-
var response IntrospectionResponse
1651-
1652-
query := `query IntrospectionQuery {
1653-
__schema {
1654-
queryType { name }
1655-
mutationType { name }
1656-
types {
1657-
...FullType
1658-
}
1659-
}
1660-
}
1661-
1662-
fragment FullType on __Type {
1663-
kind
1664-
name
1665-
description
1666-
fields(includeDeprecated: true) {
1667-
name
1668-
}
1669-
}`
1670-
1671-
request := graphql.NewRequest(query)
1672-
request.SetToken(cl.Token)
1673-
1674-
err := cl.Run(request, &response)
1675-
1676-
return &response, err
1677-
}
1678-
16791627
// OrbCategoryID fetches an orb returning the ID
16801628
func OrbCategoryID(cl *graphql.Client, name string) (*OrbCategoryIDResponse, error) {
16811629
var response OrbCategoryIDResponse

api/graphql/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (cl *Client) Run(request *Request, resp interface{}) error {
237237
defer func() {
238238
responseBodyCloseErr := res.Body.Close()
239239
if responseBodyCloseErr != nil {
240-
l.Printf(responseBodyCloseErr.Error())
240+
l.Printf("%s", responseBodyCloseErr.Error())
241241
}
242242
}()
243243

api/graphql/client_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestDoJSON(t *testing.T) {
5454

5555
b, err := io.ReadAll(r.Body)
5656
if err != nil {
57-
t.Errorf(err.Error())
57+
t.Errorf("%s", err.Error())
5858
}
5959

6060
if string(b) != `{"query":"query {}","variables":null}`+"\n" {
@@ -67,7 +67,7 @@ func TestDoJSON(t *testing.T) {
6767
}
6868
}`)
6969
if err != nil {
70-
t.Errorf(err.Error())
70+
t.Errorf("%s", err.Error())
7171
}
7272
}))
7373
defer srv.Close()
@@ -79,7 +79,7 @@ func TestDoJSON(t *testing.T) {
7979
}
8080
err := client.Run(&Request{Query: "query {}"}, &resp)
8181
if err != nil {
82-
t.Errorf(err.Error())
82+
t.Errorf("%s", err.Error())
8383
}
8484

8585
if calls != 1 {
@@ -97,14 +97,14 @@ func TestQueryJSON(t *testing.T) {
9797
calls++
9898
b, err := io.ReadAll(r.Body)
9999
if err != nil {
100-
t.Errorf(err.Error())
100+
t.Errorf("%s", err.Error())
101101
}
102102
if string(b) != `{"query":"query {}","variables":{"username":"matryer"}}`+"\n" {
103103
t.Errorf("expected %s", b)
104104
}
105105
_, err = io.WriteString(w, `{"data":{"value":"some data"}}`)
106106
if err != nil {
107-
t.Errorf(err.Error())
107+
t.Errorf("%s", err.Error())
108108
}
109109
}))
110110
defer srv.Close()
@@ -128,7 +128,7 @@ func TestQueryJSON(t *testing.T) {
128128
}
129129
err := client.Run(req, &resp)
130130
if err != nil {
131-
t.Errorf(err.Error())
131+
t.Errorf("%s", err.Error())
132132
}
133133

134134
if calls != 1 {
@@ -147,7 +147,7 @@ func TestDoJSONErr(t *testing.T) {
147147

148148
body, err := io.ReadAll(req.Body)
149149
if err != nil {
150-
t.Errorf(err.Error())
150+
t.Errorf("%s", err.Error())
151151
}
152152

153153
if string(body) != `{"query":"query {}","variables":null}`+"\n" {
@@ -166,7 +166,7 @@ func TestDoJSONErr(t *testing.T) {
166166
]
167167
}`)
168168
if err != nil {
169-
t.Errorf(err.Error())
169+
t.Errorf("%s", err.Error())
170170
}
171171
}))
172172

@@ -178,7 +178,7 @@ func TestDoJSONErr(t *testing.T) {
178178

179179
err := client.Run(&Request{Query: "query {}"}, &responseData)
180180
if err.Error() != "Something went wrong\nSomething else went wrong" {
181-
t.Errorf(err.Error())
181+
t.Errorf("%s", err.Error())
182182
}
183183
}
184184

@@ -192,7 +192,7 @@ func TestHeader(t *testing.T) {
192192

193193
_, err := io.WriteString(w, `{"data":{"value":"some data"}}`)
194194
if err != nil {
195-
t.Errorf(err.Error())
195+
t.Errorf("%s", err.Error())
196196
}
197197
}))
198198
defer srv.Close()
@@ -207,7 +207,7 @@ func TestHeader(t *testing.T) {
207207
}
208208
err := client.Run(req, &resp)
209209
if err != nil {
210-
t.Errorf(err.Error())
210+
t.Errorf("%s", err.Error())
211211
}
212212

213213
if calls != 1 {
@@ -228,7 +228,7 @@ func TestStatusCode200(t *testing.T) {
228228

229229
_, err := io.WriteString(w, `{"data":{"value":"some data"}}`)
230230
if err != nil {
231-
t.Errorf(err.Error())
231+
t.Errorf("%s", err.Error())
232232
}
233233
}))
234234
defer srv.Close()
@@ -241,7 +241,7 @@ func TestStatusCode200(t *testing.T) {
241241

242242
err := client.Run(req, &resp)
243243
if err != nil {
244-
t.Errorf(err.Error())
244+
t.Errorf("%s", err.Error())
245245
}
246246

247247
if calls != 1 {
@@ -258,7 +258,7 @@ func TestStatusCode500(t *testing.T) {
258258

259259
_, err := io.WriteString(w, "some: data")
260260
if err != nil {
261-
t.Errorf(err.Error())
261+
t.Errorf("%s", err.Error())
262262
}
263263
}))
264264
defer srv.Close()
@@ -292,7 +292,7 @@ func TestStatusCode413(t *testing.T) {
292292

293293
_, err := io.WriteString(w, "some: data")
294294
if err != nil {
295-
t.Errorf(err.Error())
295+
t.Errorf("%s", err.Error())
296296
}
297297
}))
298298
defer srv.Close()

cmd/diagnostic.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"os"
65

76
"github.com/CircleCI-Public/circleci-cli/api"
87
"github.com/CircleCI-Public/circleci-cli/api/graphql"
@@ -57,25 +56,6 @@ func diagnostic(opts diagnosticOptions) error {
5756

5857
fmt.Println("OK, got a token.")
5958

60-
fmt.Println("Trying an introspection query on API... ")
61-
62-
responseIntro, err := api.IntrospectionQuery(opts.cl)
63-
if responseIntro.Schema.QueryType.Name == "" {
64-
fmt.Println("Unable to make a query against the GraphQL API, please check your settings")
65-
if err != nil {
66-
return err
67-
}
68-
}
69-
70-
fmt.Println("Ok.")
71-
72-
if opts.cfg.Debug {
73-
_, err = fmt.Fprintf(os.Stderr, "Introspection query result with Schema.QueryType of %s", responseIntro.Schema.QueryType.Name)
74-
if err != nil {
75-
return err
76-
}
77-
}
78-
7959
responseWho, err := api.WhoamiQuery(opts.cl)
8060

8161
if err != nil {

0 commit comments

Comments
 (0)