@khanacademy/graphql-flow 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.github/workflows/pr-checks.yml +4 -6
  2. package/CHANGELOG.md +22 -0
  3. package/Readme.md +41 -167
  4. package/dist/__test__/example-schema.graphql +67 -0
  5. package/dist/__test__/generateTypeFileContents.test.js +157 -0
  6. package/dist/__test__/graphql-flow.test.js +639 -0
  7. package/dist/__test__/processPragmas.test.js +76 -0
  8. package/dist/cli/__test__/config.test.js +120 -0
  9. package/dist/cli/config.js +45 -106
  10. package/dist/cli/config.js.flow +37 -159
  11. package/dist/cli/config.js.map +1 -1
  12. package/dist/cli/run.js +40 -36
  13. package/dist/cli/run.js.flow +56 -42
  14. package/dist/cli/run.js.map +1 -1
  15. package/dist/cli/schema.json +91 -0
  16. package/dist/enums.js +9 -9
  17. package/dist/enums.js.flow +11 -11
  18. package/dist/enums.js.map +1 -1
  19. package/dist/generateResponseType.js +47 -47
  20. package/dist/generateResponseType.js.flow +55 -57
  21. package/dist/generateResponseType.js.map +1 -1
  22. package/dist/generateTypeFiles.js +13 -17
  23. package/dist/generateTypeFiles.js.flow +21 -43
  24. package/dist/generateTypeFiles.js.map +1 -1
  25. package/dist/generateVariablesType.js +24 -24
  26. package/dist/generateVariablesType.js.flow +25 -28
  27. package/dist/generateVariablesType.js.map +1 -1
  28. package/dist/index.js +0 -8
  29. package/dist/index.js.flow +4 -5
  30. package/dist/index.js.map +1 -1
  31. package/dist/parser/__test__/parse.test.js +247 -0
  32. package/dist/types.js.flow +26 -6
  33. package/package.json +3 -2
  34. package/src/__test__/generateTypeFileContents.test.js +3 -1
  35. package/src/__test__/graphql-flow.test.js +7 -7
  36. package/src/__test__/processPragmas.test.js +28 -15
  37. package/src/cli/__test__/config.test.js +110 -84
  38. package/src/cli/config.js +37 -159
  39. package/src/cli/run.js +56 -42
  40. package/src/cli/schema.json +91 -0
  41. package/src/enums.js +11 -11
  42. package/src/generateResponseType.js +55 -57
  43. package/src/generateTypeFiles.js +21 -43
  44. package/src/generateVariablesType.js +25 -28
  45. package/src/index.js +4 -5
  46. package/src/types.js +26 -6
  47. package/dist/cli/utils.js +0 -21
  48. package/dist/cli/utils.js.flow +0 -14
  49. package/dist/cli/utils.js.map +0 -1
  50. package/dist/jest-mock-graphql-tag.js +0 -88
  51. package/dist/jest-mock-graphql-tag.js.flow +0 -96
  52. package/dist/jest-mock-graphql-tag.js.map +0 -1
  53. package/src/cli/__test__/utils.test.js +0 -19
  54. package/src/cli/utils.js +0 -14
  55. package/src/jest-mock-graphql-tag.js +0 -96
@@ -0,0 +1,120 @@
1
+ // @flow
2
+ import type {Config} from '../../types';
3
+
4
+ import {findApplicableConfig, validateOrThrow} from '../config';
5
+ import configSchema from '../schema.json'; // eslint-disable-line flowtype-errors/uncovered
6
+
7
+ describe('findApplicableConfig', () => {
8
+ it('should work with one that matches', () => {
9
+ const config = {
10
+ schemaFilePath: 'ok.graphql',
11
+ };
12
+ expect(findApplicableConfig('/hello', config)).toBe(config);
13
+ });
14
+
15
+ it('should be falsy if nothing matches', () => {
16
+ const config = {
17
+ schemaFilePath: 'ok.graphql',
18
+ exclude: [/hello$/],
19
+ };
20
+ expect(findApplicableConfig('/hello', config)).toBeUndefined();
21
+ });
22
+
23
+ it('should match & exclude with multiple configs', () => {
24
+ const configs = [
25
+ {schemaFilePath: 'one', match: [/\.jsx$/], exclude: [/^test/]},
26
+ {schemaFilePath: 'two', exclude: [/^hello/]},
27
+ {schemaFilePath: 'three'},
28
+ ];
29
+ expect(findApplicableConfig('hello.js', configs)).toBe(configs[2]);
30
+ expect(findApplicableConfig('goodbye.js', configs)).toBe(configs[1]);
31
+ expect(findApplicableConfig('hello.jsx', configs)).toBe(configs[0]);
32
+ expect(findApplicableConfig('test.jsx', configs)).toBe(configs[1]);
33
+ });
34
+ });
35
+
36
+ describe('jsonschema validation', () => {
37
+ it('should accept valid schema', () => {
38
+ const config: Config = {
39
+ crawl: {
40
+ root: '/here/we/crawl',
41
+ },
42
+ generate: {
43
+ match: [/\.fixture\.js$/],
44
+ exclude: [
45
+ '_test\\.js$',
46
+ '\\bcourse-editor-package\\b',
47
+ '\\.fixture\\.js$',
48
+ '\\b__flowtests__\\b',
49
+ '\\bcourse-editor\\b',
50
+ ],
51
+ readOnlyArray: false,
52
+ regenerateCommand: 'make gqlflow',
53
+ scalars: {
54
+ JSONString: 'string',
55
+ KALocale: 'string',
56
+ NaiveDateTime: 'string',
57
+ },
58
+ splitTypes: true,
59
+ generatedDirectory: '__graphql-types__',
60
+ exportAllObjectTypes: true,
61
+ schemaFilePath: './composed_schema.graphql',
62
+ },
63
+ };
64
+ validateOrThrow(
65
+ config,
66
+ configSchema, // eslint-disable-line flowtype-errors/uncovered
67
+ );
68
+ });
69
+
70
+ it('should accept a schema with multiple generate configs', () => {
71
+ const generate = {
72
+ match: [/\.fixture\.js$/],
73
+ exclude: [
74
+ '_test\\.js$',
75
+ '\\bcourse-editor-package\\b',
76
+ '\\.fixture\\.js$',
77
+ '\\b__flowtests__\\b',
78
+ '\\bcourse-editor\\b',
79
+ ],
80
+ readOnlyArray: false,
81
+ regenerateCommand: 'make gqlflow',
82
+ scalars: {
83
+ JSONString: 'string',
84
+ KALocale: 'string',
85
+ NaiveDateTime: 'string',
86
+ },
87
+ splitTypes: true,
88
+ generatedDirectory: '__graphql-types__',
89
+ exportAllObjectTypes: true,
90
+ schemaFilePath: './composed_schema.graphql',
91
+ };
92
+ const config: Config = {
93
+ crawl: {
94
+ root: '/here/we/crawl',
95
+ },
96
+ generate: [
97
+ {...generate, match: [/^static/], exportAllObjectTypes: false},
98
+ generate,
99
+ ],
100
+ };
101
+ validateOrThrow(
102
+ config,
103
+ configSchema, // eslint-disable-line flowtype-errors/uncovered
104
+ );
105
+ });
106
+
107
+ it('should reject invalid schema', () => {
108
+ expect(() =>
109
+ validateOrThrow(
110
+ {schemaFilePath: 10, options: {extraOption: 'hello'}},
111
+ configSchema, // eslint-disable-line flowtype-errors/uncovered
112
+ ),
113
+ ).toThrowErrorMatchingInlineSnapshot(`
114
+ "instance is not allowed to have the additional property \\"schemaFilePath\\"
115
+ instance is not allowed to have the additional property \\"options\\"
116
+ instance requires property \\"crawl\\"
117
+ instance requires property \\"generate\\""
118
+ `);
119
+ });
120
+ });
@@ -3,127 +3,49 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.loadSubConfigFile = exports.loadDirConfigFiles = exports.loadConfigFile = exports.getSchemas = void 0;
6
+ exports.validateOrThrow = exports.loadConfigFile = exports.getSchemas = exports.findApplicableConfig = void 0;
7
7
 
8
8
  var _schemaFromIntrospectionData = require("../schemaFromIntrospectionData");
9
9
 
10
+ var _schema = _interopRequireDefault(require("./schema.json"));
11
+
10
12
  var _fs = _interopRequireDefault(require("fs"));
11
13
 
12
14
  var _graphql = require("graphql");
13
15
 
14
- var _path = _interopRequireDefault(require("path"));
16
+ var _jsonschema = require("jsonschema");
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
18
- const loadConfigFile = configFile => {
19
- var _data$options, _data$options2, _data$excludes$map, _data$excludes;
20
-
21
- // eslint-disable-next-line flowtype-errors/uncovered
22
- const data = JSON.parse(_fs.default.readFileSync(configFile, 'utf8'));
23
- const toplevelKeys = ['excludes', 'schemaFilePath', 'options', 'dumpOperations'];
24
- Object.keys(data).forEach(k => {
25
- if (!toplevelKeys.includes(k)) {
26
- throw new Error(`Invalid attribute in config file ${configFile}: ${k}. Allowed attributes: ${toplevelKeys.join(', ')}`);
27
- }
28
- });
29
- validateOptions(configFile, (_data$options = data.options) !== null && _data$options !== void 0 ? _data$options : {});
30
- return {
31
- options: (_data$options2 = data.options) !== null && _data$options2 !== void 0 ? _data$options2 : {},
32
- excludes: (_data$excludes$map = (_data$excludes = data.excludes) === null || _data$excludes === void 0 ? void 0 : _data$excludes.map(string => new RegExp(string))) !== null && _data$excludes$map !== void 0 ? _data$excludes$map : [],
33
- schemaFilePath: _path.default.isAbsolute(data.schemaFilePath) ? data.schemaFilePath : _path.default.join(_path.default.dirname(configFile), data.schemaFilePath),
34
- dumpOperations: data.dumpOperations
35
- };
36
- };
37
- /**
38
- * Subdirectory config to extend or overwrite higher-level config.
39
- * @param {string} extends - Path from root; optional field for a config file in a subdirectory. If left blank, config file will overwrite root for directory.
40
- */
41
-
42
-
43
- exports.loadConfigFile = loadConfigFile;
44
-
45
- const loadSubConfigFile = configFile => {
46
- var _data$options3, _data$excludes$map2, _data$excludes2, _data$options4, _data$extends;
47
-
48
- const jsonData = _fs.default.readFileSync(configFile, 'utf8'); // eslint-disable-next-line flowtype-errors/uncovered
20
+ // eslint-disable-line flowtype-errors/uncovered
21
+ // eslint-disable-line flowtype-errors/uncovered
22
+ const validateOrThrow = (value, jsonSchema) => {
23
+ /* eslint-disable flowtype-errors/uncovered */
24
+ const result = (0, _jsonschema.validate)(value, jsonSchema);
49
25
 
26
+ if (!result.valid) {
27
+ throw new Error(result.errors.map(error => error.toString()).join('\n'));
28
+ }
29
+ /* eslint-enable flowtype-errors/uncovered */
50
30
 
51
- const data = JSON.parse(jsonData);
52
- const toplevelKeys = ['excludes', 'options', 'extends'];
53
- Object.keys(data).forEach(k => {
54
- if (!toplevelKeys.includes(k)) {
55
- throw new Error(`Invalid attribute in non-root config file ${configFile}: ${k}. Allowed attributes: ${toplevelKeys.join(', ')}`);
56
- }
57
- });
58
- validateOptions(configFile, (_data$options3 = data.options) !== null && _data$options3 !== void 0 ? _data$options3 : {});
59
- return {
60
- excludes: (_data$excludes$map2 = (_data$excludes2 = data.excludes) === null || _data$excludes2 === void 0 ? void 0 : _data$excludes2.map(string => new RegExp(string))) !== null && _data$excludes$map2 !== void 0 ? _data$excludes$map2 : [],
61
- options: (_data$options4 = data.options) !== null && _data$options4 !== void 0 ? _data$options4 : {},
62
- extends: (_data$extends = data.extends) !== null && _data$extends !== void 0 ? _data$extends : ''
63
- };
64
31
  };
65
32
 
66
- exports.loadSubConfigFile = loadSubConfigFile;
67
-
68
- const loadDirConfigFiles = (filesResponse, rootConfig) => {
69
- const dirConfigMap = {}; // TODO: circular extends will cause infinite loop... consider instrumenting code to monitor for loops in the future?
70
-
71
- const loadExtendedConfig = configPath => {
72
- let dirConfig = loadSubConfigFile(configPath);
73
-
74
- if (dirConfig.extends) {
75
- const isRootConfig = dirConfig.extends === rootConfig.path;
76
- const {
77
- options,
78
- excludes
79
- } = isRootConfig ? rootConfig.config : addConfig(dirConfig.extends);
80
- dirConfig = extendConfig({
81
- options,
82
- excludes
83
- }, dirConfig);
84
- }
85
-
86
- return dirConfig;
87
- };
33
+ exports.validateOrThrow = validateOrThrow;
88
34
 
89
- const addConfig = configPath => {
90
- const {
91
- dir
92
- } = _path.default.parse(configPath);
93
-
94
- if (dirConfigMap[dir]) {
95
- return dirConfigMap[dir];
96
- }
97
-
98
- dirConfigMap[dir] = loadExtendedConfig(configPath);
99
- return dirConfigMap[dir];
100
- };
101
-
102
- const extendConfig = (toExtend, current) => ({
103
- // $FlowFixMe[exponential-spread]
104
- options: { ...toExtend.options,
105
- ...current.options
106
- },
107
- excludes: Array.from(new Set([...toExtend.excludes, ...current.excludes]))
108
- });
35
+ const loadConfigFile = configFile => {
36
+ // $FlowIgnore // eslint-disable-next-line flowtype-errors/uncovered
37
+ const data = require(configFile); // eslint-disable-next-line flowtype-errors/uncovered
109
38
 
110
- filesResponse.trim().split('\n').forEach(configPath => {
111
- const {
112
- dir
113
- } = _path.default.parse(configPath);
114
39
 
115
- if (dir && !dirConfigMap[dir]) {
116
- dirConfigMap[dir] = loadExtendedConfig(configPath);
117
- }
118
- });
119
- return dirConfigMap;
40
+ validateOrThrow(data, _schema.default);
41
+ return data;
120
42
  };
121
43
  /**
122
44
  * Loads a .json 'introspection query response', or a .graphql schema definition.
123
45
  */
124
46
 
125
47
 
126
- exports.loadDirConfigFiles = loadDirConfigFiles;
48
+ exports.loadConfigFile = loadConfigFile;
127
49
 
128
50
  const getSchemas = schemaFilePath => {
129
51
  const raw = _fs.default.readFileSync(schemaFilePath, 'utf8');
@@ -144,17 +66,34 @@ const getSchemas = schemaFilePath => {
144
66
  return [schemaForValidation, schemaForTypeGeneration];
145
67
  }
146
68
  };
69
+ /**
70
+ * Find the first item of the `config.generate` array where both:
71
+ * - no item of `exclude` matches
72
+ * - at least one item of `match` matches
73
+ */
74
+
147
75
 
148
76
  exports.getSchemas = getSchemas;
149
77
 
150
- const validateOptions = (configFile, options) => {
151
- if (options) {
152
- const externalOptionsKeys = ['pragma', 'loosePragma', 'ignorePragma', 'scalars', 'strictNullability', 'regenerateCommand', 'readOnlyArray', 'splitTypes', 'generatedDirectory', 'exportAllObjectTypes', 'typeFileName', 'experimentalEnums'];
153
- Object.keys(options).forEach(k => {
154
- if (!externalOptionsKeys.includes(k)) {
155
- throw new Error(`Invalid option in config file ${configFile}: ${k}. Allowed options: ${externalOptionsKeys.join(', ')}`);
156
- }
157
- });
78
+ const findApplicableConfig = (path, configs) => {
79
+ if (!Array.isArray(configs)) {
80
+ configs = [configs];
158
81
  }
82
+
83
+ return configs.find(config => {
84
+ var _config$exclude;
85
+
86
+ if ((_config$exclude = config.exclude) !== null && _config$exclude !== void 0 && _config$exclude.some(exclude => new RegExp(exclude).test(path))) {
87
+ return false;
88
+ }
89
+
90
+ if (!config.match) {
91
+ return true;
92
+ }
93
+
94
+ return config.match.some(matcher => new RegExp(matcher).test(path));
95
+ });
159
96
  };
97
+
98
+ exports.findApplicableConfig = findApplicableConfig;
160
99
  //# sourceMappingURL=config.js.map
@@ -1,9 +1,9 @@
1
1
  // @flow
2
- import type {ExternalOptions} from '../generateTypeFiles';
3
2
  import type {Schema} from '../types';
4
3
  import type {GraphQLSchema} from 'graphql/type/schema';
5
4
 
6
5
  import {schemaFromIntrospectionData} from '../schemaFromIntrospectionData';
6
+ import configSchema from './schema.json'; // eslint-disable-line flowtype-errors/uncovered
7
7
 
8
8
  import fs from 'fs';
9
9
  import {
@@ -13,140 +13,26 @@ import {
13
13
  graphqlSync,
14
14
  type IntrospectionQuery,
15
15
  } from 'graphql';
16
- import path from 'path';
16
+ import type {Config, GenerateConfig} from '../types';
17
+ import {validate} from 'jsonschema'; // eslint-disable-line flowtype-errors/uncovered
17
18
 
18
- export type CliConfig = {
19
- excludes: Array<RegExp>,
20
- schemaFilePath: string,
21
- dumpOperations?: string,
22
- options: ExternalOptions,
23
- };
24
-
25
- /**
26
- * This is the json-compatible form of the config
27
- * object.
28
- */
29
- type JSONConfig = {
30
- excludes?: Array<string>,
31
- schemaFilePath: string,
32
- options?: ExternalOptions,
33
- dumpOperations?: string,
34
- };
35
-
36
- export const loadConfigFile = (configFile: string): CliConfig => {
37
- // eslint-disable-next-line flowtype-errors/uncovered
38
- const data: JSONConfig = JSON.parse(fs.readFileSync(configFile, 'utf8'));
39
- const toplevelKeys = [
40
- 'excludes',
41
- 'schemaFilePath',
42
- 'options',
43
- 'dumpOperations',
44
- ];
45
- Object.keys(data).forEach((k) => {
46
- if (!toplevelKeys.includes(k)) {
47
- throw new Error(
48
- `Invalid attribute in config file ${configFile}: ${k}. Allowed attributes: ${toplevelKeys.join(
49
- ', ',
50
- )}`,
51
- );
52
- }
53
- });
54
- validateOptions(configFile, data.options ?? {});
55
- return {
56
- options: data.options ?? {},
57
- excludes: data.excludes?.map((string) => new RegExp(string)) ?? [],
58
- schemaFilePath: path.isAbsolute(data.schemaFilePath)
59
- ? data.schemaFilePath
60
- : path.join(path.dirname(configFile), data.schemaFilePath),
61
- dumpOperations: data.dumpOperations,
62
- };
63
- };
64
-
65
- /**
66
- * Subdirectory config to extend or overwrite higher-level config.
67
- * @param {string} extends - Path from root; optional field for a config file in a subdirectory. If left blank, config file will overwrite root for directory.
68
- */
69
- type JSONSubConfig = {
70
- excludes?: Array<string>,
71
- options?: ExternalOptions,
72
- extends?: string,
73
- };
74
-
75
- type SubConfig = {
76
- excludes: Array<RegExp>,
77
- options: ExternalOptions,
78
- extends?: string,
19
+ export const validateOrThrow = (value: mixed, jsonSchema: mixed) => {
20
+ /* eslint-disable flowtype-errors/uncovered */
21
+ const result = validate(value, jsonSchema);
22
+ if (!result.valid) {
23
+ throw new Error(
24
+ result.errors.map((error) => error.toString()).join('\n'),
25
+ );
26
+ }
27
+ /* eslint-enable flowtype-errors/uncovered */
79
28
  };
80
29
 
81
- export const loadSubConfigFile = (configFile: string): SubConfig => {
82
- const jsonData = fs.readFileSync(configFile, 'utf8');
30
+ export const loadConfigFile = (configFile: string): Config => {
31
+ // $FlowIgnore // eslint-disable-next-line flowtype-errors/uncovered
32
+ const data: Config = require(configFile);
83
33
  // eslint-disable-next-line flowtype-errors/uncovered
84
- const data: JSONSubConfig = JSON.parse(jsonData);
85
- const toplevelKeys = ['excludes', 'options', 'extends'];
86
- Object.keys(data).forEach((k) => {
87
- if (!toplevelKeys.includes(k)) {
88
- throw new Error(
89
- `Invalid attribute in non-root config file ${configFile}: ${k}. Allowed attributes: ${toplevelKeys.join(
90
- ', ',
91
- )}`,
92
- );
93
- }
94
- });
95
- validateOptions(configFile, data.options ?? {});
96
- return {
97
- excludes: data.excludes?.map((string) => new RegExp(string)) ?? [],
98
- options: data.options ?? {},
99
- extends: data.extends ?? '',
100
- };
101
- };
102
-
103
- export const loadDirConfigFiles = (
104
- filesResponse: string,
105
- rootConfig: {path: string, config: CliConfig},
106
- ): {[dir: string]: SubConfig} => {
107
- const dirConfigMap: {[key: string]: SubConfig} = {};
108
-
109
- // TODO: circular extends will cause infinite loop... consider instrumenting code to monitor for loops in the future?
110
- const loadExtendedConfig = (configPath: string): SubConfig => {
111
- let dirConfig = loadSubConfigFile(configPath);
112
- if (dirConfig.extends) {
113
- const isRootConfig = dirConfig.extends === rootConfig.path;
114
- const {options, excludes} = isRootConfig
115
- ? rootConfig.config
116
- : addConfig(dirConfig.extends);
117
- dirConfig = extendConfig({options, excludes}, dirConfig);
118
- }
119
- return dirConfig;
120
- };
121
- const addConfig = (configPath) => {
122
- const {dir} = path.parse(configPath);
123
- if (dirConfigMap[dir]) {
124
- return dirConfigMap[dir];
125
- }
126
- dirConfigMap[dir] = loadExtendedConfig(configPath);
127
- return dirConfigMap[dir];
128
- };
129
- const extendConfig = (
130
- toExtend: SubConfig,
131
- current: SubConfig,
132
- ): SubConfig => ({
133
- // $FlowFixMe[exponential-spread]
134
- options: {...toExtend.options, ...current.options},
135
- excludes: Array.from(
136
- new Set([...toExtend.excludes, ...current.excludes]),
137
- ),
138
- });
139
-
140
- filesResponse
141
- .trim()
142
- .split('\n')
143
- .forEach((configPath) => {
144
- const {dir} = path.parse(configPath);
145
- if (dir && !dirConfigMap[dir]) {
146
- dirConfigMap[dir] = loadExtendedConfig(configPath);
147
- }
148
- });
149
- return dirConfigMap;
34
+ validateOrThrow(data, configSchema);
35
+ return data;
150
36
  };
151
37
 
152
38
  /**
@@ -175,33 +61,25 @@ export const getSchemas = (schemaFilePath: string): [GraphQLSchema, Schema] => {
175
61
  }
176
62
  };
177
63
 
178
- const validateOptions = (
179
- configFile: string,
180
- options: ExternalOptions,
181
- ): void => {
182
- if (options) {
183
- const externalOptionsKeys = [
184
- 'pragma',
185
- 'loosePragma',
186
- 'ignorePragma',
187
- 'scalars',
188
- 'strictNullability',
189
- 'regenerateCommand',
190
- 'readOnlyArray',
191
- 'splitTypes',
192
- 'generatedDirectory',
193
- 'exportAllObjectTypes',
194
- 'typeFileName',
195
- 'experimentalEnums',
196
- ];
197
- Object.keys(options).forEach((k) => {
198
- if (!externalOptionsKeys.includes(k)) {
199
- throw new Error(
200
- `Invalid option in config file ${configFile}: ${k}. Allowed options: ${externalOptionsKeys.join(
201
- ', ',
202
- )}`,
203
- );
204
- }
205
- });
64
+ /**
65
+ * Find the first item of the `config.generate` array where both:
66
+ * - no item of `exclude` matches
67
+ * - at least one item of `match` matches
68
+ */
69
+ export const findApplicableConfig = (
70
+ path: string,
71
+ configs: Array<GenerateConfig> | GenerateConfig,
72
+ ): ?GenerateConfig => {
73
+ if (!Array.isArray(configs)) {
74
+ configs = [configs];
206
75
  }
76
+ return configs.find((config) => {
77
+ if (config.exclude?.some((exclude) => new RegExp(exclude).test(path))) {
78
+ return false;
79
+ }
80
+ if (!config.match) {
81
+ return true;
82
+ }
83
+ return config.match.some((matcher) => new RegExp(matcher).test(path));
84
+ });
207
85
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/config.js"],"names":["loadConfigFile","configFile","data","JSON","parse","fs","readFileSync","toplevelKeys","Object","keys","forEach","k","includes","Error","join","validateOptions","options","excludes","map","string","RegExp","schemaFilePath","path","isAbsolute","dirname","dumpOperations","loadSubConfigFile","jsonData","extends","loadDirConfigFiles","filesResponse","rootConfig","dirConfigMap","loadExtendedConfig","configPath","dirConfig","isRootConfig","config","addConfig","extendConfig","dir","toExtend","current","Array","from","Set","trim","split","getSchemas","raw","endsWith","schemaForValidation","queryResponse","descriptions","schemaForTypeGeneration","introspectionData","externalOptionsKeys"],"mappings":";;;;;;;AAKA;;AAEA;;AACA;;AAOA;;;;AAoBO,MAAMA,cAAc,GAAIC,UAAD,IAAmC;AAAA;;AAC7D;AACA,QAAMC,IAAgB,GAAGC,IAAI,CAACC,KAAL,CAAWC,YAAGC,YAAH,CAAgBL,UAAhB,EAA4B,MAA5B,CAAX,CAAzB;AACA,QAAMM,YAAY,GAAG,CACjB,UADiB,EAEjB,gBAFiB,EAGjB,SAHiB,EAIjB,gBAJiB,CAArB;AAMAC,EAAAA,MAAM,CAACC,IAAP,CAAYP,IAAZ,EAAkBQ,OAAlB,CAA2BC,CAAD,IAAO;AAC7B,QAAI,CAACJ,YAAY,CAACK,QAAb,CAAsBD,CAAtB,CAAL,EAA+B;AAC3B,YAAM,IAAIE,KAAJ,CACD,oCAAmCZ,UAAW,KAAIU,CAAE,yBAAwBJ,YAAY,CAACO,IAAb,CACzE,IADyE,CAE3E,EAHA,CAAN;AAKH;AACJ,GARD;AASAC,EAAAA,eAAe,CAACd,UAAD,mBAAa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CAACC,KAAL,CAAW6C,GAAX,CAA9C;AACA,UAAME,mBAAmB,GAAG,gCAAkBI,iBAAlB,CAA5B;AACA,UAAMD,uBAAuB,GACzB,8DAA4BC,iBAA5B,CADJ;AAEA,WAAO,CAACJ,mBAAD,EAAsBG,uBAAtB,CAAP;AACH;AACJ,CArBM;;;;AAuBP,MAAMvC,eAAe,GAAG,CACpBd,UADoB,EAEpBe,OAFoB,KAGb;AACP,MAAIA,OAAJ,EAAa;AACT,UAAMwC,mBAAmB,GAAG,CACxB,QADwB,EAExB,aAFwB,EAGxB,cAHwB,EAIxB,SAJwB,EAKxB,mBALwB,EAMxB,mBANwB,EAOxB,eAPwB,EAQxB,YARwB,EASxB,oBATwB,EAUxB,sBAVwB,EAWxB,cAXwB,EAYxB,mBAZwB,CAA5B;AAcAhD,IAAAA,MAAM,CAACC,IAAP,CAAYO,OAAZ,EAAqBN,OAArB,CAA8BC,CAAD,IAAO;AAChC,UAAI,CAAC6C,mBAAmB,CAAC5C,QAApB,CAA6BD,CAA7B,CAAL,EAAsC;AAClC,cAAM,IAAIE,KAAJ,CACD,iCAAgCZ,UAAW,KAAIU,CAAE,sBAAqB6C,mBAAmB,CAAC1C,IAApB,CACnE,IADmE,CAErE,EAHA,CAAN;AAKH;AACJ,KARD;AASH;AACJ,CA7BD","sourcesContent":["// @flow\nimport type {ExternalOptions} from '../generateTypeFiles';\nimport type {Schema} from '../types';\nimport type {GraphQLSchema} from 'graphql/type/schema';\n\nimport {schemaFromIntrospectionData} from '../schemaFromIntrospectionData';\n\nimport fs from 'fs';\nimport {\n buildClientSchema,\n buildSchema,\n getIntrospectionQuery,\n graphqlSync,\n type IntrospectionQuery,\n} from 'graphql';\nimport path from 'path';\n\nexport type CliConfig = {\n excludes: Array<RegExp>,\n schemaFilePath: string,\n dumpOperations?: string,\n options: ExternalOptions,\n};\n\n/**\n * This is the json-compatible form of the config\n * object.\n */\ntype JSONConfig = {\n excludes?: Array<string>,\n schemaFilePath: string,\n options?: ExternalOptions,\n dumpOperations?: string,\n};\n\nexport const loadConfigFile = (configFile: string): CliConfig => {\n // eslint-disable-next-line flowtype-errors/uncovered\n const data: JSONConfig = JSON.parse(fs.readFileSync(configFile, 'utf8'));\n const toplevelKeys = [\n 'excludes',\n 'schemaFilePath',\n 'options',\n 'dumpOperations',\n ];\n Object.keys(data).forEach((k) => {\n if (!toplevelKeys.includes(k)) {\n throw new Error(\n `Invalid attribute in config file ${configFile}: ${k}. Allowed attributes: ${toplevelKeys.join(\n ', ',\n )}`,\n );\n }\n });\n validateOptions(configFile, data.options ?? {});\n return {\n options: data.options ?? {},\n excludes: data.excludes?.map((string) => new RegExp(string)) ?? [],\n schemaFilePath: path.isAbsolute(data.schemaFilePath)\n ? data.schemaFilePath\n : path.join(path.dirname(configFile), data.schemaFilePath),\n dumpOperations: data.dumpOperations,\n };\n};\n\n/**\n * Subdirectory config to extend or overwrite higher-level config.\n * @param {string} extends - Path from root; optional field for a config file in a subdirectory. If left blank, config file will overwrite root for directory.\n */\ntype JSONSubConfig = {\n excludes?: Array<string>,\n options?: ExternalOptions,\n extends?: string,\n};\n\ntype SubConfig = {\n excludes: Array<RegExp>,\n options: ExternalOptions,\n extends?: string,\n};\n\nexport const loadSubConfigFile = (configFile: string): SubConfig => {\n const jsonData = fs.readFileSync(configFile, 'utf8');\n // eslint-disable-next-line flowtype-errors/uncovered\n const data: JSONSubConfig = JSON.parse(jsonData);\n const toplevelKeys = ['excludes', 'options', 'extends'];\n Object.keys(data).forEach((k) => {\n if (!toplevelKeys.includes(k)) {\n throw new Error(\n `Invalid attribute in non-root config file ${configFile}: ${k}. Allowed attributes: ${toplevelKeys.join(\n ', ',\n )}`,\n );\n }\n });\n validateOptions(configFile, data.options ?? {});\n return {\n excludes: data.excludes?.map((string) => new RegExp(string)) ?? [],\n options: data.options ?? {},\n extends: data.extends ?? '',\n };\n};\n\nexport const loadDirConfigFiles = (\n filesResponse: string,\n rootConfig: {path: string, config: CliConfig},\n): {[dir: string]: SubConfig} => {\n const dirConfigMap: {[key: string]: SubConfig} = {};\n\n // TODO: circular extends will cause infinite loop... consider instrumenting code to monitor for loops in the future?\n const loadExtendedConfig = (configPath: string): SubConfig => {\n let dirConfig = loadSubConfigFile(configPath);\n if (dirConfig.extends) {\n const isRootConfig = dirConfig.extends === rootConfig.path;\n const {options, excludes} = isRootConfig\n ? rootConfig.config\n : addConfig(dirConfig.extends);\n dirConfig = extendConfig({options, excludes}, dirConfig);\n }\n return dirConfig;\n };\n const addConfig = (configPath) => {\n const {dir} = path.parse(configPath);\n if (dirConfigMap[dir]) {\n return dirConfigMap[dir];\n }\n dirConfigMap[dir] = loadExtendedConfig(configPath);\n return dirConfigMap[dir];\n };\n const extendConfig = (\n toExtend: SubConfig,\n current: SubConfig,\n ): SubConfig => ({\n // $FlowFixMe[exponential-spread]\n options: {...toExtend.options, ...current.options},\n excludes: Array.from(\n new Set([...toExtend.excludes, ...current.excludes]),\n ),\n });\n\n filesResponse\n .trim()\n .split('\\n')\n .forEach((configPath) => {\n const {dir} = path.parse(configPath);\n if (dir && !dirConfigMap[dir]) {\n dirConfigMap[dir] = loadExtendedConfig(configPath);\n }\n });\n return dirConfigMap;\n};\n\n/**\n * Loads a .json 'introspection query response', or a .graphql schema definition.\n */\nexport const getSchemas = (schemaFilePath: string): [GraphQLSchema, Schema] => {\n const raw = fs.readFileSync(schemaFilePath, 'utf8');\n if (schemaFilePath.endsWith('.graphql')) {\n const schemaForValidation = buildSchema(raw);\n const queryResponse = graphqlSync(\n schemaForValidation,\n getIntrospectionQuery({descriptions: true}),\n );\n const schemaForTypeGeneration = schemaFromIntrospectionData(\n // eslint-disable-next-line flowtype-errors/uncovered\n ((queryResponse.data: any): IntrospectionQuery),\n );\n return [schemaForValidation, schemaForTypeGeneration];\n } else {\n // eslint-disable-next-line flowtype-errors/uncovered\n const introspectionData: IntrospectionQuery = JSON.parse(raw);\n const schemaForValidation = buildClientSchema(introspectionData);\n const schemaForTypeGeneration =\n schemaFromIntrospectionData(introspectionData);\n return [schemaForValidation, schemaForTypeGeneration];\n }\n};\n\nconst validateOptions = (\n configFile: string,\n options: ExternalOptions,\n): void => {\n if (options) {\n const externalOptionsKeys = [\n 'pragma',\n 'loosePragma',\n 'ignorePragma',\n 'scalars',\n 'strictNullability',\n 'regenerateCommand',\n 'readOnlyArray',\n 'splitTypes',\n 'generatedDirectory',\n 'exportAllObjectTypes',\n 'typeFileName',\n 'experimentalEnums',\n ];\n Object.keys(options).forEach((k) => {\n if (!externalOptionsKeys.includes(k)) {\n throw new Error(\n `Invalid option in config file ${configFile}: ${k}. Allowed options: ${externalOptionsKeys.join(\n ', ',\n )}`,\n );\n }\n });\n }\n};\n"],"file":"config.js"}
1
+ {"version":3,"sources":["../../src/cli/config.js"],"names":["validateOrThrow","value","jsonSchema","result","valid","Error","errors","map","error","toString","join","loadConfigFile","configFile","data","require","configSchema","getSchemas","schemaFilePath","raw","fs","readFileSync","endsWith","schemaForValidation","queryResponse","descriptions","schemaForTypeGeneration","introspectionData","JSON","parse","findApplicableConfig","path","configs","Array","isArray","find","config","exclude","some","RegExp","test","match","matcher"],"mappings":";;;;;;;AAIA;;AACA;;AAEA;;AACA;;AAQA;;;;AAX0C;AAWL;AAE9B,MAAMA,eAAe,GAAG,CAACC,KAAD,EAAeC,UAAf,KAAqC;AAChE;AACA,QAAMC,MAAM,GAAG,0BAASF,KAAT,EAAgBC,UAAhB,CAAf;;AACA,MAAI,CAACC,MAAM,CAACC,KAAZ,EAAmB;AACf,UAAM,IAAIC,KAAJ,CACFF,MAAM,CAACG,MAAP,CAAcC,GAAd,CAAmBC,KAAD,IAAWA,KAAK,CAACC,QAAN,EAA7B,EAA+CC,IAA/C,CAAoD,IAApD,CADE,CAAN;AAGH;AACD;;AACH,CATM;;;;AAWA,MAAMC,cAAc,GAAIC,UAAD,IAAgC;AAC1D;AACA,QAAMC,IAAY,GAAGC,OAAO,CAACF,UAAD,CAA5B,CAF0D,CAG1D;;;AACAZ,EAAAA,eAA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P;AACH;;AACD,QAAI,CAACK,MAAM,CAACK,KAAZ,EAAmB;AACf,aAAO,IAAP;AACH;;AACD,WAAOL,MAAM,CAACK,KAAP,CAAaH,IAAb,CAAmBI,OAAD,IAAa,IAAIH,MAAJ,CAAWG,OAAX,EAAoBF,IAApB,CAAyBT,IAAzB,CAA/B,CAAP;AACH,GARM,CAAP;AASH,CAhBM","sourcesContent":["// @flow\nimport type {Schema} from '../types';\nimport type {GraphQLSchema} from 'graphql/type/schema';\n\nimport {schemaFromIntrospectionData} from '../schemaFromIntrospectionData';\nimport configSchema from './schema.json'; // eslint-disable-line flowtype-errors/uncovered\n\nimport fs from 'fs';\nimport {\n buildClientSchema,\n buildSchema,\n getIntrospectionQuery,\n graphqlSync,\n type IntrospectionQuery,\n} from 'graphql';\nimport type {Config, GenerateConfig} from '../types';\nimport {validate} from 'jsonschema'; // eslint-disable-line flowtype-errors/uncovered\n\nexport const validateOrThrow = (value: mixed, jsonSchema: mixed) => {\n /* eslint-disable flowtype-errors/uncovered */\n const result = validate(value, jsonSchema);\n if (!result.valid) {\n throw new Error(\n result.errors.map((error) => error.toString()).join('\\n'),\n );\n }\n /* eslint-enable flowtype-errors/uncovered */\n};\n\nexport const loadConfigFile = (configFile: string): Config => {\n // $FlowIgnore // eslint-disable-next-line flowtype-errors/uncovered\n const data: Config = require(configFile);\n // eslint-disable-next-line flowtype-errors/uncovered\n validateOrThrow(data, configSchema);\n return data;\n};\n\n/**\n * Loads a .json 'introspection query response', or a .graphql schema definition.\n */\nexport const getSchemas = (schemaFilePath: string): [GraphQLSchema, Schema] => {\n const raw = fs.readFileSync(schemaFilePath, 'utf8');\n if (schemaFilePath.endsWith('.graphql')) {\n const schemaForValidation = buildSchema(raw);\n const queryResponse = graphqlSync(\n schemaForValidation,\n getIntrospectionQuery({descriptions: true}),\n );\n const schemaForTypeGeneration = schemaFromIntrospectionData(\n // eslint-disable-next-line flowtype-errors/uncovered\n ((queryResponse.data: any): IntrospectionQuery),\n );\n return [schemaForValidation, schemaForTypeGeneration];\n } else {\n // eslint-disable-next-line flowtype-errors/uncovered\n const introspectionData: IntrospectionQuery = JSON.parse(raw);\n const schemaForValidation = buildClientSchema(introspectionData);\n const schemaForTypeGeneration =\n schemaFromIntrospectionData(introspectionData);\n return [schemaForValidation, schemaForTypeGeneration];\n }\n};\n\n/**\n * Find the first item of the `config.generate` array where both:\n * - no item of `exclude` matches\n * - at least one item of `match` matches\n */\nexport const findApplicableConfig = (\n path: string,\n configs: Array<GenerateConfig> | GenerateConfig,\n): ?GenerateConfig => {\n if (!Array.isArray(configs)) {\n configs = [configs];\n }\n return configs.find((config) => {\n if (config.exclude?.some((exclude) => new RegExp(exclude).test(path))) {\n return false;\n }\n if (!config.match) {\n return true;\n }\n return config.match.some((matcher) => new RegExp(matcher).test(path));\n });\n};\n"],"file":"config.js"}