apollo-codegen
Advanced tools
Comparing version 0.19.1 to 0.20.0-alpha.f3534c9a
@@ -16,4 +16,7 @@ #!/usr/bin/env node | ||
const yargs = require("yargs"); | ||
const _1 = require("."); | ||
const errors_1 = require("./errors"); | ||
const downloadSchema_1 = require("./downloadSchema"); | ||
const introspectSchema_1 = require("./introspectSchema"); | ||
const printSchema_1 = require("./printSchema"); | ||
const errors_1 = require("apollo-codegen-core/lib/errors"); | ||
const generate_1 = require("./generate"); | ||
require("source-map-support/register"); | ||
@@ -69,6 +72,6 @@ process.on('unhandledRejection', (error) => { throw error; }); | ||
if (urlRegex.test(schema)) { | ||
yield _1.downloadSchema(schema, output, header, insecure, method); | ||
yield downloadSchema_1.default(schema, output, header, insecure, method); | ||
} | ||
else { | ||
yield _1.introspectSchema(schema, output); | ||
yield introspectSchema_1.default(schema, output); | ||
} | ||
@@ -93,3 +96,3 @@ })) | ||
const { schema, output } = argv; | ||
yield _1.printSchema(schema, output); | ||
yield printSchema_1.default(schema, output); | ||
})) | ||
@@ -104,2 +107,3 @@ .command('generate [input...]', 'Generate code from a GraphQL schema and query documents', { | ||
output: { | ||
demand: true, | ||
describe: 'Output directory for the generated files', | ||
@@ -112,3 +116,3 @@ normalize: true, | ||
describe: 'Code generation target language', | ||
choices: ['swift', 'scala', 'json', 'ts', 'ts-modern', 'typescript', 'typescript-modern', 'flow', 'flow-modern'], | ||
choices: ['swift', 'scala', 'json', 'ts-legacy', 'ts', 'typescript-legacy', 'typescript', 'flow-leagcy', 'flow'], | ||
default: 'swift' | ||
@@ -128,3 +132,3 @@ }, | ||
demand: false, | ||
describe: "Don't attempt to map custom scalars [temporary option]", | ||
describe: "Use the names of custom scalars as their type name [temporary option]", | ||
default: false | ||
@@ -145,3 +149,3 @@ }, | ||
demand: false, | ||
describe: "Use Flow exact objects for generated types [flow-modern only]", | ||
describe: "Use Flow exact objects for generated types [flow only]", | ||
default: false, | ||
@@ -152,3 +156,3 @@ type: 'boolean' | ||
demand: false, | ||
describe: "Use Flow read only types for generated types [flow-modern only]", | ||
describe: "Use Flow read only types for generated types [flow only]", | ||
default: false, | ||
@@ -197,3 +201,3 @@ type: 'boolean' | ||
}; | ||
_1.generate(inputPaths, argv.schema, argv.output, argv.only, argv.target, argv.tagName, argv.projectName, options); | ||
generate_1.default(inputPaths, argv.schema, argv.output, argv.only, argv.target, argv.tagName, argv.projectName, options); | ||
}) | ||
@@ -200,0 +204,0 @@ .fail(function (message, error) { |
@@ -15,3 +15,3 @@ "use strict"; | ||
const utilities_1 = require("graphql/utilities"); | ||
const errors_1 = require("./errors"); | ||
const errors_1 = require("apollo-codegen-core/lib/errors"); | ||
const defaultHeaders = { | ||
@@ -18,0 +18,0 @@ 'Accept': 'application/json', |
@@ -6,13 +6,13 @@ "use strict"; | ||
const rimraf = require("rimraf"); | ||
const loading_1 = require("./loading"); | ||
const loading_1 = require("apollo-codegen-core/lib/loading"); | ||
const validation_1 = require("./validation"); | ||
const compiler_1 = require("./compiler"); | ||
const legacyIR_1 = require("./compiler/legacyIR"); | ||
const serializeToJSON_1 = require("./serializeToJSON"); | ||
const swift_1 = require("./swift"); | ||
const typescript_1 = require("./typescript"); | ||
const flow_1 = require("./flow"); | ||
const flow_2 = require("./javascript/flow"); | ||
const typescript_2 = require("./javascript/typescript"); | ||
const scala_1 = require("./scala"); | ||
const compiler_1 = require("apollo-codegen-core/lib/compiler"); | ||
const legacyIR_1 = require("apollo-codegen-core/lib/compiler/legacyIR"); | ||
const serializeToJSON_1 = require("apollo-codegen-core/lib/serializeToJSON"); | ||
const apollo_codegen_swift_1 = require("apollo-codegen-swift"); | ||
const apollo_codegen_typescript_legacy_1 = require("apollo-codegen-typescript-legacy"); | ||
const apollo_codegen_flow_legacy_1 = require("apollo-codegen-flow-legacy"); | ||
const apollo_codegen_flow_1 = require("apollo-codegen-flow"); | ||
const apollo_codegen_typescript_1 = require("apollo-codegen-typescript"); | ||
const apollo_codegen_scala_1 = require("apollo-codegen-scala"); | ||
function generate(inputPaths, schemaPath, outputPath, only, target, tagName, projectName, options) { | ||
@@ -28,3 +28,3 @@ const schema = schemaPath == null | ||
const outputIndividualFiles = fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory(); | ||
const generator = swift_1.generateSource(context, outputIndividualFiles, only); | ||
const generator = apollo_codegen_swift_1.generateSource(context, outputIndividualFiles, only); | ||
if (outputIndividualFiles) { | ||
@@ -40,24 +40,21 @@ writeGeneratedFiles(generator.generatedFiles, outputPath); | ||
} | ||
else if (target === 'flow-modern' || target === 'typescript-modern' || target === 'ts-modern') { | ||
else if (target === 'flow' || target === 'typescript' || target === 'ts') { | ||
const context = compiler_1.compileToIR(schema, document, options); | ||
const generatedFiles = target === 'flow-modern' | ||
? flow_2.generateSource(context) | ||
: typescript_2.generateSource(context); | ||
const filesByOutputDirectory = {}; | ||
Object.keys(generatedFiles) | ||
.forEach((filePath) => { | ||
const outputDirectory = path.dirname(filePath); | ||
if (!filesByOutputDirectory[outputDirectory]) { | ||
filesByOutputDirectory[outputDirectory] = { | ||
[path.basename(filePath)]: generatedFiles[filePath] | ||
const { generatedFiles, common } = target === 'flow' | ||
? apollo_codegen_flow_1.generateSource(context) | ||
: apollo_codegen_typescript_1.generateSource(context); | ||
const outFiles = {}; | ||
const outputIndividualFiles = fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory(); | ||
if (outputIndividualFiles) { | ||
Object.keys(generatedFiles) | ||
.forEach((filePath) => { | ||
outFiles[path.basename(filePath)] = { | ||
output: generatedFiles[filePath].fileContents + common | ||
}; | ||
} | ||
else { | ||
filesByOutputDirectory[outputDirectory][path.basename(filePath)] = generatedFiles[filePath]; | ||
} | ||
}); | ||
Object.keys(filesByOutputDirectory) | ||
.forEach((outputDirectory) => { | ||
writeGeneratedFiles(filesByOutputDirectory[outputDirectory], outputDirectory); | ||
}); | ||
}); | ||
writeGeneratedFiles(outFiles, outputPath); | ||
} | ||
else { | ||
fs.writeFileSync(outputPath, Object.values(generatedFiles).map(v => v.fileContents).join("\n") + common); | ||
} | ||
} | ||
@@ -71,11 +68,11 @@ else { | ||
break; | ||
case 'ts': | ||
case 'typescript': | ||
output = typescript_1.generateSource(context); | ||
case 'ts-legacy': | ||
case 'typescript-legacy': | ||
output = apollo_codegen_typescript_legacy_1.generateSource(context); | ||
break; | ||
case 'flow': | ||
output = flow_1.generateSource(context); | ||
case 'flow-legacy': | ||
output = apollo_codegen_flow_legacy_1.generateSource(context); | ||
break; | ||
case 'scala': | ||
output = scala_1.generateSource(context, options); | ||
output = apollo_codegen_scala_1.generateSource(context); | ||
} | ||
@@ -82,0 +79,0 @@ if (outputPath) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./polyfills"); | ||
require("apollo-codegen-core/lib/polyfills"); | ||
var downloadSchema_1 = require("./downloadSchema"); | ||
@@ -5,0 +5,0 @@ exports.downloadSchema = downloadSchema_1.default; |
@@ -14,3 +14,3 @@ "use strict"; | ||
const utilities_1 = require("graphql/utilities"); | ||
const errors_1 = require("./errors"); | ||
const errors_1 = require("apollo-codegen-core/lib/errors"); | ||
function introspect(schemaContents) { | ||
@@ -17,0 +17,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -13,3 +13,3 @@ "use strict"; | ||
const graphql_1 = require("graphql"); | ||
const errors_1 = require("./errors"); | ||
const errors_1 = require("apollo-codegen-core/lib/errors"); | ||
function printSchemaFromIntrospectionResult(schemaPath, outputPath, options) { | ||
@@ -16,0 +16,0 @@ return __awaiter(this, void 0, void 0, function* () { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graphql_1 = require("graphql"); | ||
const errors_1 = require("./errors"); | ||
const errors_1 = require("apollo-codegen-core/lib/errors"); | ||
function validateQueryDocument(schema, document) { | ||
@@ -6,0 +6,0 @@ const specifiedRulesToBeRemoved = [graphql_1.NoUnusedFragmentsRule, graphql_1.KnownDirectivesRule]; |
{ | ||
"name": "apollo-codegen", | ||
"version": "0.19.1", | ||
"description": "Generate API code or type annotations based on a GraphQL schema and query documents", | ||
"version": "0.20.0-alpha.f3534c9a", | ||
"main": "./lib/index.js", | ||
@@ -9,7 +9,7 @@ "bin": "./lib/cli.js", | ||
"clean": "rm -rf lib", | ||
"compile": "tsc", | ||
"prebuild": "npm run clean", | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"prepare": "npm run clean && npm run compile", | ||
"test": "./node_modules/.bin/jest", | ||
"test:smoke": "npm install && npm run compile && rm -rf node_modules && npm install --prod && node ./lib/cli.js && echo 'Smoke Test Passed'" | ||
"test:smoke": "npm run build && node ./lib/cli.js && echo 'Smoke Test Passed'" | ||
}, | ||
@@ -27,9 +27,4 @@ "repository": { | ||
"devDependencies": { | ||
"@types/babel-generator": "^6.25.1", | ||
"@types/babel-types": "^7.0.0", | ||
"@types/babylon": "^6.16.2", | ||
"@types/common-tags": "^1.4.0", | ||
"@types/glob": "^5.0.34", | ||
"@types/graphql": "^0.12.4", | ||
"@types/inflected": "^1.1.29", | ||
"@types/jest": "^21.1.8", | ||
@@ -39,5 +34,5 @@ "@types/node-fetch": "^1.6.7", | ||
"@types/yargs": "^10.0.0", | ||
"ansi-regex": "^3.0.0", | ||
"jest": "^22.0.3", | ||
"jest-matcher-utils": "^22.0.3", | ||
"lerna": "^2.11.0", | ||
"ts-jest": "^22.0.0", | ||
@@ -47,11 +42,11 @@ "typescript": "^2.6.2" | ||
"dependencies": { | ||
"@babel/generator": "7.0.0-beta.38", | ||
"@babel/types": "7.0.0-beta.38", | ||
"change-case": "^3.0.1", | ||
"common-tags": "^1.5.1", | ||
"core-js": "^2.5.3", | ||
"apollo-codegen-core": "^0.20.0-alpha.f3534c9a", | ||
"apollo-codegen-flow": "^0.20.0-alpha.f3534c9a", | ||
"apollo-codegen-flow-legacy": "^0.20.0-alpha.f3534c9a", | ||
"apollo-codegen-scala": "^0.20.0-alpha.f3534c9a", | ||
"apollo-codegen-swift": "^0.20.0-alpha.f3534c9a", | ||
"apollo-codegen-typescript": "^0.20.0-alpha.f3534c9a", | ||
"apollo-codegen-typescript-legacy": "^0.20.0-alpha.f3534c9a", | ||
"glob": "^7.1.2", | ||
"graphql": "^0.13.1", | ||
"graphql-config": "^1.1.1", | ||
"inflected": "^2.0.3", | ||
"node-fetch": "^1.7.3", | ||
@@ -64,11 +59,8 @@ "rimraf": "^2.6.2", | ||
"testEnvironment": "node", | ||
"setupFiles": [ | ||
"<rootDir>/src/polyfills.js" | ||
], | ||
"setupTestFrameworkScriptFile": "<rootDir>/test/test-utils/matchers.ts", | ||
"testMatch": [ | ||
"**/test/**/*.(js|ts)", | ||
"**/test/*.(js|ts)", | ||
"**/__tests__/*.(js|ts)" | ||
], | ||
"setupFiles": [ | ||
"<rootDir>/../apollo-codegen-core/src/polyfills.ts" | ||
], | ||
"testPathIgnorePatterns": [ | ||
@@ -81,3 +73,3 @@ "<rootDir>/node_modules/", | ||
"transform": { | ||
"^.+\\.(ts|js)x?$": "<rootDir>/node_modules/ts-jest/preprocessor.js" | ||
"^.+\\.(ts|js)x?$": "<rootDir>../../node_modules/ts-jest/preprocessor.js" | ||
}, | ||
@@ -84,0 +76,0 @@ "moduleFileExtensions": [ |
@@ -11,3 +11,3 @@ // Based on https://facebook.github.io/relay/docs/guides-babel-plugin.html#using-other-graphql-implementations | ||
import { ToolError } from './errors' | ||
import { ToolError } from 'apollo-codegen-core/lib/errors' | ||
@@ -14,0 +14,0 @@ const defaultHeaders = { |
@@ -5,19 +5,20 @@ import * as fs from 'fs'; | ||
import { loadSchema, loadSchemaFromConfig, loadAndMergeQueryDocuments } from './loading'; | ||
import { loadSchema, loadSchemaFromConfig, loadAndMergeQueryDocuments } from 'apollo-codegen-core/lib/loading'; | ||
import { validateQueryDocument } from './validation'; | ||
import { compileToIR } from './compiler'; | ||
import { compileToLegacyIR } from './compiler/legacyIR'; | ||
import serializeToJSON from './serializeToJSON'; | ||
import { BasicGeneratedFile } from './utilities/CodeGenerator' | ||
import { generateSource as generateSwiftSource } from './swift'; | ||
import { generateSource as generateTypescriptSource } from './typescript'; | ||
import { generateSource as generateFlowSource } from './flow'; | ||
import { generateSource as generateFlowModernSource } from './javascript/flow'; | ||
import { generateSource as generateTypescriptModernSource } from './javascript/typescript'; | ||
import { generateSource as generateScalaSource } from './scala'; | ||
import { compileToIR } from 'apollo-codegen-core/lib/compiler'; | ||
import { compileToLegacyIR } from 'apollo-codegen-core/lib/compiler/legacyIR'; | ||
import serializeToJSON from 'apollo-codegen-core/lib/serializeToJSON'; | ||
import { BasicGeneratedFile } from 'apollo-codegen-core/lib/utilities/CodeGenerator' | ||
type TargetType = 'json' | 'swift' | 'ts' | 'typescript' | ||
| 'flow' | 'scala' | 'flow-modern' | 'typescript-modern' | ||
| 'ts-modern'; | ||
import { generateSource as generateSwiftSource } from 'apollo-codegen-swift'; | ||
import { generateSource as generateTypescriptLegacySource } from 'apollo-codegen-typescript-legacy'; | ||
import { generateSource as generateFlowLegacySource } from 'apollo-codegen-flow-legacy'; | ||
import { generateSource as generateFlowSource } from 'apollo-codegen-flow'; | ||
import { generateSource as generateTypescriptSource } from 'apollo-codegen-typescript'; | ||
import { generateSource as generateScalaSource } from 'apollo-codegen-scala'; | ||
type TargetType = 'json' | 'swift' | 'ts-legacy' | 'typescript-legacy' | ||
| 'flow-legacy' | 'scala' | 'flow' | 'typescript' | ||
| 'ts'; | ||
export default function generate( | ||
@@ -59,34 +60,32 @@ inputPaths: string[], | ||
} | ||
else if (target === 'flow-modern' || target === 'typescript-modern' || target === 'ts-modern') { | ||
else if (target === 'flow' || target === 'typescript' || target === 'ts') { | ||
const context = compileToIR(schema, document, options); | ||
const generatedFiles = target === 'flow-modern' | ||
? generateFlowModernSource(context) | ||
: generateTypescriptModernSource(context) ; | ||
const { generatedFiles, common } = target === 'flow' | ||
? generateFlowSource(context) | ||
: generateTypescriptSource(context) ; | ||
// Group by output directory | ||
const filesByOutputDirectory: { | ||
[outputDirectory: string]: { | ||
[fileName: string]: BasicGeneratedFile | ||
} | ||
const outFiles: { | ||
[fileName: string]: BasicGeneratedFile | ||
} = {}; | ||
Object.keys(generatedFiles) | ||
.forEach((filePath: string) => { | ||
const outputDirectory = path.dirname(filePath); | ||
if (!filesByOutputDirectory[outputDirectory]) { | ||
filesByOutputDirectory[outputDirectory] = { | ||
[path.basename(filePath)]: generatedFiles[filePath] | ||
}; | ||
} else { | ||
filesByOutputDirectory[outputDirectory][path.basename(filePath)] = generatedFiles[filePath]; | ||
} | ||
}) | ||
const outputIndividualFiles = fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory(); | ||
Object.keys(filesByOutputDirectory) | ||
.forEach((outputDirectory) => { | ||
writeGeneratedFiles( | ||
filesByOutputDirectory[outputDirectory], | ||
outputDirectory | ||
); | ||
}); | ||
if (outputIndividualFiles) { | ||
Object.keys(generatedFiles) | ||
.forEach((filePath: string) => { | ||
outFiles[path.basename(filePath)] = { | ||
output: generatedFiles[filePath].fileContents + common | ||
} | ||
}); | ||
writeGeneratedFiles( | ||
outFiles, | ||
outputPath | ||
); | ||
} else { | ||
fs.writeFileSync( | ||
outputPath, | ||
Object.values(generatedFiles).map(v => v.fileContents).join("\n") + common | ||
); | ||
} | ||
} | ||
@@ -100,11 +99,11 @@ else { | ||
break; | ||
case 'ts': | ||
case 'typescript': | ||
output = generateTypescriptSource(context); | ||
case 'ts-legacy': | ||
case 'typescript-legacy': | ||
output = generateTypescriptLegacySource(context); | ||
break; | ||
case 'flow': | ||
output = generateFlowSource(context); | ||
case 'flow-legacy': | ||
output = generateFlowLegacySource(context); | ||
break; | ||
case 'scala': | ||
output = generateScalaSource(context, options); | ||
output = generateScalaSource(context); | ||
} | ||
@@ -111,0 +110,0 @@ |
@@ -1,2 +0,2 @@ | ||
import './polyfills'; | ||
import 'apollo-codegen-core/lib/polyfills'; | ||
@@ -3,0 +3,0 @@ export { default as downloadSchema } from './downloadSchema'; |
import * as fs from 'fs'; | ||
import { buildASTSchema, graphql, parse } from 'graphql'; | ||
import { buildASTSchema, graphql, parse, DocumentNode, GraphQLSchema } from 'graphql'; | ||
import { introspectionQuery } from 'graphql/utilities'; | ||
import { ToolError } from './errors' | ||
import { ToolError } from 'apollo-codegen-core/lib/errors' | ||
declare module "graphql/utilities/buildASTSchema" { | ||
function buildASTSchema( | ||
ast: DocumentNode, | ||
options?: { assumeValid?: boolean, commentDescriptions?: boolean }, | ||
): GraphQLSchema; | ||
} | ||
export async function introspect(schemaContents: string) { | ||
@@ -9,0 +16,0 @@ const schema = buildASTSchema(parse(schemaContents), { commentDescriptions: true }); |
@@ -5,3 +5,3 @@ import * as fs from 'fs'; | ||
import { ToolError } from './errors' | ||
import { ToolError } from 'apollo-codegen-core/lib/errors' | ||
import { PrinterOptions } from 'graphql/utilities/schemaPrinter'; | ||
@@ -8,0 +8,0 @@ |
@@ -14,3 +14,3 @@ import { | ||
import { ToolError, logError } from './errors'; | ||
import { ToolError, logError } from 'apollo-codegen-core/lib/errors'; | ||
@@ -17,0 +17,0 @@ export function validateQueryDocument(schema: GraphQLSchema, document: DocumentNode) { |
{ | ||
"extends": "../../tsconfig.base", | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "lib", | ||
"lib": ["es2017", "esnext.asynciterable", "dom"], | ||
"removeComments": true, | ||
"strict": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedParameters": true, | ||
"noUnusedLocals": true, | ||
"allowJs": true, | ||
"allowUnreachableCode": true | ||
"outDir": "lib" | ||
}, | ||
"include" : [ | ||
"src/**/*" | ||
] | ||
"include" : [ "src/**/*" ], | ||
"exclude": [ "**/__tests__/*" ] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
11
0
4
55203
29
1002
1
0
3
+ Addedapollo-codegen-typescript-legacy@^0.20.0-alpha.f3534c9a
+ Addedapollo-codegen-core@0.20.1(transitive)
+ Addedapollo-codegen-flow@0.20.0(transitive)
+ Addedapollo-codegen-flow-legacy@0.20.0(transitive)
+ Addedapollo-codegen-scala@0.20.0(transitive)
+ Addedapollo-codegen-swift@0.20.0(transitive)
+ Addedapollo-codegen-typescript@0.20.0(transitive)
+ Addedapollo-codegen-typescript-legacy@0.20.0(transitive)
+ Addedgraphql-config@2.2.2(transitive)
+ Addedgraphql-import@0.7.1(transitive)
+ Addedresolve-from@4.0.0(transitive)
- Removed@babel/generator@7.0.0-beta.38
- Removed@babel/types@7.0.0-beta.38
- Removedchange-case@^3.0.1
- Removedcommon-tags@^1.5.1
- Removedcore-js@^2.5.3
- Removedgraphql-config@^1.1.1
- Removedinflected@^2.0.3
- Removedgraphql@0.12.3(transitive)
- Removedgraphql-config@1.2.1(transitive)
- Removedgraphql-import@0.4.5(transitive)
- Removediterall@1.1.3(transitive)