Skip to content

Commit

Permalink
CIRCLE-11151: CLI can accept a GQL query from stdin and call api-service
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Jun 5, 2018
1 parent f29be32 commit 31b93b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
30 changes: 5 additions & 25 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"encoding/json"
"io/ioutil"
"os"

"github.com/circleci/circleci-cli/client"
"github.com/spf13/cobra"
Expand All @@ -17,32 +19,10 @@ var queryCmd = &cobra.Command{
func query(cmd *cobra.Command, args []string) {
client := client.NewClient(viper.GetString("host"), viper.GetString("token"), Logger)

query := `
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
}
}
}
query, err := ioutil.ReadAll(os.Stdin)
Logger.FatalOnError("Something happened", err)

fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
}
}`

resp, err := client.Run(query)
resp, err := client.Run(string(query))
Logger.FatalOnError("Something happend", err)
b, err := json.MarshalIndent(resp, "", " ")
Logger.FatalOnError("Could not parse graphql response", err)
Expand Down
23 changes: 23 additions & 0 deletions testquery.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
}
}
}

fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
}
}

0 comments on commit 31b93b4

Please sign in to comment.