Created
April 18, 2021 10:07
-
-
Save tvvignesh/19e540d0211c1a3b88f08c0f59aed54b to your computer and use it in GitHub Desktop.
header-patch-file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/packages/ci/src/index.ts b/packages/ci/src/index.ts | |
index 188aeae..cf69827 100644 | |
--- a/packages/ci/src/index.ts | |
+++ b/packages/ci/src/index.ts | |
@@ -1,8 +1,8 @@ | |
-import {useConfig, availableCommands} from '@graphql-inspector/config'; | |
-import {useCommands} from '@graphql-inspector/commands'; | |
-import {useLoaders} from '@graphql-inspector/loaders'; | |
-import yargs, {Argv} from 'yargs'; | |
-import {Logger} from '@graphql-inspector/logger'; | |
+import { useCommands } from '@graphql-inspector/commands'; | |
+import { availableCommands, useConfig } from '@graphql-inspector/config'; | |
+import { useLoaders } from '@graphql-inspector/loaders'; | |
+import { Logger } from '@graphql-inspector/logger'; | |
+import yargs, { Argv } from 'yargs'; | |
async function main() { | |
const config = await useConfig(); | |
@@ -30,6 +30,16 @@ async function main() { | |
describe: 'Http Header', | |
type: 'array', | |
}, | |
+ hl: { | |
+ alias: 'leftheader', | |
+ describe: 'Http Header - Left', | |
+ type: 'array', | |
+ }, | |
+ hr: { | |
+ alias: 'rightheader', | |
+ describe: 'Http Header - Right', | |
+ type: 'array', | |
+ }, | |
}); | |
commands | |
diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts | |
index 5958159..2c43d85 100644 | |
--- a/packages/cli/src/index.ts | |
+++ b/packages/cli/src/index.ts | |
@@ -1,6 +1,6 @@ | |
-import {useCommands} from '@graphql-inspector/commands'; | |
-import {useLoaders} from '@graphql-inspector/loaders'; | |
-import yargs, {Argv} from 'yargs'; | |
+import { useCommands } from '@graphql-inspector/commands'; | |
+import { useLoaders } from '@graphql-inspector/loaders'; | |
+import yargs, { Argv } from 'yargs'; | |
async function main() { | |
const config = { | |
@@ -39,6 +39,16 @@ async function main() { | |
describe: 'Http Header', | |
type: 'array', | |
}, | |
+ hl: { | |
+ alias: 'leftheader', | |
+ describe: 'Http Header - Left', | |
+ type: 'array', | |
+ }, | |
+ hr: { | |
+ alias: 'rightheader', | |
+ describe: 'Http Header - Right', | |
+ type: 'array', | |
+ }, | |
}); | |
commands | |
diff --git a/packages/commands/commands/src/index.ts b/packages/commands/commands/src/index.ts | |
index 3d74059..b4ea266 100644 | |
--- a/packages/commands/commands/src/index.ts | |
+++ b/packages/commands/commands/src/index.ts | |
@@ -1,10 +1,9 @@ | |
-import {InspectorConfig} from '@graphql-inspector/config'; | |
-import {Loaders} from '@graphql-inspector/loaders'; | |
-import {isAbsolute, resolve} from 'path'; | |
-import {CommandModule as Command} from 'yargs'; | |
-import yargs from 'yargs'; | |
+import { InspectorConfig } from '@graphql-inspector/config'; | |
+import { Loaders } from '@graphql-inspector/loaders'; | |
+import { isAbsolute, resolve } from 'path'; | |
+import yargs, { CommandModule as Command } from 'yargs'; | |
-export {Command}; | |
+export { Command }; | |
export interface UseCommandsAPI { | |
config: InspectorConfig; | |
@@ -40,6 +39,8 @@ export interface GlobalArgs { | |
require?: string[]; | |
token?: string; | |
header?: string[]; | |
+ leftheader?: string[]; | |
+ rightheader?: string[]; | |
federation?: boolean; | |
aws?: boolean; | |
method?: string; | |
@@ -47,6 +48,8 @@ export interface GlobalArgs { | |
export function parseGlobalArgs(args: GlobalArgs) { | |
const headers: Record<string, string> = {}; | |
+ const leftHeaders: Record<string, string> = {}; | |
+ const rightHeaders: Record<string, string> = {}; | |
if (args.header) { | |
args.header.forEach((header) => { | |
@@ -56,11 +59,27 @@ export function parseGlobalArgs(args: GlobalArgs) { | |
}); | |
} | |
+ if (args.leftheader) { | |
+ args.leftheader.forEach((leftHeader) => { | |
+ const [lname, ...lvalues] = leftHeader.split(':'); | |
+ | |
+ leftHeaders[lname] = lvalues.join(''); | |
+ }); | |
+ } | |
+ | |
+ if (args.rightheader) { | |
+ args.rightheader.forEach((rightHeader) => { | |
+ const [rname, ...rvalues] = rightHeader.split(':'); | |
+ | |
+ rightHeaders[rname] = rvalues.join(''); | |
+ }); | |
+ } | |
+ | |
if (args.require) { | |
args.require.forEach((mod) => require(mod)); | |
} | |
- return {headers, token: args.token}; | |
+ return {headers, leftHeaders, rightHeaders, token: args.token}; | |
} | |
export async function mockCommand(mod: Command, cmd: string) { | |
diff --git a/packages/commands/diff/src/index.ts b/packages/commands/diff/src/index.ts | |
index 83d4dab..32c786d 100644 | |
--- a/packages/commands/diff/src/index.ts | |
+++ b/packages/commands/diff/src/index.ts | |
@@ -1,24 +1,25 @@ | |
import { | |
- createCommand, | |
+ CommandFactory, createCommand, | |
ensureAbsolute, | |
- parseGlobalArgs, | |
- GlobalArgs, | |
- CommandFactory, | |
+ | |
+ GlobalArgs, parseGlobalArgs | |
} from '@graphql-inspector/commands'; | |
-import {symbols, Logger, bolderize} from '@graphql-inspector/logger'; | |
import { | |
- diff as diffSchema, | |
- CriticalityLevel, | |
Change, | |
+ | |
+ | |
+ | |
+ CompletionArgs, CompletionHandler, CriticalityLevel, diff as diffSchema, | |
+ | |
+ | |
DiffRule, | |
- Rule, | |
- CompletionHandler, | |
- CompletionArgs, | |
+ Rule | |
} from '@graphql-inspector/core'; | |
-import {existsSync} from 'fs'; | |
-import {GraphQLSchema} from 'graphql'; | |
+import { bolderize, Logger, symbols } from '@graphql-inspector/logger'; | |
+import { existsSync } from 'fs'; | |
+import { GraphQLSchema } from 'graphql'; | |
-export {CommandFactory}; | |
+export { CommandFactory }; | |
export function handler(input: { | |
oldSchema: GraphQLSchema; | |
@@ -127,12 +128,15 @@ export default createCommand< | |
const apolloFederation = args.federation || false; | |
const aws = args.aws || false; | |
const method = args.method?.toUpperCase() || 'POST'; | |
- const {headers, token} = parseGlobalArgs(args); | |
+ const {headers, leftHeaders, rightHeaders, token} = parseGlobalArgs(args); | |
+ | |
+ const oldSchemaHeaders = leftHeaders || headers; | |
+ const newSchemaHeaders = rightHeaders || headers; | |
const oldSchema = await loaders.loadSchema( | |
oldSchemaPointer, | |
{ | |
- headers, | |
+ oldSchemaHeaders, | |
token, | |
method, | |
}, | |
@@ -142,7 +146,7 @@ export default createCommand< | |
const newSchema = await loaders.loadSchema( | |
newSchemaPointer, | |
{ | |
- headers, | |
+ newSchemaHeaders, | |
token, | |
method, | |
}, | |
diff --git a/tsconfig.json b/tsconfig.json | |
index f0b6da1..24f2ceb 100644 | |
--- a/tsconfig.json | |
+++ b/tsconfig.json | |
@@ -80,5 +80,5 @@ | |
} | |
}, | |
"include": ["packages"], | |
- "exclude": ["**/dist", "**/node_modules/**", "**/__tests__", "**/tests"] | |
+ "exclude": ["**/dist", "**/node_modules/**", "**/__tests__/**", "**/tests/**"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment