Skip to content

Commit c699e6a

Browse files
authored
Export getIntrospectionQuery() wrapper that uses the options we want to use (#82)
## Summary: graphql-flow uses these options when we pass it composed_schema.graphql, but we weren't using these options in Khan/frontend when downloading the introspection JSON from production. This PR exports a wrapper around `getIntrospectionQuery` that uses the options we want to use. Once this PR lands, Khan/frontend should be updated to use this wrapper instead of the original function from `"graphql"`. Issue: FEI-7058 ## Test plan: - let CI run checks Author: kevinb-khan Reviewers: somewhatabstract, kevinb-khan, jeremywiebe, jaredly Required Reviewers: Approved By: jeremywiebe Checks: ✅ 3 checks were successful Pull Request URL: #82
1 parent 339ebfa commit c699e6a

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

.changeset/hip-dodos-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/graphql-flow": minor
3+
---
4+
5+
Export the introspection options we use

.github/workflows/pr-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Run TypeScript
3636
if: steps.ts-files.outputs.filtered != '[]'
37-
run: yarn tsc
37+
run: yarn typecheck
3838

3939
- id: eslint-reset
4040
uses: Khan/actions@filter-files-v1

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"scripts": {
1313
"test": "jest",
14+
"typecheck": "tsc --noEmit",
1415
"publish:ci": "yarn run build && changeset publish",
1516
"build": "babel src --extensions '.ts, .tsx' --out-dir dist --ignore 'src/**/*.spec.ts','src/**/*.test.ts' && chmod 755 dist/cli/run.js"
1617
},

src/cli/config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ import fs from "fs";
88
import {
99
buildClientSchema,
1010
buildSchema,
11-
getIntrospectionQuery,
1211
graphqlSync,
13-
IntrospectionQuery,
12+
type IntrospectionQuery,
1413
} from "graphql";
1514
import {validate} from "jsonschema";
1615
import processArgs from "minimist";
1716
import type {Config, GenerateConfig} from "../types";
1817
import {execSync} from "child_process";
1918
import path from "path";
2019

20+
import {getIntrospectionQuery} from "./get-introspection-query";
21+
2122
export const validateOrThrow = (value: unknown, jsonSchema: unknown) => {
2223
const result = validate(value, jsonSchema);
2324
if (!result.valid) {
@@ -91,10 +92,7 @@ export const getSchemas = (schemaFilePath: string): [GraphQLSchema, Schema] => {
9192
const schemaForValidation = buildSchema(raw);
9293
const queryResponse = graphqlSync({
9394
schema: schemaForValidation,
94-
source: getIntrospectionQuery({
95-
descriptions: true,
96-
inputValueDeprecation: true,
97-
}),
95+
source: getIntrospectionQuery(),
9896
});
9997
const schemaForTypeGeneration = schemaFromIntrospectionData(
10098
queryResponse.data as any as IntrospectionQuery,

src/cli/get-introspection-query.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {
2+
getIntrospectionQuery as getIntrospectionQueryWithOptions,
3+
type IntrospectionOptions,
4+
} from "graphql";
5+
6+
const INTROSPECTION_OPTIONS: IntrospectionOptions = {
7+
descriptions: true,
8+
inputValueDeprecation: true,
9+
};
10+
11+
export const getIntrospectionQuery = () => {
12+
return getIntrospectionQueryWithOptions(INTROSPECTION_OPTIONS);
13+
};

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import type {Node} from "@babel/types";
1919

2020
import type {Context, Schema, GenerateConfig} from "./types";
2121

22+
// NOTE(kevinb): This is exported so that tooling in other repos can use
23+
// the same options for their introspection query. In particular, we use
24+
// this in Khan/frontend when downloading the introspection JSON from prod.
25+
export {getIntrospectionQuery} from "./cli/get-introspection-query";
26+
2227
const optionsToConfig = (
2328
schema: Schema,
2429
definitions: ReadonlyArray<DefinitionNode>,

0 commit comments

Comments
 (0)