@@ -3,10 +3,7 @@ import { Command, flags } from "@oclif/command";
33import { table , styledJSON } from "heroku-cli-util" ;
44import * as Listr from "listr" ;
55import { toPromise , execute } from "apollo-link" ;
6- import {
7- print ,
8- GraphQLError
9- } from "graphql" ;
6+ import { print , GraphQLError } from "graphql" ;
107
118import * as fg from "glob" ;
129import { withGlobalFS } from "apollo-codegen-core/lib/localfs" ;
@@ -19,6 +16,11 @@ import { gitInfo } from "../../git";
1916import { VALIDATE_OPERATIONS } from "../../operations/validateOperations" ;
2017import { ChangeType } from "../../printer/ast" ;
2118import { format } from "../schema/check" ;
19+ import {
20+ ApolloConfig ,
21+ loadConfigFromFile ,
22+ findAndLoadConfig
23+ } from "../../config" ;
2224
2325export default class CheckQueries extends Command {
2426 static description =
@@ -29,6 +31,9 @@ export default class CheckQueries extends Command {
2931 char : "h" ,
3032 description : "Show command help"
3133 } ) ,
34+ config : flags . string ( {
35+ description : "Path to your Apollo config file"
36+ } ) ,
3237 queries : flags . string ( {
3338 description :
3439 "Path to your GraphQL queries, can include search tokens like **" ,
@@ -49,19 +54,37 @@ export default class CheckQueries extends Command {
4954 async run ( ) {
5055 const { flags } = this . parse ( CheckQueries ) ;
5156
52- const apiKey = flags . key ;
53- if ( ! apiKey ) {
54- this . error (
55- "No API key was specified. Set an Apollo Engine API key using the `--key` flag or the `ENGINE_API_KEY` environment variable."
56- ) ;
57- return ;
58- }
5957 const tasks : Listr = new Listr ( [
58+ {
59+ title : "Loading Apollo config" ,
60+ task : async ctx => {
61+ if ( flags . config ) {
62+ ctx . config = loadConfigFromFile ( flags . config ) || { } ;
63+ } else {
64+ ctx . config = findAndLoadConfig ( __dirname ) || { } ;
65+ }
66+
67+ ctx . config = {
68+ ...ctx . config ,
69+ operations : flags . queries
70+ ? flags . queries . split ( "\n" )
71+ : ctx . config . operations ,
72+ engineKey : flags . key || ctx . config . engineKey
73+ } ;
74+
75+ if ( ! ctx . config . engineKey ) {
76+ this . error (
77+ "No API key was specified. Set an Apollo Engine API key using the `--key` flag or the `ENGINE_API_KEY` environment variable."
78+ ) ;
79+ return ;
80+ }
81+ }
82+ } ,
6083 {
6184 title : "Scanning for GraphQL queries" ,
6285 task : async ( ctx , task ) => {
6386 const paths = withGlobalFS ( ( ) => {
64- return ( flags . queries ? flags . queries . split ( "\n" ) : [ ] ) . flatMap ( p =>
87+ return ( ctx . config as ApolloConfig ) . operations . flatMap ( p =>
6588 fg . sync ( p )
6689 ) ;
6790 } ) ;
@@ -76,11 +99,11 @@ export default class CheckQueries extends Command {
7699 } ,
77100 {
78101 title : "Checking query compatibility with schema" ,
79- task : async ( ctx ) => {
102+ task : async ctx => {
80103 const gitContext = await gitInfo ( ) ;
81104
82105 const variables = {
83- id : getIdFromKey ( apiKey ) ,
106+ id : getIdFromKey ( ctx . config . engineKey ) ,
84107 // XXX hardcoded for now
85108 tag : "current" ,
86109 gitContext,
@@ -92,7 +115,7 @@ export default class CheckQueries extends Command {
92115 query : VALIDATE_OPERATIONS ,
93116 variables,
94117 context : {
95- headers : { [ "x-api-key" ] : apiKey } ,
118+ headers : { [ "x-api-key" ] : ctx . config . engineKey } ,
96119 ...( flags . engine && { uri : flags . engine } )
97120 }
98121 } )
0 commit comments