@khanacademy/graphql-flow 0.2.4 → 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 (57) hide show
  1. package/.flowconfig +1 -0
  2. package/.github/workflows/changeset-release.yml +3 -17
  3. package/.github/workflows/pr-checks.yml +13 -10
  4. package/CHANGELOG.md +35 -0
  5. package/Readme.md +41 -132
  6. package/dist/__test__/example-schema.graphql +67 -0
  7. package/dist/__test__/generateTypeFileContents.test.js +157 -0
  8. package/dist/__test__/graphql-flow.test.js +639 -0
  9. package/dist/__test__/processPragmas.test.js +76 -0
  10. package/dist/cli/__test__/config.test.js +120 -0
  11. package/dist/cli/config.js +51 -26
  12. package/dist/cli/config.js.flow +40 -68
  13. package/dist/cli/config.js.map +1 -1
  14. package/dist/cli/run.js +41 -19
  15. package/dist/cli/run.js.flow +58 -22
  16. package/dist/cli/run.js.map +1 -1
  17. package/dist/cli/schema.json +91 -0
  18. package/dist/enums.js +20 -7
  19. package/dist/enums.js.flow +44 -15
  20. package/dist/enums.js.map +1 -1
  21. package/dist/generateResponseType.js +47 -47
  22. package/dist/generateResponseType.js.flow +55 -57
  23. package/dist/generateResponseType.js.map +1 -1
  24. package/dist/generateTypeFiles.js +41 -22
  25. package/dist/generateTypeFiles.js.flow +86 -78
  26. package/dist/generateTypeFiles.js.map +1 -1
  27. package/dist/generateVariablesType.js +24 -24
  28. package/dist/generateVariablesType.js.flow +25 -28
  29. package/dist/generateVariablesType.js.map +1 -1
  30. package/dist/index.js +18 -20
  31. package/dist/index.js.flow +31 -16
  32. package/dist/index.js.map +1 -1
  33. package/dist/parser/__test__/parse.test.js +247 -0
  34. package/dist/types.js.flow +28 -5
  35. package/flow-typed/npm/@babel/types_vx.x.x.js +17 -3
  36. package/package.json +3 -2
  37. package/src/__test__/generateTypeFileContents.test.js +55 -1
  38. package/src/__test__/graphql-flow.test.js +7 -7
  39. package/src/__test__/processPragmas.test.js +28 -15
  40. package/src/cli/__test__/config.test.js +120 -0
  41. package/src/cli/config.js +40 -68
  42. package/src/cli/run.js +58 -22
  43. package/src/cli/schema.json +91 -0
  44. package/src/enums.js +44 -15
  45. package/src/generateResponseType.js +55 -57
  46. package/src/generateTypeFiles.js +86 -78
  47. package/src/generateVariablesType.js +25 -28
  48. package/src/index.js +31 -16
  49. package/src/types.js +28 -5
  50. package/.github/actions/filter-files/action.yml +0 -37
  51. package/.github/actions/full-or-limited/action.yml +0 -27
  52. package/.github/actions/json-args/action.yml +0 -32
  53. package/.github/actions/setup/action.yml +0 -28
  54. package/dist/jest-mock-graphql-tag.js +0 -88
  55. package/dist/jest-mock-graphql-tag.js.flow +0 -96
  56. package/dist/jest-mock-graphql-tag.js.map +0 -1
  57. package/src/jest-mock-graphql-tag.js +0 -96
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/run.js"],"names":["findGraphqlTagReferences","root","response","encoding","cwd","trim","split","map","relative","path","join","_","__","configFile","cliFiles","process","argv","console","log","exit","config","schemaForValidation","schemaForTypeGeneration","schemaFilePath","inputFiles","length","files","f","Error","filesHadErrors","Object","keys","forEach","key","file","errors","error","message","resolved","loc","validationFailures","printedOperations","k","document","raw","excludes","some","rx","test","hasNonFragments","definitions","kind","rawSource","literals","withTypeNames","printed","includes","push","processedOptions","options","err","dumpOperations","parent","recursive","JSON","stringify","sort"],"mappings":"AAAA;;AAEA;;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAPwD;;AAUxD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AAEA,MAAMA,wBAAwB,GAAIC,IAAD,IAAiC;AAC9D,QAAMC,QAAQ,GAAG,6BACb,uFADa,EAEb;AACIC,IAAAA,QAAQ,EAAE,MADd;AAEIC,IAAAA,GAAG,EAAEH;AAFT,GAFa,CAAjB;AAOA,SAAOC,QAAQ,CACVG,IADE,GAEFC,KAFE,CAEI,IAFJ,EAGFC,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,OAAOE,GAAP,EAAY;AACV3C,IAAAA,OAAO,CAACmB,KAAR,CAAe,yCAAwCQ,GAAG,CAACL,GAAJ,CAAQ9B,IAAK,EAApE;AACAQ,IAAAA,OAAO,CAACmB,KAAR,CAAcmB,OAAd,EAFU,CAGV;;AACAtC,IAAAA,OAAO,CAACmB,KAAR,CAAcwB,GAAd;AACApB,IAAAA,kBAAkB;AACrB;AACJ,CAtDD;;AAwDA,IAAIA,kBAAJ,EAAwB;AACpBvB,EAAAA,OAAO,CAACmB,KAAR,CACK,eAAcI,kBAAmB,4CADtC,EADoB,CAIpB;;AACAzB,EAAAA,OAAO,CAACI,IAAR,CAAa,CAAb;AACH;;AAED,IAAIC,MAAM,CAACyC,cAAX,EAA2B;AACvB,QAAMA,cAAc,GAAGzC,MAAM,CAACyC,cAA9B;AACA,QAAMC,MAAM,GAAG,mBAAQD,cAAR,CAAf;AACA,qBAAUC,MAAV,EAAkB;AAACC,IAAAA,SAAS,EAAE;AAAZ,GAAlB;AACA,yBACIF,cADJ,EAEIG,IAAI,CAACC,SAAL,CAAexB,iBAAiB,CAACyB,IAAlB,EAAf,EAAyC,IAAzC,EAA+C,CAA/C,CAFJ;AAIH","sourcesContent":["#!/usr/bin/env node\n// @flow\n/* eslint-disable no-console */\nimport {generateTypeFiles, processPragmas} from '../generateTypeFiles';\nimport {processFiles} from '../parser/parse';\nimport {resolveDocuments} from '../parser/resolve';\nimport {getSchemas, loadConfigFile} from './config';\n\nimport {addTypenameToDocument} from 'apollo-utilities'; // eslint-disable-line flowtype-errors/uncovered\n\nimport {execSync} from 'child_process';\nimport {existsSync, mkdirSync, readFileSync, writeFileSync} from 'fs';\nimport {type DocumentNode} from 'graphql';\nimport {print} from 'graphql/language/printer';\nimport {validate} from 'graphql/validation';\nimport path from 'path';\nimport {dirname} from 'path';\n\n/**\n * This CLI tool executes the following steps:\n * 1) process options\n * 2) crawl files to find all operations and fragments, with\n * tagged template literals and expressions.\n * 3) resolve the found operations, passing the literals and\n * fragments into the `graphql-tag` function to produce\n * the DocumentNodes.\n * 4) generate types for all resolved Queries & Mutations\n */\n\n/** Step (1) */\n\nconst findGraphqlTagReferences = (root: string): Array<string> => {\n const response = execSync(\n \"git grep -I --word-regexp --name-only --fixed-strings 'graphql-tag' -- '*.js' '*.jsx'\",\n {\n encoding: 'utf8',\n cwd: root,\n },\n );\n return response\n .trim()\n .split('\\n')\n .map((relative) => path.join(root, relative));\n};\n\nconst [_, __, configFile, ...cliFiles] = process.argv;\n\nif (\n configFile === '-h' ||\n configFile === '--help' ||\n configFile === 'help' ||\n !configFile\n) {\n console.log(`graphql-flow\n\nUsage: graphql-flow [configFile.json] [filesToCrawl...]`);\n process.exit(1); // eslint-disable-line flowtype-errors/uncovered\n}\n\nconst config = loadConfigFile(configFile);\n\nconst [schemaForValidation, schemaForTypeGeneration] = getSchemas(\n config.schemaFilePath,\n);\n\nconst inputFiles = cliFiles.length\n ? cliFiles\n : findGraphqlTagReferences(process.cwd());\n\n/** Step (2) */\n\nconst files = processFiles(inputFiles, (f) => {\n if (existsSync(f)) {\n return readFileSync(f, 'utf8');\n }\n if (existsSync(f + '.js')) {\n return readFileSync(f + '.js', 'utf8');\n }\n throw new Error(`Unable to find ${f}`);\n});\n\nlet filesHadErrors = false;\nObject.keys(files).forEach((key) => {\n const file = files[key];\n if (file.errors.length) {\n filesHadErrors = true;\n console.error(`Errors in ${file.path}`);\n file.errors.forEach((error) => {\n console.error(` - ${error.message}`);\n });\n }\n});\n\nif (filesHadErrors) {\n console.error('Aborting');\n process.exit(1); // eslint-disable-line flowtype-errors/uncovered\n}\n\n/** Step (3) */\n\nconst {resolved, errors} = resolveDocuments(files);\nif (errors.length) {\n errors.forEach((error) => {\n console.error(`Resolution error ${error.message} in ${error.loc.path}`);\n });\n console.error('Aborting');\n process.exit(1); // eslint-disable-line flowtype-errors/uncovered\n}\n\nconsole.log(Object.keys(resolved).length, 'resolved queries');\n\n/** Step (4) */\n\nlet validationFailures: number = 0;\nconst printedOperations: Array<string> = [];\n\nObject.keys(resolved).forEach((k) => {\n const {document, raw} = resolved[k];\n if (config.excludes.some((rx) => rx.test(raw.loc.path))) {\n return; // skip\n }\n const hasNonFragments = document.definitions.some(\n ({kind}) => kind !== 'FragmentDefinition',\n );\n const rawSource: string = raw.literals[0];\n\n // eslint-disable-next-line flowtype-errors/uncovered\n const withTypeNames: DocumentNode = addTypenameToDocument(document);\n const printed = print(withTypeNames);\n if (hasNonFragments && !printedOperations.includes(printed)) {\n printedOperations.push(printed);\n }\n\n const processedOptions = processPragmas(config.options, rawSource);\n if (!processedOptions) {\n return;\n }\n\n if (hasNonFragments) {\n /* eslint-disable flowtype-errors/uncovered */\n const errors = validate(schemaForValidation, withTypeNames);\n /* eslint-disable flowtype-errors/uncovered */\n if (errors.length) {\n errors.forEach((error) => {\n console.error(\n `Schema validation found errors for ${raw.loc.path}!`,\n );\n console.error(printed);\n console.error(error);\n validationFailures++;\n });\n }\n /* eslint-enable flowtype-errors/uncovered */\n }\n\n try {\n generateTypeFiles(\n raw.loc.path,\n schemaForTypeGeneration,\n withTypeNames,\n processedOptions,\n );\n // eslint-disable-next-line flowtype-errors/uncovered\n } catch (err) {\n console.error(`Error while generating operation from ${raw.loc.path}`);\n console.error(printed);\n // eslint-disable-next-line flowtype-errors/uncovered\n console.error(err);\n validationFailures++;\n }\n});\n\nif (validationFailures) {\n console.error(\n `Encountered ${validationFailures} validation failures while printing types.`,\n );\n // eslint-disable-next-line flowtype-errors/uncovered\n process.exit(1);\n}\n\nif (config.dumpOperations) {\n const dumpOperations = config.dumpOperations;\n const parent = dirname(dumpOperations);\n mkdirSync(parent, {recursive: true});\n writeFileSync(\n dumpOperations,\n JSON.stringify(printedOperations.sort(), null, 2),\n );\n}\n"],"file":"run.js"}
1
+ {"version":3,"sources":["../../src/cli/run.js"],"names":["findGraphqlTagReferences","root","response","encoding","cwd","trim","split","map","relative","path","join","_","__","configFilePath","cliFiles","process","argv","console","log","exit","makeAbsPath","maybeRelativePath","basePath","isAbsolute","absConfigPath","config","inputFiles","length","crawl","dirname","files","f","Error","filesHadErrors","Object","keys","forEach","key","file","errors","error","message","resolved","loc","schemaCache","getCachedSchemas","schemaFilePath","validationFailures","printedOperations","filePathAndLine","document","raw","hasNonFragments","definitions","some","kind","rawSource","literals","generateConfig","generate","withTypeNames","printed","includes","push","pragmaResult","strict","strictNullability","schemaForValidation","schemaForTypeGeneration","err","dumpOperations","parent","recursive","JSON","stringify","sort"],"mappings":"AAAA;;AAEA;;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAPwD;;AAWxD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AAEA,MAAMA,wBAAwB,GAAIC,IAAD,IAAiC;AAC9D,QAAMC,QAAQ,GAAG,6BACb,uFADa,EAEb;AACIC,IAAAA,QAAQ,EAAE,MADd;AAEIC,IAAAA,GAAG,EAAEH;AAFT,GAFa,CAAjB;AAOA,SAAOC,QAAQ,CACVG,IADE,GAEFC,KAFE,CAEI,IAFJ,EAGFC,GAHE,CAGGC,QAAD,IAAcC,cAAKC,IAAL,CAAUT,IAAV,EAAgBO,QAAhB,CAHhB,CAAP;AAIH,CAZD;;AAcA,MAAM,CAACG,CAAD,EAAIC,EAAJ,EAAQC,cAAR,EAAwB,GAAGC,QAA3B,IAAuCC,OAAO,CAACC,IAArD;;AAEA,IACIH,cAAc,KAAK,IAAnB,IACAA,cAAc,KAAK,QADnB,IAEAA,cAAc,KAAK,MAFnB,IAGA,CAACA,cAJL,EAKE;AACEI,EAAAA,OAAO,CAACC,GAAR,CAAa;AACjB;AACA,wDAFI;AAGAH,EAAAA,OAAO,CAACI,IAAR,CAAa,CAAb,EAJF,CAImB;AACpB;;AAED,MAAMC,WAAW,GAAG,CAACC,iBAAD,EAA4BC,QAA5B,KAAiD;AACjE,SAAOb,cAAKc,UAAL,CAAgBF,iBAAhB,IACDA,iBADC,GAEDZ,cAAKC,I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AAQlC,IAAK,GADvD;AAGAQ,QAAAA,OAAO,CAACuB,KAAR,CAAcqB,OAAd;AACA5C,QAAAA,OAAO,CAACuB,KAAR,CAAcA,KAAd;AACAO,QAAAA,kBAAkB;AACrB,OAPD;AAQH;AACD;;AACH;;AAED,MAAI;AACA,8CACII,GAAG,CAACR,GAAJ,CAAQlC,IADZ,EAEI2D,uBAFJ,EAGIR,aAHJ,EAIIF,cAJJ,EADA,CAOA;AACH,GARD,CAQE,OAAOW,GAAP,EAAY;AACVpD,IAAAA,OAAO,CAACuB,KAAR,CAAe,yCAAwCW,GAAG,CAACR,GAAJ,CAAQlC,IAAK,EAApE;AACAQ,IAAAA,OAAO,CAACuB,KAAR,CAAcqB,OAAd,EAFU,CAGV;;AACA5C,IAAAA,OAAO,CAACuB,KAAR,CAAc6B,GAAd;AACAtB,IAAAA,kBAAkB;AACrB;AACJ,CAxED;;AA0EA,IAAIA,kBAAJ,EAAwB;AACpB9B,EAAAA,OAAO,CAACuB,KAAR,CACK,eAAcO,kBAAmB,4CADtC,EADoB,CAIpB;;AACAhC,EAAAA,OAAO,CAACI,IAAR,CAAa,CAAb;AACH;;AAED,IAAIM,MAAM,CAACG,KAAP,CAAa0C,cAAjB,EAAiC;AAC7B,QAAMA,cAAc,GAAG7C,MAAM,CAACG,KAAP,CAAa0C,cAApC;AACA,QAAMC,MAAM,GAAG,mBAAQD,cAAR,CAAf;AACA,qBAAUC,MAAV,EAAkB;AAACC,IAAAA,SAAS,EAAE;AAAZ,GAAlB;AACA,yBACIF,cADJ,EAEIG,IAAI,CAACC,SAAL,CAAe1B,iBAAiB,CAAC2B,IAAlB,EAAf,EAAyC,IAAzC,EAA+C,CAA/C,CAFJ;AAIH","sourcesContent":["#!/usr/bin/env node\n// @flow\n/* eslint-disable no-console */\nimport {generateTypeFiles, processPragmas} from '../generateTypeFiles';\nimport {processFiles} from '../parser/parse';\nimport {resolveDocuments} from '../parser/resolve';\nimport {findApplicableConfig, getSchemas, loadConfigFile} from './config';\n\nimport {addTypenameToDocument} from 'apollo-utilities'; // eslint-disable-line flowtype-errors/uncovered\n\nimport {execSync} from 'child_process';\nimport {existsSync, mkdirSync, readFileSync, writeFileSync} from 'fs';\nimport {type DocumentNode} from 'graphql';\nimport {print} from 'graphql/language/printer';\nimport {validate} from 'graphql/validation';\nimport path from 'path';\nimport {dirname} from 'path';\nimport type {GenerateConfig} from '../types';\n\n/**\n * This CLI tool executes the following steps:\n * 1) parse & validate config file\n * 2) crawl files to find all operations and fragments, with\n * tagged template literals and expressions.\n * 3) resolve the found operations, passing the literals and\n * fragments into the `graphql-tag` function to produce\n * the DocumentNodes.\n * 4) generate types for all resolved Queries & Mutations\n */\n\n/** Step (1) */\n\nconst findGraphqlTagReferences = (root: string): Array<string> => {\n const response = execSync(\n \"git grep -I --word-regexp --name-only --fixed-strings 'graphql-tag' -- '*.js' '*.jsx'\",\n {\n encoding: 'utf8',\n cwd: root,\n },\n );\n return response\n .trim()\n .split('\\n')\n .map((relative) => path.join(root, relative));\n};\n\nconst [_, __, configFilePath, ...cliFiles] = process.argv;\n\nif (\n configFilePath === '-h' ||\n configFilePath === '--help' ||\n configFilePath === 'help' ||\n !configFilePath\n) {\n console.log(`graphql-flow\n\nUsage: graphql-flow [configFile.json] [filesToCrawl...]`);\n process.exit(1); // eslint-disable-line flowtype-errors/uncovered\n}\n\nconst makeAbsPath = (maybeRelativePath: string, basePath: string) => {\n return path.isAbsolute(maybeRelativePath)\n ? maybeRelativePath\n : path.join(basePath, maybeRelativePath);\n};\n\nconst absConfigPath = makeAbsPath(configFilePath, process.cwd());\n\nconst config = loadConfigFile(absConfigPath);\n\nconst inputFiles = cliFiles.length\n ? cliFiles\n : findGraphqlTagReferences(\n makeAbsPath(config.crawl.root, path.dirname(absConfigPath)),\n );\n\n/** Step (2) */\n\nconst files = processFiles(inputFiles, (f) => {\n if (existsSync(f)) {\n return readFileSync(f, 'utf8');\n }\n if (existsSync(f + '.js')) {\n return readFileSync(f + '.js', 'utf8');\n }\n throw new Error(`Unable to find ${f}`);\n});\n\nlet filesHadErrors = false;\nObject.keys(files).forEach((key) => {\n const file = files[key];\n if (file.errors.length) {\n filesHadErrors = true;\n console.error(`Errors in ${file.path}`);\n file.errors.forEach((error) => {\n console.error(` - ${error.message}`);\n });\n }\n});\n\nif (filesHadErrors) {\n console.error('Aborting');\n process.exit(1); // eslint-disable-line flowtype-errors/uncovered\n}\n\n/** Step (3) */\n\nconst {resolved, errors} = resolveDocuments(files);\nif (errors.length) {\n errors.forEach((error) => {\n console.error(`Resolution error ${error.message} in ${error.loc.path}`);\n });\n console.error('Aborting');\n process.exit(1); // eslint-disable-line flowtype-errors/uncovered\n}\n\nconsole.log(Object.keys(resolved).length, 'resolved queries');\n\n/** Step (4) */\n\nconst schemaCache = {};\nconst getCachedSchemas = (schemaFilePath: string) => {\n if (!schemaCache[schemaFilePath]) {\n schemaCache[schemaFilePath] = getSchemas(\n makeAbsPath(schemaFilePath, path.dirname(absConfigPath)),\n );\n }\n\n return schemaCache[schemaFilePath];\n};\n\nlet validationFailures: number = 0;\nconst printedOperations: Array<string> = [];\n\nObject.keys(resolved).forEach((filePathAndLine) => {\n const {document, raw} = resolved[filePathAndLine];\n\n const hasNonFragments = document.definitions.some(\n ({kind}) => kind !== 'FragmentDefinition',\n );\n const rawSource: string = raw.literals[0];\n\n const generateConfig = findApplicableConfig(\n // strip off the trailing line number, e.g. `:23`\n filePathAndLine.split(':')[0],\n config.generate,\n );\n if (!generateConfig) {\n return; // no generate config matches, bail\n }\n\n // eslint-disable-next-line flowtype-errors/uncovered\n const withTypeNames: DocumentNode = addTypenameToDocument(document);\n const printed = print(withTypeNames);\n if (hasNonFragments && !printedOperations.includes(printed)) {\n printedOperations.push(printed);\n }\n\n const pragmaResult = processPragmas(\n generateConfig,\n config.crawl,\n rawSource,\n );\n if (!pragmaResult.generate) {\n return;\n }\n if (pragmaResult.strict != null) {\n generateConfig.strictNullability = pragmaResult.strict;\n }\n\n const [schemaForValidation, schemaForTypeGeneration] = getCachedSchemas(\n generateConfig.schemaFilePath,\n );\n\n if (hasNonFragments) {\n /* eslint-disable flowtype-errors/uncovered */\n const errors = validate(schemaForValidation, withTypeNames);\n /* eslint-disable flowtype-errors/uncovered */\n if (errors.length) {\n errors.forEach((error) => {\n console.error(\n `Schema validation found errors for ${raw.loc.path}!`,\n );\n console.error(printed);\n console.error(error);\n validationFailures++;\n });\n }\n /* eslint-enable flowtype-errors/uncovered */\n }\n\n try {\n generateTypeFiles(\n raw.loc.path,\n schemaForTypeGeneration,\n withTypeNames,\n generateConfig,\n );\n // eslint-disable-next-line flowtype-errors/uncovered\n } catch (err) {\n console.error(`Error while generating operation from ${raw.loc.path}`);\n console.error(printed);\n // eslint-disable-next-line flowtype-errors/uncovered\n console.error(err);\n validationFailures++;\n }\n});\n\nif (validationFailures) {\n console.error(\n `Encountered ${validationFailures} validation failures while printing types.`,\n );\n // eslint-disable-next-line flowtype-errors/uncovered\n process.exit(1);\n}\n\nif (config.crawl.dumpOperations) {\n const dumpOperations = config.crawl.dumpOperations;\n const parent = dirname(dumpOperations);\n mkdirSync(parent, {recursive: true});\n writeFileSync(\n dumpOperations,\n JSON.stringify(printedOperations.sort(), null, 2),\n );\n}\n"],"file":"run.js"}
@@ -0,0 +1,91 @@
1
+ {
2
+ "$schema":"http://json-schema.org/draft-07/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "definitions": {
6
+ "GenerateConfig": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "schemaFilePath": {
11
+ "type": "string"
12
+ },
13
+ "match": {
14
+ "type": "array",
15
+ "items": {
16
+ "oneOf": [
17
+ { "type": "object" },
18
+ { "type": "string" }
19
+ ]
20
+ }
21
+ },
22
+ "exclude": {
23
+ "type": "array",
24
+ "items": {
25
+ "oneOf": [
26
+ { "type": "object" },
27
+ { "type": "string" }
28
+ ]
29
+ }
30
+ },
31
+ "scalars": {
32
+ "type": "object"
33
+ },
34
+ "strictNullability": {
35
+ "type": "boolean"
36
+ },
37
+ "regenerateCommand": {
38
+ "type": "string"
39
+ },
40
+ "readOnlyArray": {
41
+ "type": "boolean"
42
+ },
43
+ "splitTypes": {
44
+ "type": "boolean"
45
+ },
46
+ "generatedDirectory": {
47
+ "type": "string"
48
+ },
49
+ "exportAllObjectTypes": {
50
+ "type": "boolean"
51
+ },
52
+ "typeFileName": {
53
+ "type": "string"
54
+ },
55
+ "experimentalEnums": {
56
+ "type": "boolean"
57
+ }
58
+ },
59
+ "required": [
60
+ "schemaFilePath"
61
+ ]
62
+ }
63
+ },
64
+ "properties": {
65
+ "crawl": {
66
+ "type": "object",
67
+ "additionalProperties": false,
68
+ "properties": {
69
+ "root": {"type": "string"},
70
+ "pragma": {
71
+ "type": "string"
72
+ },
73
+ "loosePragma": {
74
+ "type": "string"
75
+ },
76
+ "ignorePragma": {
77
+ "type": "string"
78
+ },
79
+ "dumpOperations": {
80
+ "type": "string"
81
+ }
82
+ },
83
+ "required": [ "root" ]
84
+ },
85
+ "generate": {"oneOf": [
86
+ {"$ref": "#/definitions/GenerateConfig"},
87
+ {"type": "array", "items": {"$ref": "#/definitions/GenerateConfig"}}
88
+ ]}
89
+ },
90
+ "required": [ "crawl", "generate" ]
91
+ }
package/dist/enums.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.scalarTypeToFlow = exports.enumTypeToFlow = exports.builtinScalars = void 0;
6
+ exports.scalarTypeToFlow = exports.experimentalEnumTypeToFlow = exports.enumTypeToFlow = exports.builtinScalars = void 0;
7
7
 
8
8
  var babelTypes = _interopRequireWildcard(require("@babel/types"));
9
9
 
@@ -16,15 +16,28 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
16
16
  /**
17
17
  * Both input & output types can have enums & scalars.
18
18
  */
19
- const enumTypeToFlow = (config, name) => {
20
- const enumConfig = config.schema.enumsByName[name];
19
+ const experimentalEnumTypeToFlow = (ctx, enumConfig, description) => {
20
+ const enumDeclaration = babelTypes.enumDeclaration( // pass id into generic type annotation
21
+ babelTypes.identifier(enumConfig.name), babelTypes.enumStringBody(enumConfig.enumValues.map(v => babelTypes.enumDefaultedMember(babelTypes.identifier(v.name)))));
22
+
23
+ if (ctx.experimentalEnumsMap) {
24
+ ctx.experimentalEnumsMap[enumConfig.name] = enumDeclaration;
25
+ }
26
+
27
+ return (0, _utils.maybeAddDescriptionComment)(description, babelTypes.genericTypeAnnotation(enumDeclaration.id));
28
+ };
29
+
30
+ exports.experimentalEnumTypeToFlow = experimentalEnumTypeToFlow;
31
+
32
+ const enumTypeToFlow = (ctx, name) => {
33
+ const enumConfig = ctx.schema.enumsByName[name];
21
34
  let combinedDescription = enumConfig.enumValues.map(n => `- ${n.name}` + (n.description ? '\n\n ' + n.description.replace(/\n/g, '\n ') : '')).join('\n');
22
35
 
23
36
  if (enumConfig.description) {
24
37
  combinedDescription = enumConfig.description + '\n\n' + combinedDescription;
25
38
  }
26
39
 
27
- return (0, _utils.maybeAddDescriptionComment)(combinedDescription, babelTypes.unionTypeAnnotation(enumConfig.enumValues.map(n => babelTypes.stringLiteralTypeAnnotation(n.name))));
40
+ return ctx.experimentalEnumsMap ? experimentalEnumTypeToFlow(ctx, enumConfig, combinedDescription) : (0, _utils.maybeAddDescriptionComment)(combinedDescription, babelTypes.unionTypeAnnotation(enumConfig.enumValues.map(n => babelTypes.stringLiteralTypeAnnotation(n.name))));
28
41
  };
29
42
 
30
43
  exports.enumTypeToFlow = enumTypeToFlow;
@@ -39,18 +52,18 @@ const builtinScalars = {
39
52
  };
40
53
  exports.builtinScalars = builtinScalars;
41
54
 
42
- const scalarTypeToFlow = (config, name) => {
55
+ const scalarTypeToFlow = (ctx, name) => {
43
56
  if (builtinScalars[name]) {
44
57
  return babelTypes.genericTypeAnnotation(babelTypes.identifier(builtinScalars[name]));
45
58
  }
46
59
 
47
- const underlyingType = config.scalars[name];
60
+ const underlyingType = ctx.scalars[name];
48
61
 
49
62
  if (underlyingType != null) {
50
63
  return babelTypes.genericTypeAnnotation(babelTypes.identifier(underlyingType));
51
64
  }
52
65
 
53
- config.errors.push(`Unexpected scalar '${name}'! Please add it to the "scalars" argument at the callsite of 'generateFlowTypes()'.`);
66
+ ctx.errors.push(`Unexpected scalar '${name}'! Please add it to the "scalars" argument at the callsite of 'generateFlowTypes()'.`);
54
67
  return babelTypes.genericTypeAnnotation(babelTypes.identifier(`UNKNOWN_SCALAR["${name}"]`));
55
68
  };
56
69
 
@@ -3,15 +3,41 @@
3
3
  * Both input & output types can have enums & scalars.
4
4
  */
5
5
  import * as babelTypes from '@babel/types';
6
- import {type BabelNodeFlowType} from '@babel/types';
7
- import type {Config} from './types';
6
+ import type {BabelNodeFlowType} from '@babel/types';
7
+ import type {Context} from './types';
8
8
  import {maybeAddDescriptionComment} from './utils';
9
+ import type {IntrospectionEnumType} from 'graphql/utilities/introspectionQuery';
10
+
11
+ export const experimentalEnumTypeToFlow = (
12
+ ctx: Context,
13
+ enumConfig: IntrospectionEnumType,
14
+ description: string,
15
+ ): BabelNodeFlowType => {
16
+ const enumDeclaration = babelTypes.enumDeclaration(
17
+ // pass id into generic type annotation
18
+ babelTypes.identifier(enumConfig.name),
19
+ babelTypes.enumStringBody(
20
+ enumConfig.enumValues.map((v) =>
21
+ babelTypes.enumDefaultedMember(babelTypes.identifier(v.name)),
22
+ ),
23
+ ),
24
+ );
25
+
26
+ if (ctx.experimentalEnumsMap) {
27
+ ctx.experimentalEnumsMap[enumConfig.name] = enumDeclaration;
28
+ }
29
+
30
+ return maybeAddDescriptionComment(
31
+ description,
32
+ babelTypes.genericTypeAnnotation(enumDeclaration.id),
33
+ );
34
+ };
9
35
 
10
36
  export const enumTypeToFlow = (
11
- config: Config,
37
+ ctx: Context,
12
38
  name: string,
13
39
  ): BabelNodeFlowType => {
14
- const enumConfig = config.schema.enumsByName[name];
40
+ const enumConfig = ctx.schema.enumsByName[name];
15
41
  let combinedDescription = enumConfig.enumValues
16
42
  .map(
17
43
  (n) =>
@@ -25,14 +51,17 @@ export const enumTypeToFlow = (
25
51
  combinedDescription =
26
52
  enumConfig.description + '\n\n' + combinedDescription;
27
53
  }
28
- return maybeAddDescriptionComment(
29
- combinedDescription,
30
- babelTypes.unionTypeAnnotation(
31
- enumConfig.enumValues.map((n) =>
32
- babelTypes.stringLiteralTypeAnnotation(n.name),
33
- ),
34
- ),
35
- );
54
+
55
+ return ctx.experimentalEnumsMap
56
+ ? experimentalEnumTypeToFlow(ctx, enumConfig, combinedDescription)
57
+ : maybeAddDescriptionComment(
58
+ combinedDescription,
59
+ babelTypes.unionTypeAnnotation(
60
+ enumConfig.enumValues.map((n) =>
61
+ babelTypes.stringLiteralTypeAnnotation(n.name),
62
+ ),
63
+ ),
64
+ );
36
65
  };
37
66
 
38
67
  export const builtinScalars: {[key: string]: string} = {
@@ -46,7 +75,7 @@ export const builtinScalars: {[key: string]: string} = {
46
75
  };
47
76
 
48
77
  export const scalarTypeToFlow = (
49
- config: Config,
78
+ ctx: Context,
50
79
  name: string,
51
80
  ): BabelNodeFlowType => {
52
81
  if (builtinScalars[name]) {
@@ -54,13 +83,13 @@ export const scalarTypeToFlow = (
54
83
  babelTypes.identifier(builtinScalars[name]),
55
84
  );
56
85
  }
57
- const underlyingType = config.scalars[name];
86
+ const underlyingType = ctx.scalars[name];
58
87
  if (underlyingType != null) {
59
88
  return babelTypes.genericTypeAnnotation(
60
89
  babelTypes.identifier(underlyingType),
61
90
  );
62
91
  }
63
- config.errors.push(
92
+ ctx.errors.push(
64
93
  `Unexpected scalar '${name}'! Please add it to the "scalars" argument at the callsite of 'generateFlowTypes()'.`,
65
94
  );
66
95
  return babelTypes.genericTypeAnnotation(
package/dist/enums.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/enums.js"],"names":["enumTypeToFlow","config","name","enumConfig","schema","enumsByName","combinedDescription","enumValues","map","n","description","replace","join","babelTypes","unionTypeAnnotation","stringLiteralTypeAnnotation","builtinScalars","Boolean","String","DateTime","Date","ID","Int","Float","scalarTypeToFlow","genericTypeAnnotation","identifier","underlyingType","scalars","errors","push"],"mappings":";;;;;;;AAIA;;AAGA;;;;;;AANA;AACA;AACA;AAMO,MAAMA,cAAc,GAAG,CAC1BC,MAD0B,EAE1BC,IAF0B,KAGN;AACpB,QAAMC,UAAU,GAAGF,MAAM,CAACG,MAAP,CAAcC,WAAd,CAA0BH,IAA1B,CAAnB;AACA,MAAII,mBAAmB,GAAGH,UAAU,CAACI,UAAX,CACrBC,GADqB,CAEjBC,CAAD,IACK,KAAIA,CAAC,CAACP,IAAK,EAAZ,IACCO,CAAC,CAACC,WAAF,GACK,eAAeD,CAAC,CAACC,WAAF,CAAcC,OAAd,CAAsB,KAAtB,EAA6B,UAA7B,CADpB,GAEK,EAHN,CAHc,EAQrBC,IARqB,CAQhB,IARgB,CAA1B;;AASA,MAAIT,UAAU,CAACO,WAAf,EAA4B;AACxBJ,IAAAA,mBAAmB,GACfH,UAAU,CAACO,WAAX,GAAyB,MAAzB,GAAkCJ,mBADtC;AAEH;;AACD,SAAO,uCACHA,mBADG,EAEHO,UAAU,CAACC,mBAAX,CACIX,UAAU,CAACI,UAAX,CAAsBC,GAAtB,CAA2BC,CAAD,IACtBI,UAAU,CAACE,2BAAX,CAAuCN,CAAC,CAACP,IAAzC,CADJ,CADJ,CAFG,CAAP;AAQH,CA1BM;;;AA4BA,MAAMc,cAAuC,GAAG;AACnDC,EAAAA,OAAO,EAAE,SAD0C;AAEnDC,EAAAA,MAAM,EAAE,QAF2C;AAGnDC,EAAAA,QAAQ,EAAE,QAHyC;AAInDC,EAAAA,IAAI,EAAE,QAJ6C;AAKnDC,EAAAA,EAAE,EAAE,QAL+C;AAMnDC,EAAAA,GAAG,EAAE,QAN8C;AAOnDC,EAAAA,KAAK,EAAE;AAP4C,CAAhD;;;AAUA,MAAMC,gBAAgB,GAAG,CAC5BvB,MAD4B,EAE5BC,IAF4B,KAGR;AACpB,MAAIc,cAAc,CAACd,IAAD,CAAlB,EAA0B;AACtB,WAAOW,UAAU,CAACY,qBAAX,CACHZ,UAAU,CAACa,UAAX,CAAsBV,cAAc,CAACd,IAAD,CAApC,CADG,CAAP;AAGH;;AACD,QAAMyB,cAAc,GAAG1B,MAAM,CAAC2B,OAAP,CAAe1B,IAAf,CAAvB;;AACA,MAAIyB,cAAc,IAAI,IAAtB,EAA4B;AACxB,WAAOd,UAAU,CAACY,qBAAX,CACHZ,UAAU,CAACa,UAAX,CAAsBC,cAAtB,CADG,CAAP;AAGH;;AACD1B,EAAAA,MAAM,CAAC4B,MAAP,CAAcC,IAAd,CACK,sBAAqB5B,IAAK,sFAD/B;AAGA,SAAOW,UAAU,CAACY,qBAAX,CACHZ,UAAU,CAACa,UAAX,CAAuB,mBAAkBxB,IAAK,IAA9C,CADG,CAAP;AAGH,CArBM","sourcesContent":["// @flow\n/**\n * Both input & output types can have enums & scalars.\n */\nimport * as babelTypes from '@babel/types';\nimport {type BabelNodeFlowType} from '@babel/types';\nimport type {Config} from './types';\nimport {maybeAddDescriptionComment} from './utils';\n\nexport const enumTypeToFlow = (\n config: Config,\n name: string,\n): BabelNodeFlowType => {\n const enumConfig = config.schema.enumsByName[name];\n let combinedDescription = enumConfig.enumValues\n .map(\n (n) =>\n `- ${n.name}` +\n (n.description\n ? '\\n\\n ' + n.description.replace(/\\n/g, '\\n ')\n : ''),\n )\n .join('\\n');\n if (enumConfig.description) {\n combinedDescription =\n enumConfig.description + '\\n\\n' + combinedDescription;\n }\n return maybeAddDescriptionComment(\n combinedDescription,\n babelTypes.unionTypeAnnotation(\n enumConfig.enumValues.map((n) =>\n babelTypes.stringLiteralTypeAnnotation(n.name),\n ),\n ),\n );\n};\n\nexport const builtinScalars: {[key: string]: string} = {\n Boolean: 'boolean',\n String: 'string',\n DateTime: 'string',\n Date: 'string',\n ID: 'string',\n Int: 'number',\n Float: 'number',\n};\n\nexport const scalarTypeToFlow = (\n config: Config,\n name: string,\n): BabelNodeFlowType => {\n if (builtinScalars[name]) {\n return babelTypes.genericTypeAnnotation(\n babelTypes.identifier(builtinScalars[name]),\n );\n }\n const underlyingType = config.scalars[name];\n if (underlyingType != null) {\n return babelTypes.genericTypeAnnotation(\n babelTypes.identifier(underlyingType),\n );\n }\n config.errors.push(\n `Unexpected scalar '${name}'! Please add it to the \"scalars\" argument at the callsite of 'generateFlowTypes()'.`,\n );\n return babelTypes.genericTypeAnnotation(\n babelTypes.identifier(`UNKNOWN_SCALAR[\"${name}\"]`),\n );\n};\n"],"file":"enums.js"}
1
+ {"version":3,"sources":["../src/enums.js"],"names":["experimentalEnumTypeToFlow","ctx","enumConfig","description","enumDeclaration","babelTypes","identifier","name","enumStringBody","enumValues","map","v","enumDefaultedMember","experimentalEnumsMap","genericTypeAnnotation","id","enumTypeToFlow","schema","enumsByName","combinedDescription","n","replace","join","unionTypeAnnotation","stringLiteralTypeAnnotation","builtinScalars","Boolean","String","DateTime","Date","ID","Int","Float","scalarTypeToFlow","underlyingType","scalars","errors","push"],"mappings":";;;;;;;AAIA;;AAGA;;;;;;AANA;AACA;AACA;AAOO,MAAMA,0BAA0B,GAAG,CACtCC,GADsC,EAEtCC,UAFsC,EAGtCC,WAHsC,KAIlB;AACpB,QAAMC,eAAe,GAAGC,UAAU,CAACD,eAAX,EACpB;AACAC,EAAAA,UAAU,CAACC,UAAX,CAAsBJ,UAAU,CAACK,IAAjC,CAFoB,EAGpBF,UAAU,CAACG,cAAX,CACIN,UAAU,CAACO,UAAX,CAAsBC,GAAtB,CAA2BC,CAAD,IACtBN,UAAU,CAACO,mBAAX,CAA+BP,UAAU,CAACC,UAAX,CAAsBK,CAAC,CAACJ,IAAxB,CAA/B,CADJ,CADJ,CAHoB,CAAxB;;AAUA,MAAIN,GAAG,CAACY,oBAAR,EAA8B;AAC1BZ,IAAAA,GAAG,CAACY,oBAAJ,CAAyBX,UAAU,CAACK,IAApC,IAA4CH,eAA5C;AACH;;AAED,SAAO,uCACHD,WADG,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G,CAC5BhC,GAD4B,EAE5BM,IAF4B,KAGR;AACpB,MAAIkB,cAAc,CAAClB,IAAD,CAAlB,EAA0B;AACtB,WAAOF,UAAU,CAACS,qBAAX,CACHT,UAAU,CAACC,UAAX,CAAsBmB,cAAc,CAAClB,IAAD,CAApC,CADG,CAAP;AAGH;;AACD,QAAM2B,cAAc,GAAGjC,GAAG,CAACkC,OAAJ,CAAY5B,IAAZ,CAAvB;;AACA,MAAI2B,cAAc,IAAI,IAAtB,EAA4B;AACxB,WAAO7B,UAAU,CAACS,qBAAX,CACHT,UAAU,CAACC,UAAX,CAAsB4B,cAAtB,CADG,CAAP;AAGH;;AACDjC,EAAAA,GAAG,CAACmC,MAAJ,CAAWC,IAAX,CACK,sBAAqB9B,IAAK,sFAD/B;AAGA,SAAOF,UAAU,CAACS,qBAAX,CACHT,UAAU,CAACC,UAAX,CAAuB,mBAAkBC,IAAK,IAA9C,CADG,CAAP;AAGH,CArBM","sourcesContent":["// @flow\n/**\n * Both input & output types can have enums & scalars.\n */\nimport * as babelTypes from '@babel/types';\nimport type {BabelNodeFlowType} from '@babel/types';\nimport type {Context} from './types';\nimport {maybeAddDescriptionComment} from './utils';\nimport type {IntrospectionEnumType} from 'graphql/utilities/introspectionQuery';\n\nexport const experimentalEnumTypeToFlow = (\n ctx: Context,\n enumConfig: IntrospectionEnumType,\n description: string,\n): BabelNodeFlowType => {\n const enumDeclaration = babelTypes.enumDeclaration(\n // pass id into generic type annotation\n babelTypes.identifier(enumConfig.name),\n babelTypes.enumStringBody(\n enumConfig.enumValues.map((v) =>\n babelTypes.enumDefaultedMember(babelTypes.identifier(v.name)),\n ),\n ),\n );\n\n if (ctx.experimentalEnumsMap) {\n ctx.experimentalEnumsMap[enumConfig.name] = enumDeclaration;\n }\n\n return maybeAddDescriptionComment(\n description,\n babelTypes.genericTypeAnnotation(enumDeclaration.id),\n );\n};\n\nexport const enumTypeToFlow = (\n ctx: Context,\n name: string,\n): BabelNodeFlowType => {\n const enumConfig = ctx.schema.enumsByName[name];\n let combinedDescription = enumConfig.enumValues\n .map(\n (n) =>\n `- ${n.name}` +\n (n.description\n ? '\\n\\n ' + n.description.replace(/\\n/g, '\\n ')\n : ''),\n )\n .join('\\n');\n if (enumConfig.description) {\n combinedDescription =\n enumConfig.description + '\\n\\n' + combinedDescription;\n }\n\n return ctx.experimentalEnumsMap\n ? experimentalEnumTypeToFlow(ctx, enumConfig, combinedDescription)\n : maybeAddDescriptionComment(\n combinedDescription,\n babelTypes.unionTypeAnnotation(\n enumConfig.enumValues.map((n) =>\n babelTypes.stringLiteralTypeAnnotation(n.name),\n ),\n ),\n );\n};\n\nexport const builtinScalars: {[key: string]: string} = {\n Boolean: 'boolean',\n String: 'string',\n DateTime: 'string',\n Date: 'string',\n ID: 'string',\n Int: 'number',\n Float: 'number',\n};\n\nexport const scalarTypeToFlow = (\n ctx: Context,\n name: string,\n): BabelNodeFlowType => {\n if (builtinScalars[name]) {\n return babelTypes.genericTypeAnnotation(\n babelTypes.identifier(builtinScalars[name]),\n );\n }\n const underlyingType = ctx.scalars[name];\n if (underlyingType != null) {\n return babelTypes.genericTypeAnnotation(\n babelTypes.identifier(underlyingType),\n );\n }\n ctx.errors.push(\n `Unexpected scalar '${name}'! Please add it to the \"scalars\" argument at the callsite of 'generateFlowTypes()'.`,\n );\n return babelTypes.genericTypeAnnotation(\n babelTypes.identifier(`UNKNOWN_SCALAR[\"${name}\"]`),\n );\n};\n"],"file":"enums.js"}
@@ -21,15 +21,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
21
21
 
22
22
  /* eslint-disable no-console */
23
23
  // eslint-disable-line flowtype-errors/uncovered
24
- const generateResponseType = (schema, query, config) => {
25
- const ast = querySelectionToObjectType(config, query.selectionSet.selections, query.operation === 'mutation' ? schema.typesByName.Mutation : schema.typesByName.Query, query.operation === 'mutation' ? 'mutation' : 'query'); // eslint-disable-next-line flowtype-errors/uncovered
24
+ const generateResponseType = (schema, query, ctx) => {
25
+ const ast = querySelectionToObjectType(ctx, query.selectionSet.selections, query.operation === 'mutation' ? schema.typesByName.Mutation : schema.typesByName.Query, query.operation === 'mutation' ? 'mutation' : 'query'); // eslint-disable-next-line flowtype-errors/uncovered
26
26
 
27
27
  return (0, _generator.default)(ast).code;
28
28
  };
29
29
 
30
30
  exports.generateResponseType = generateResponseType;
31
31
 
32
- const sortedObjectTypeAnnotation = (config, properties) => {
32
+ const sortedObjectTypeAnnotation = (ctx, properties) => {
33
33
  const obj = babelTypes.objectTypeAnnotation(properties.sort((a, b) => {
34
34
  if (a.type === 'ObjectTypeProperty' && b.type === 'ObjectTypeProperty') {
35
35
  const aName = a.key.type === 'Identifier' ? a.key.name : '';
@@ -47,27 +47,27 @@ const sortedObjectTypeAnnotation = (config, properties) => {
47
47
  , true
48
48
  /* exact */
49
49
  );
50
- const name = config.path.join('_');
51
- const isTopLevelType = config.path.length <= 1;
50
+ const name = ctx.path.join('_');
51
+ const isTopLevelType = ctx.path.length <= 1;
52
52
 
53
- if (config.allObjectTypes != null && !isTopLevelType) {
54
- config.allObjectTypes[name] = obj;
53
+ if (ctx.allObjectTypes != null && !isTopLevelType) {
54
+ ctx.allObjectTypes[name] = obj;
55
55
  return babelTypes.genericTypeAnnotation(babelTypes.identifier(name));
56
56
  } else {
57
57
  return obj;
58
58
  }
59
59
  };
60
60
 
61
- const generateFragmentType = (schema, fragment, config) => {
61
+ const generateFragmentType = (schema, fragment, ctx) => {
62
62
  const onType = fragment.typeCondition.name.value;
63
63
  let ast;
64
64
 
65
65
  if (schema.typesByName[onType]) {
66
- ast = sortedObjectTypeAnnotation(config, objectPropertiesToFlow(config, schema.typesByName[onType], onType, fragment.selectionSet.selections));
66
+ ast = sortedObjectTypeAnnotation(ctx, objectPropertiesToFlow(ctx, schema.typesByName[onType], onType, fragment.selectionSet.selections));
67
67
  } else if (schema.interfacesByName[onType]) {
68
- ast = unionOrInterfaceToFlow(config, config.schema.interfacesByName[onType], fragment.selectionSet.selections);
68
+ ast = unionOrInterfaceToFlow(ctx, ctx.schema.interfacesByName[onType], fragment.selectionSet.selections);
69
69
  } else if (schema.unionsByName[onType]) {
70
- ast = unionOrInterfaceToFlow(config, config.schema.unionsByName[onType], fragment.selectionSet.selections);
70
+ ast = unionOrInterfaceToFlow(ctx, ctx.schema.unionsByName[onType], fragment.selectionSet.selections);
71
71
  } else {
72
72
  throw new Error(`Unknown ${onType}`);
73
73
  } // eslint-disable-next-line flowtype-errors/uncovered
@@ -78,24 +78,24 @@ const generateFragmentType = (schema, fragment, config) => {
78
78
 
79
79
  exports.generateFragmentType = generateFragmentType;
80
80
 
81
- const _typeToFlow = (config, type, selection) => {
81
+ const _typeToFlow = (ctx, type, selection) => {
82
82
  if (type.kind === 'SCALAR') {
83
- return (0, _enums.scalarTypeToFlow)(config, type.name);
83
+ return (0, _enums.scalarTypeToFlow)(ctx, type.name);
84
84
  }
85
85
 
86
86
  if (type.kind === 'LIST') {
87
- return babelTypes.genericTypeAnnotation(config.readOnlyArray ? babelTypes.identifier('$ReadOnlyArray') : babelTypes.identifier('Array'), babelTypes.typeParameterInstantiation([typeToFlow(config, type.ofType, selection)]));
87
+ return babelTypes.genericTypeAnnotation(ctx.readOnlyArray ? babelTypes.identifier('$ReadOnlyArray') : babelTypes.identifier('Array'), babelTypes.typeParameterInstantiation([typeToFlow(ctx, type.ofType, selection)]));
88
88
  }
89
89
 
90
90
  if (type.kind === 'UNION') {
91
- const union = config.schema.unionsByName[type.name];
91
+ const union = ctx.schema.unionsByName[type.name];
92
92
 
93
93
  if (!selection.selectionSet) {
94
94
  console.log('no selection set', selection);
95
95
  return babelTypes.anyTypeAnnotation();
96
96
  }
97
97
 
98
- return unionOrInterfaceToFlow(config, union, selection.selectionSet.selections);
98
+ return unionOrInterfaceToFlow(ctx, union, selection.selectionSet.selections);
99
99
  }
100
100
 
101
101
  if (type.kind === 'INTERFACE') {
@@ -104,11 +104,11 @@ const _typeToFlow = (config, type, selection) => {
104
104
  return babelTypes.anyTypeAnnotation();
105
105
  }
106
106
 
107
- return unionOrInterfaceToFlow(config, config.schema.interfacesByName[type.name], selection.selectionSet.selections);
107
+ return unionOrInterfaceToFlow(ctx, ctx.schema.interfacesByName[type.name], selection.selectionSet.selections);
108
108
  }
109
109
 
110
110
  if (type.kind === 'ENUM') {
111
- return (0, _enums.enumTypeToFlow)(config, type.name);
111
+ return (0, _enums.enumTypeToFlow)(ctx, type.name);
112
112
  }
113
113
 
114
114
  if (type.kind !== 'OBJECT') {
@@ -118,33 +118,33 @@ const _typeToFlow = (config, type, selection) => {
118
118
 
119
119
  const tname = type.name;
120
120
 
121
- if (!config.schema.typesByName[tname]) {
121
+ if (!ctx.schema.typesByName[tname]) {
122
122
  console.log('unknown referenced type', tname);
123
123
  return babelTypes.anyTypeAnnotation();
124
124
  }
125
125
 
126
- const childType = config.schema.typesByName[tname];
126
+ const childType = ctx.schema.typesByName[tname];
127
127
 
128
128
  if (!selection.selectionSet) {
129
129
  console.log('no selection set', selection);
130
130
  return babelTypes.anyTypeAnnotation();
131
131
  }
132
132
 
133
- return (0, _utils.maybeAddDescriptionComment)(childType.description, querySelectionToObjectType(config, selection.selectionSet.selections, childType, tname));
133
+ return (0, _utils.maybeAddDescriptionComment)(childType.description, querySelectionToObjectType(ctx, selection.selectionSet.selections, childType, tname));
134
134
  };
135
135
 
136
- const typeToFlow = (config, type, selection) => {
136
+ const typeToFlow = (ctx, type, selection) => {
137
137
  // throw new Error('npoe');
138
138
  if (type.kind === 'NON_NULL') {
139
- return _typeToFlow(config, type.ofType, selection);
139
+ return _typeToFlow(ctx, type.ofType, selection);
140
140
  } // If we don'babelTypes care about strict nullability checking, then pretend everything is non-null
141
141
 
142
142
 
143
- if (!config.strictNullability) {
144
- return _typeToFlow(config, type, selection);
143
+ if (!ctx.strictNullability) {
144
+ return _typeToFlow(ctx, type, selection);
145
145
  }
146
146
 
147
- const inner = _typeToFlow(config, type, selection);
147
+ const inner = _typeToFlow(ctx, type, selection);
148
148
 
149
149
  const result = babelTypes.nullableTypeAnnotation(inner);
150
150
  return (0, _utils.transferLeadingComments)(inner, result);
@@ -176,11 +176,11 @@ const ensureOnlyOneTypenameProperty = properties => {
176
176
  });
177
177
  };
178
178
 
179
- const querySelectionToObjectType = (config, selections, type, typeName) => {
180
- return sortedObjectTypeAnnotation(config, ensureOnlyOneTypenameProperty(objectPropertiesToFlow(config, type, typeName, selections)));
179
+ const querySelectionToObjectType = (ctx, selections, type, typeName) => {
180
+ return sortedObjectTypeAnnotation(ctx, ensureOnlyOneTypenameProperty(objectPropertiesToFlow(ctx, type, typeName, selections)));
181
181
  };
182
182
 
183
- const objectPropertiesToFlow = (config, type, typeName, selections) => {
183
+ const objectPropertiesToFlow = (ctx, type, typeName, selections) => {
184
184
  return [].concat(...selections.map(selection => {
185
185
  switch (selection.kind) {
186
186
  case 'InlineFragment':
@@ -193,16 +193,16 @@ const objectPropertiesToFlow = (config, type, typeName, selections) => {
193
193
  return [];
194
194
  }
195
195
 
196
- return objectPropertiesToFlow(config, config.schema.typesByName[newTypeName], newTypeName, selection.selectionSet.selections);
196
+ return objectPropertiesToFlow(ctx, ctx.schema.typesByName[newTypeName], newTypeName, selection.selectionSet.selections);
197
197
  }
198
198
 
199
199
  case 'FragmentSpread':
200
- if (!config.fragments[selection.name.value]) {
201
- config.errors.push(`No fragment named '${selection.name.value}'. Did you forget to include it in the template literal?`);
200
+ if (!ctx.fragments[selection.name.value]) {
201
+ ctx.errors.push(`No fragment named '${selection.name.value}'. Did you forget to include it in the template literal?`);
202
202
  return [babelTypes.objectTypeProperty(babelTypes.identifier(selection.name.value), babelTypes.genericTypeAnnotation(babelTypes.identifier(`UNKNOWN_FRAGMENT`)))];
203
203
  }
204
204
 
205
- return objectPropertiesToFlow(config, type, typeName, config.fragments[selection.name.value].selectionSet.selections);
205
+ return objectPropertiesToFlow(ctx, type, typeName, ctx.fragments[selection.name.value].selectionSet.selections);
206
206
 
207
207
  case 'Field':
208
208
  const name = selection.name.value;
@@ -213,17 +213,17 @@ const objectPropertiesToFlow = (config, type, typeName, selections) => {
213
213
  }
214
214
 
215
215
  if (!type.fieldsByName[name]) {
216
- config.errors.push(`Unknown field '${name}' for type '${typeName}'`);
216
+ ctx.errors.push(`Unknown field '${name}' for type '${typeName}'`);
217
217
  return babelTypes.objectTypeProperty(babelTypes.identifier(alias), babelTypes.genericTypeAnnotation(babelTypes.identifier(`UNKNOWN_FIELD["${name}"]`)));
218
218
  }
219
219
 
220
220
  const typeField = type.fieldsByName[name];
221
- return [(0, _utils.maybeAddDescriptionComment)(typeField.description, (0, _utils.liftLeadingPropertyComments)(babelTypes.objectTypeProperty(babelTypes.identifier(alias), typeToFlow({ ...config,
222
- path: config.path.concat([alias])
221
+ return [(0, _utils.maybeAddDescriptionComment)(typeField.description, (0, _utils.liftLeadingPropertyComments)(babelTypes.objectTypeProperty(babelTypes.identifier(alias), typeToFlow({ ...ctx,
222
+ path: ctx.path.concat([alias])
223
223
  }, typeField.type, selection))))];
224
224
 
225
225
  default:
226
- config.errors.push( // eslint-disable-next-line flowtype-errors/uncovered
226
+ ctx.errors.push( // eslint-disable-next-line flowtype-errors/uncovered
227
227
  `Unsupported selection kind '${selection.kind}'`);
228
228
  return [];
229
229
  }
@@ -232,13 +232,13 @@ const objectPropertiesToFlow = (config, type, typeName, selections) => {
232
232
 
233
233
  exports.objectPropertiesToFlow = objectPropertiesToFlow;
234
234
 
235
- const unionOrInterfaceToFlow = (config, type, selections) => {
235
+ const unionOrInterfaceToFlow = (ctx, type, selections) => {
236
236
  const allFields = selections.every(selection => selection.kind === 'Field');
237
237
  const selectedAttributes = type.possibleTypes.slice().sort((a, b) => {
238
238
  return a.name < b.name ? -1 : 1;
239
239
  }).map(possible => {
240
- const configWithUpdatedPath = { ...config,
241
- path: allFields ? config.path : config.path.concat([possible.name])
240
+ const configWithUpdatedPath = { ...ctx,
241
+ path: allFields ? ctx.path : ctx.path.concat([possible.name])
242
242
  };
243
243
  return {
244
244
  typeName: possible.name,
@@ -255,11 +255,11 @@ const unionOrInterfaceToFlow = (config, type, selections) => {
255
255
  attrs.attributes[typeNameIndex].value)));
256
256
  }
257
257
 
258
- return sortedObjectTypeAnnotation(config, sharedAttributes);
258
+ return sortedObjectTypeAnnotation(ctx, sharedAttributes);
259
259
  }
260
260
 
261
261
  if (selectedAttributes.length === 1) {
262
- return sortedObjectTypeAnnotation(config, selectedAttributes[0].attributes);
262
+ return sortedObjectTypeAnnotation(ctx, selectedAttributes[0].attributes);
263
263
  }
264
264
  /**
265
265
  * When generating the objects for the sub-options of a union, the path needs
@@ -296,13 +296,13 @@ const unionOrInterfaceToFlow = (config, type, selections) => {
296
296
  const result = babelTypes.unionTypeAnnotation(selectedAttributes.map(({
297
297
  typeName,
298
298
  attributes
299
- }) => sortedObjectTypeAnnotation({ ...config,
300
- path: config.path.concat([typeName])
299
+ }) => sortedObjectTypeAnnotation({ ...ctx,
300
+ path: ctx.path.concat([typeName])
301
301
  }, attributes)));
302
- const name = config.path.join('_');
302
+ const name = ctx.path.join('_');
303
303
 
304
- if (config.allObjectTypes && config.path.length > 1) {
305
- config.allObjectTypes[name] = result;
304
+ if (ctx.allObjectTypes && ctx.path.length > 1) {
305
+ ctx.allObjectTypes[name] = result;
306
306
  return babelTypes.genericTypeAnnotation(babelTypes.identifier(name));
307
307
  }
308
308