Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotansimha/graphql-code-generator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: @graphql-codegen/cli@1.18.0
Choose a base ref
...
head repository: dotansimha/graphql-code-generator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: @graphql-codegen/cli@1.19.0
Choose a head ref

Commits on Oct 19, 2020

  1. Fixed decorators for non-nullable type-graphql array types (#4909)

    Co-authored-by: Borre <borre.mosch@cubonacci.com>
    borremosch and Borre authored Oct 19, 2020
    Copy the full SHA
    4f89d40 View commit details
  2. chore(release): update monorepo packages versions (#4934)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Oct 19, 2020
    Copy the full SHA
    2ddeed4 View commit details

Commits on Oct 20, 2020

  1. Copy the full SHA
    0244eb9 View commit details
  2. Copy the full SHA
    0560876 View commit details
  3. Copy the full SHA
    42b139b View commit details
  4. Copy the full SHA
    b51cfb8 View commit details
  5. Copy the full SHA
    6cee304 View commit details

Commits on Oct 21, 2020

  1. Copy the full SHA
    fd384c3 View commit details
  2. Copy the full SHA
    7d251c0 View commit details
  3. Copy the full SHA
    5cc22b4 View commit details
  4. Copy the full SHA
    5d146de View commit details
  5. Copy the full SHA
    67ac456 View commit details
  6. Copy the full SHA
    8396ed2 View commit details
  7. Copy the full SHA
    40d850c View commit details
  8. Add errors-only flag to graphql-codegen-cli (#4931)

    * Add errors-only flag to graphql-codegen-cli
    
    * Add changeset
    maurobalbi authored Oct 21, 2020
    Copy the full SHA
    857c603 View commit details

Commits on Oct 22, 2020

  1. Copy the full SHA
    7a2e024 View commit details
  2. Copy the full SHA
    5793d8b View commit details
  3. Copy the full SHA
    5e3236c View commit details

Commits on Oct 23, 2020

  1. Copy the full SHA
    cb3dfbd View commit details

Commits on Oct 25, 2020

  1. near-operation-file absolute types path (#4966)

    I was configurating graphql-codegen for a monorepo project and I needed an absolute types path, but the docs didn't specify anything about using absolute paths, for example, for node_modules reference, and I found while looking at the source code about this undocumented feature
    
    https://github.com/dotansimha/graphql-code-generator/blob/master/packages/presets/near-operation-file/src/index.ts#L148
    PabloSzx authored Oct 25, 2020
    Copy the full SHA
    fe95e84 View commit details
  2. Added new plugin for generating apollo-client v3 types helpers (#4973)

    * added new plugin for generating apollo-client v3 types helpers
    
    * added changeset
    
    * fixes
    
    * fixes, added docs to website
    
    * fixes
    dotansimha authored Oct 25, 2020
    Copy the full SHA
    8c2ae04 View commit details
  3. chore(release): update monorepo packages versions (#4957)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    github-actions[bot] and github-actions[bot] authored Oct 25, 2020
    Copy the full SHA
    9aae6d6 View commit details
Showing with 1,390 additions and 872 deletions.
  1. +10 −10 package.json
  2. +7 −0 packages/graphql-cli-codegen-plugin/CHANGELOG.md
  3. +2 −2 packages/graphql-cli-codegen-plugin/package.json
  4. +11 −0 packages/graphql-codegen-cli/CHANGELOG.md
  5. +3 −3 packages/graphql-codegen-cli/package.json
  6. +2 −2 packages/graphql-codegen-cli/src/codegen.ts
  7. +10 −0 packages/graphql-codegen-cli/src/config.ts
  8. +40 −0 packages/graphql-codegen-cli/src/utils/listr-renderer.ts
  9. +11 −0 packages/plugins/typescript/apollo-client-helpers/CHANGELOG.md
  10. +1 −0 packages/plugins/typescript/apollo-client-helpers/jest.config.js
  11. +42 −0 packages/plugins/typescript/apollo-client-helpers/package.json
  12. +16 −0 packages/plugins/typescript/apollo-client-helpers/src/config.ts
  13. +84 −0 packages/plugins/typescript/apollo-client-helpers/src/index.ts
  14. +30 −0 ...s/plugins/typescript/apollo-client-helpers/tests/__snapshots__/apollo-client-helpers.spec.ts.snap
  15. +19 −0 packages/plugins/typescript/apollo-client-helpers/tests/apollo-client-helpers.spec.ts
  16. +6 −0 packages/plugins/typescript/type-graphql/CHANGELOG.md
  17. +1 −1 packages/plugins/typescript/type-graphql/package.json
  18. +42 −13 packages/plugins/typescript/type-graphql/src/visitor.ts
  19. +226 −36 packages/plugins/typescript/type-graphql/tests/type-graphql.spec.ts
  20. +5 −0 packages/utils/config-schema/src/plugins.ts
  21. +1 −1 packages/utils/graphql-codegen-testing/package.json
  22. +6 −0 packages/utils/plugins-helpers/CHANGELOG.md
  23. +1 −1 packages/utils/plugins-helpers/package.json
  24. +4 −0 packages/utils/plugins-helpers/src/types.ts
  25. +3 −0 tsconfig.json
  26. +2 −1 website/docs/generated-config/near-operation-file.md
  27. +21 −0 website/docs/generated-config/typescript-apollo-client-helpers.md
  28. +18 −1 website/docs/generated-config/typescript-type-graphql.md
  29. +37 −32 website/docs/plugins/index.md
  30. +54 −0 website/docs/plugins/typescript-apollo-client-helpers.md
  31. +8 −7 website/package.json
  32. +1 −0 website/sidebars.js
  33. +15 −3 website/src/components/live-demo/examples.js
  34. +2 −1 website/src/components/live-demo/plugins.js
  35. +69 −1 website/static/config.schema.json
  36. +580 −757 yarn.lock
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@
]
},
"devDependencies": {
"@apollo/client": "3.2.4",
"@babel/preset-typescript": "7.12.0",
"@apollo/client": "3.2.5",
"@babel/preset-typescript": "7.12.1",
"@changesets/cli": "2.11.1",
"@graphql-tools/apollo-engine-loader": "6.2.4",
"@graphql-tools/code-file-loader": "6.2.4",
@@ -58,9 +58,9 @@
"@graphql-typed-document-node/core": "3.1.0",
"@types/common-tags": "1.8.0",
"@types/glob": "7.1.3",
"@types/jest": "26.0.14",
"@types/jest": "26.0.15",
"@types/mkdirp": "1.0.1",
"@types/node": "14.11.8",
"@types/node": "14.14.0",
"@types/react": "16.9.52",
"@types/request": "2.48.5",
"@typescript-eslint/eslint-plugin": "4.0.0",
@@ -75,13 +75,13 @@
"auto-bind": "4.0.0",
"bob-the-bundler": "1.1.0",
"eslint": "7.11.0",
"eslint-config-prettier": "6.13.0",
"eslint-config-prettier": "6.14.0",
"eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-react-hooks": "4.1.2",
"eslint-plugin-standard": "4.0.1",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-standard": "4.0.2",
"flow-bin": "0.136.0",
"flow-parser": "0.136.0",
"fs-extra": "9.0.1",
@@ -90,14 +90,14 @@
"graphql-tag": "2.11.0",
"husky": "4.3.0",
"java-ast": "0.3.0",
"jest": "26.5.3",
"jest": "26.6.0",
"jest-docblock": "26.0.0",
"jest-junit": "12.0.0",
"lint-staged": "10.4.0",
"lint-staged": "10.4.2",
"lodash": "4.17.20",
"npm": "6.14.8",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-dom": "17.0.1",
"rimraf": "3.0.2",
"stencil-apollo": "0.1.5",
"ts-jest": "26.4.1",
7 changes: 7 additions & 0 deletions packages/graphql-cli-codegen-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @graphql-cli/codegen

## 1.17.12

### Patch Changes

- Updated dependencies [857c603c]
- @graphql-codegen/cli@1.19.0

## 1.17.11

### Patch Changes
4 changes: 2 additions & 2 deletions packages/graphql-cli-codegen-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-cli/codegen",
"version": "1.17.11",
"version": "1.17.12",
"description": "GraphQL Code Generator's GraphQL CLI plugin. GraphQL Code Generator is a tool that generates code from your GraphQL schema and documents for your backend or frontend with flexible support for custom plugins and templates.",
"license": "MIT",
"keywords": [
@@ -26,7 +26,7 @@
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
},
"dependencies": {
"@graphql-codegen/cli": "1.18.0",
"@graphql-codegen/cli": "1.19.0",
"@graphql-cli/common": "4.1.0"
},
"main": "dist/index.cjs.js",
11 changes: 11 additions & 0 deletions packages/graphql-codegen-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @graphql-codegen/cli

## 1.19.0

### Minor Changes

- 857c603c: Adds the --errors-only flag to the cli to print errors only.

### Patch Changes

- Updated dependencies [857c603c]
- @graphql-codegen/plugin-helpers@1.18.0

## 1.18.0

### Minor Changes
6 changes: 3 additions & 3 deletions packages/graphql-codegen-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/cli",
"version": "1.18.0",
"version": "1.19.0",
"license": "MIT",
"bin": {
"gql-gen": "dist/bin.js",
@@ -42,7 +42,7 @@
"dependencies": {
"latest-version": "5.1.0",
"@graphql-codegen/core": "1.17.8",
"@graphql-codegen/plugin-helpers": "^1.17.9",
"@graphql-codegen/plugin-helpers": "^1.18.0",
"@graphql-tools/apollo-engine-loader": "^6",
"@graphql-tools/code-file-loader": "^6",
"@graphql-tools/git-loader": "^6",
@@ -83,7 +83,7 @@
"upper-case": "^2.0.1",
"valid-url": "^1.0.9",
"wrap-ansi": "^7.0.0",
"yargs": "^16.0.3"
"yargs": "^16.1.0"
},
"devDependencies": {
"@types/chokidar": "2.1.3",
4 changes: 2 additions & 2 deletions packages/graphql-codegen-cli/src/codegen.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import {
} from '@graphql-codegen/plugin-helpers';
import { codegen } from '@graphql-codegen/core';

import { Renderer } from './utils/listr-renderer';
import { Renderer, ErrorRenderer } from './utils/listr-renderer';
import { GraphQLError, GraphQLSchema, DocumentNode, parse } from 'graphql';
import { getPluginByName } from './plugins';
import { getPresetByName } from './presets';
@@ -72,7 +72,7 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
} else {
listr = new Listr({
...commonListrOptions,
renderer: config.silent ? 'silent' : Renderer,
renderer: config.silent ? 'silent' : config.errorsOnly ? ErrorRenderer : Renderer,
nonTTYRenderer: config.silent ? 'silent' : 'default',
collapse: true,
clearOutput: false,
10 changes: 10 additions & 0 deletions packages/graphql-codegen-cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ export type YamlCliFlags = {
overwrite: boolean;
project: string;
silent: boolean;
errorsOnly: boolean;
};

function generateSearchPlaces(moduleName: string) {
@@ -151,6 +152,11 @@ export function buildOptions() {
describe: 'Suppresses printing errors',
type: 'boolean' as const,
},
e: {
alias: 'errors-only',
describe: 'Only print errors',
type: 'boolean' as const,
},
p: {
alias: 'project',
describe: 'Name of a project in GraphQL Config',
@@ -191,6 +197,10 @@ export function updateContextWithCliFlags(context: CodegenContext, cliFlags: Yam
config.silent = cliFlags.silent;
}

if (cliFlags.errorsOnly === true) {
config.errorsOnly = cliFlags.errorsOnly;
}

if (cliFlags.project) {
context.useProject(cliFlags.project);
}
40 changes: 40 additions & 0 deletions packages/graphql-codegen-cli/src/utils/listr-renderer.ts
Original file line number Diff line number Diff line change
@@ -79,6 +79,46 @@ export class Renderer {
}
}

const render = tasks => {
for (const task of tasks) {
task.subscribe(
event => {
if (event.type === 'SUBTASKS') {
render(task.subtasks);
return;
}

if (event.type === 'DATA') {
logUpdate.emit(chalk.dim(`${event.data}`));
}
logUpdate.done();
},
err => {
logUpdate.emit(err);
logUpdate.done();
}
);
}
};

export class ErrorRenderer {
private tasks: any;

constructor(tasks, options) {
this.tasks = tasks;
}

render() {
render(this.tasks);
}

static get nonTTY() {
return true;
}

end() {}
}

class LogUpdate {
private stream = process.stdout;
// state
11 changes: 11 additions & 0 deletions packages/plugins/typescript/apollo-client-helpers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @graphql-codegen/typescript-apollo-client-helpers

## 1.0.0
### Major Changes

- 8c2ae046: 🚀🚀 NEW PLUGIN: Helpers for Apollo-Client v3 🚀🚀

### Patch Changes

- Updated dependencies [857c603c]
- @graphql-codegen/plugin-helpers@1.18.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../../../jest.project')({ dirname: __dirname });
42 changes: 42 additions & 0 deletions packages/plugins/typescript/apollo-client-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@graphql-codegen/typescript-apollo-client-helpers",
"version": "1.0.0",
"description": "GraphQL Code Generator plugin for generating TypeScript helpers for Apollo Client > 3",
"repository": {
"type": "git",
"url": "https://github.com/dotansimha/graphql-code-generator.git",
"directory": "packages/plugins/typescript/apollo-client-helpers"
},
"license": "MIT",
"scripts": {
"lint": "eslint **/*.ts",
"test": "jest --no-watchman --config ../../../../jest.config.js",
"prepack": "bob prepack"
},
"peerDependencies": {
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
},
"devDependencies": {
"@apollo/client": "3.2.5"
},
"dependencies": {
"change-case": "^4.1.1",
"@graphql-codegen/plugin-helpers": "^1.18.0",
"@graphql-codegen/visitor-plugin-common": "^1.17.13",
"auto-bind": "~4.0.0",
"tslib": "~2.0.1"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
},
"buildOptions": {
"input": "./src/index.ts"
},
"publishConfig": {
"directory": "dist",
"access": "public"
}
}
16 changes: 16 additions & 0 deletions packages/plugins/typescript/apollo-client-helpers/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type ApolloClientHelpersConfig = {
/**
* @name useTypeImports
* @type boolean
* @default false
* @description Will use `import type {}` rather than `import {}` when importing only types. This gives
* compatibility with TypeScript's "importsNotUsedAsValues": "error" option
*
* @example
* ```yml
* config:
* useTypeImports: true
* ```
*/
useTypeImports?: boolean;
};
84 changes: 84 additions & 0 deletions packages/plugins/typescript/apollo-client-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Types, PluginValidateFn, PluginFunction } from '@graphql-codegen/plugin-helpers';
import { GraphQLSchema, isInterfaceType, isObjectType } from 'graphql';
import { extname } from 'path';
import { ApolloClientHelpersConfig } from './config';

export const plugin: PluginFunction<ApolloClientHelpersConfig> = (
schema: GraphQLSchema,
documents: Types.DocumentFile[],
config: ApolloClientHelpersConfig
) => {
const results: Types.ComplexPluginOutput[] = [];

results.push(generateTypePoliciesSignature(schema, config));

return {
prepend: results.reduce((prev, r) => [...prev, ...(r.prepend || [])], []),
append: results.reduce((prev, r) => [...prev, ...(r.append || [])], []),
content: results.map(r => r.content).join('\n'),
};
};

function generateTypePoliciesSignature(
schema: GraphQLSchema,
config: ApolloClientHelpersConfig
): Types.ComplexPluginOutput {
const typeMap = schema.getTypeMap();
const perTypePolicies: string[] = [];
const typedTypePolicies = Object.keys(typeMap).reduce((prev, typeName) => {
const type = typeMap[typeName];

if (!typeName.startsWith('__') && (isObjectType(type) || isInterfaceType(type))) {
const fieldsNames = Object.keys(type.getFields()).filter(f => !f.startsWith('__'));
const keySpecifierVarName = `${typeName}KeySpecifier`;
const fieldPolicyVarName = `${typeName}FieldPolicy`;

perTypePolicies.push(
`export type ${keySpecifierVarName} = (${fieldsNames
.map(f => `'${f}'`)
.join(' | ')} | ${keySpecifierVarName})[];`
);

perTypePolicies.push(`export type ${fieldPolicyVarName} = {
${fieldsNames.map(fieldName => `\t${fieldName}?: FieldPolicy<any> | FieldReadFunction<any>`).join(',\n')}
};`);

return {
...prev,
[typeName]: `{
\t\tkeyFields?: false | ${keySpecifierVarName} | (() => undefined | ${keySpecifierVarName}),
\t\tqueryType?: true,
\t\tmutationType?: true,
\t\tsubscriptionType?: true,
\t\tfields?: ${fieldPolicyVarName},
\t}`,
};
}

return prev;
}, {} as Record<string, string>);

const rootContent = `export type TypedTypePolicies = TypePolicies & {${Object.keys(typedTypePolicies)
.map(typeName => `\n\t${typeName}?: ${typedTypePolicies[typeName]}`)
.join(',')}\n};`;

return {
prepend: [
`import ${
config.useTypeImports ? 'type ' : ''
}{ FieldPolicy, FieldReadFunction, TypePolicies } from '@apollo/client/cache';`,
],
content: [...perTypePolicies, rootContent].join('\n'),
};
}

export const validate: PluginValidateFn<ApolloClientHelpersConfig> = async (
schema: GraphQLSchema,
documents: Types.DocumentFile[],
config,
outputFile: string
) => {
if (extname(outputFile) !== '.ts' && extname(outputFile) !== '.tsx') {
throw new Error(`Plugin "typed-document-node" requires extension to be ".ts" or ".tsx"!`);
}
};
Loading