@graphql-codegen/java-apollo-android 2.3.0-alpha-a52c122aa.0 → 2.3.0-alpha-29eb1293b.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 (40) hide show
  1. package/cjs/base-java-visitor.js +114 -0
  2. package/cjs/custom-type-class.js +69 -0
  3. package/cjs/field-arguments.js +36 -0
  4. package/cjs/file-type.js +10 -0
  5. package/cjs/imports.js +45 -0
  6. package/cjs/index.js +5 -0
  7. package/cjs/input-type-visitor.js +187 -0
  8. package/cjs/operation-visitor.js +780 -0
  9. package/cjs/package.json +1 -0
  10. package/cjs/plugin.js +48 -0
  11. package/cjs/preset.js +95 -0
  12. package/cjs/types.js +2 -0
  13. package/cjs/visitor-config.js +2 -0
  14. package/esm/base-java-visitor.js +110 -0
  15. package/esm/custom-type-class.js +65 -0
  16. package/esm/field-arguments.js +32 -0
  17. package/esm/file-type.js +7 -0
  18. package/esm/imports.js +42 -0
  19. package/esm/index.js +2 -0
  20. package/esm/input-type-visitor.js +183 -0
  21. package/{index.mjs → esm/operation-visitor.js} +38 -620
  22. package/esm/plugin.js +44 -0
  23. package/esm/preset.js +92 -0
  24. package/esm/types.js +1 -0
  25. package/esm/visitor-config.js +1 -0
  26. package/package.json +24 -17
  27. package/{base-java-visitor.d.ts → typings/base-java-visitor.d.ts} +3 -3
  28. package/{custom-type-class.d.ts → typings/custom-type-class.d.ts} +3 -3
  29. package/{field-arguments.d.ts → typings/field-arguments.d.ts} +1 -1
  30. package/{file-type.d.ts → typings/file-type.d.ts} +0 -0
  31. package/{imports.d.ts → typings/imports.d.ts} +0 -0
  32. package/typings/index.d.ts +2 -0
  33. package/{input-type-visitor.d.ts → typings/input-type-visitor.d.ts} +3 -3
  34. package/{operation-visitor.d.ts → typings/operation-visitor.d.ts} +3 -3
  35. package/{plugin.d.ts → typings/plugin.d.ts} +4 -4
  36. package/{preset.d.ts → typings/preset.d.ts} +0 -0
  37. package/{types.d.ts → typings/types.d.ts} +0 -0
  38. package/{visitor-config.d.ts → typings/visitor-config.d.ts} +0 -0
  39. package/index.d.ts +0 -2
  40. package/index.js +0 -1364
package/esm/plugin.js ADDED
@@ -0,0 +1,44 @@
1
+ import { oldVisit } from '@graphql-codegen/plugin-helpers';
2
+ import { concatAST, Kind } from 'graphql';
3
+ import { InputTypeVisitor } from './input-type-visitor.js';
4
+ import { OperationVisitor } from './operation-visitor.js';
5
+ import { FileType } from './file-type.js';
6
+ import { CustomTypeClassVisitor } from './custom-type-class.js';
7
+ export const plugin = (schema, documents, config) => {
8
+ const allAst = concatAST(documents.map(v => v.document));
9
+ const allFragments = [
10
+ ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
11
+ node: fragmentDef,
12
+ name: fragmentDef.name.value,
13
+ onType: fragmentDef.typeCondition.name.value,
14
+ isExternal: false,
15
+ })),
16
+ ...(config.externalFragments || []),
17
+ ];
18
+ let visitor;
19
+ switch (config.fileType) {
20
+ case FileType.FRAGMENT:
21
+ case FileType.OPERATION: {
22
+ visitor = new OperationVisitor(schema, config, allFragments);
23
+ break;
24
+ }
25
+ case FileType.INPUT_TYPE: {
26
+ visitor = new InputTypeVisitor(schema, config);
27
+ break;
28
+ }
29
+ case FileType.CUSTOM_TYPES: {
30
+ visitor = new CustomTypeClassVisitor(schema, config);
31
+ break;
32
+ }
33
+ }
34
+ if (!visitor) {
35
+ return { content: '' };
36
+ }
37
+ const visitResult = oldVisit(allAst, visitor);
38
+ const additionalContent = visitor.additionalContent();
39
+ const imports = visitor.getImports();
40
+ return {
41
+ prepend: [`package ${visitor.getPackage()};\n`, ...imports],
42
+ content: '\n' + [...visitResult.definitions.filter(a => a && typeof a === 'string'), additionalContent].join('\n'),
43
+ };
44
+ };
package/esm/preset.js ADDED
@@ -0,0 +1,92 @@
1
+ import { visit, concatAST, Kind, } from 'graphql';
2
+ import { join } from 'path';
3
+ import { FileType } from './file-type.js';
4
+ import { pascalCase } from 'change-case-all';
5
+ const packageNameToDirectory = (packageName) => {
6
+ return `./${packageName.split('.').join('/')}/`;
7
+ };
8
+ export const preset = {
9
+ buildGeneratesSection: options => {
10
+ const outDir = options.baseOutputDir;
11
+ const inputTypesAst = [];
12
+ visit(options.schema, {
13
+ InputObjectTypeDefinition: {
14
+ enter(node) {
15
+ inputTypesAst.push(node);
16
+ },
17
+ },
18
+ });
19
+ const inputTypesDocumentNode = { kind: Kind.DOCUMENT, definitions: inputTypesAst };
20
+ const allAst = concatAST(options.documents.map(v => v.document));
21
+ const operationsAst = allAst.definitions.filter(d => d.kind === Kind.OPERATION_DEFINITION);
22
+ const fragments = allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION);
23
+ const externalFragments = fragments.map(frag => ({
24
+ isExternal: true,
25
+ importFrom: frag.name.value,
26
+ name: frag.name.value,
27
+ onType: frag.typeCondition.name.value,
28
+ node: frag,
29
+ }));
30
+ return [
31
+ {
32
+ filename: join(outDir, packageNameToDirectory(options.config.typePackage), 'CustomType.java'),
33
+ plugins: options.plugins,
34
+ pluginMap: options.pluginMap,
35
+ config: {
36
+ ...options.config,
37
+ fileType: FileType.CUSTOM_TYPES,
38
+ },
39
+ schema: options.schema,
40
+ documents: [],
41
+ },
42
+ ...inputTypesDocumentNode.definitions.map((ast) => {
43
+ const document = { kind: Kind.DOCUMENT, definitions: [ast] };
44
+ return {
45
+ filename: join(outDir, packageNameToDirectory(options.config.typePackage), ast.name.value + '.java'),
46
+ plugins: options.plugins,
47
+ pluginMap: options.pluginMap,
48
+ config: {
49
+ ...options.config,
50
+ fileType: FileType.INPUT_TYPE,
51
+ skipDocumentsValidation: true,
52
+ },
53
+ schema: options.schema,
54
+ documents: [{ document, location: '' }],
55
+ };
56
+ }),
57
+ ...operationsAst.map((ast) => {
58
+ const fileName = ast.name.value.toLowerCase().endsWith(ast.operation)
59
+ ? ast.name.value
60
+ : `${ast.name.value}${pascalCase(ast.operation)}`;
61
+ const document = { kind: Kind.DOCUMENT, definitions: [ast] };
62
+ return {
63
+ filename: join(outDir, packageNameToDirectory(options.config.package), fileName + '.java'),
64
+ plugins: options.plugins,
65
+ pluginMap: options.pluginMap,
66
+ config: {
67
+ ...options.config,
68
+ fileType: FileType.OPERATION,
69
+ externalFragments,
70
+ },
71
+ schema: options.schema,
72
+ documents: [{ document, location: '' }],
73
+ };
74
+ }),
75
+ ...fragments.map((ast) => {
76
+ const document = { kind: Kind.DOCUMENT, definitions: [ast] };
77
+ return {
78
+ filename: join(outDir, packageNameToDirectory(options.config.fragmentPackage), ast.name.value + '.java'),
79
+ plugins: options.plugins,
80
+ pluginMap: options.pluginMap,
81
+ config: {
82
+ ...options.config,
83
+ fileType: FileType.FRAGMENT,
84
+ externalFragments,
85
+ },
86
+ schema: options.schema,
87
+ documents: [{ document, location: '' }],
88
+ };
89
+ }),
90
+ ];
91
+ },
92
+ };
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@graphql-codegen/java-apollo-android",
3
- "version": "2.3.0-alpha-a52c122aa.0",
3
+ "version": "2.3.0-alpha-29eb1293b.0",
4
4
  "description": "GraphQL Code Generator plugin for generating Java classes for Apollo-Android",
5
5
  "peerDependencies": {
6
6
  "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 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-codegen/java-common": "2.1.11-alpha-a52c122aa.0",
10
- "@graphql-codegen/plugin-helpers": "2.5.0-alpha-a52c122aa.0",
11
- "@graphql-codegen/visitor-plugin-common": "2.6.1-alpha-a52c122aa.0",
9
+ "@graphql-codegen/java-common": "^2.2.0-alpha-29eb1293b.0",
10
+ "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-29eb1293b.0",
11
+ "@graphql-codegen/visitor-plugin-common": "2.11.0-alpha-29eb1293b.0",
12
12
  "auto-bind": "~4.0.0",
13
13
  "change-case-all": "1.0.14",
14
14
  "pluralize": "^8.0.0",
15
- "tslib": "~2.3.0"
15
+ "tslib": "~2.4.0"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
@@ -20,21 +20,28 @@
20
20
  "directory": "packages/plugins/java/apollo-android"
21
21
  },
22
22
  "license": "MIT",
23
- "main": "index.js",
24
- "module": "index.mjs",
25
- "typings": "index.d.ts",
23
+ "main": "cjs/index.js",
24
+ "module": "esm/index.js",
25
+ "typings": "typings/index.d.ts",
26
26
  "typescript": {
27
- "definition": "index.d.ts"
27
+ "definition": "typings/index.d.ts"
28
28
  },
29
+ "type": "module",
29
30
  "exports": {
30
- "./package.json": "./package.json",
31
31
  ".": {
32
- "require": "./index.js",
33
- "import": "./index.mjs"
32
+ "require": {
33
+ "types": "./typings/index.d.ts",
34
+ "default": "./cjs/index.js"
35
+ },
36
+ "import": {
37
+ "types": "./typings/index.d.ts",
38
+ "default": "./esm/index.js"
39
+ },
40
+ "default": {
41
+ "types": "./typings/index.d.ts",
42
+ "default": "./esm/index.js"
43
+ }
34
44
  },
35
- "./*": {
36
- "require": "./*.js",
37
- "import": "./*.mjs"
38
- }
45
+ "./package.json": "./package.json"
39
46
  }
40
- }
47
+ }
@@ -1,8 +1,8 @@
1
1
  import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
2
- import { JavaApolloAndroidPluginConfig } from './plugin';
2
+ import { JavaApolloAndroidPluginConfig } from './plugin.js';
3
3
  import { GraphQLSchema, GraphQLNamedType, GraphQLOutputType, TypeNode, GraphQLInterfaceType } from 'graphql';
4
- import { VisitorConfig } from './visitor-config';
5
- import { ImportsSet, TransformedType } from './types';
4
+ import { VisitorConfig } from './visitor-config.js';
5
+ import { ImportsSet, TransformedType } from './types.js';
6
6
  export declare const SCALAR_TO_WRITER_METHOD: {
7
7
  ID: string;
8
8
  String: string;
@@ -1,7 +1,7 @@
1
1
  import { GraphQLSchema } from 'graphql';
2
- import { BaseJavaVisitor } from './base-java-visitor';
3
- import { VisitorConfig } from './visitor-config';
4
- import { JavaApolloAndroidPluginConfig } from './plugin';
2
+ import { BaseJavaVisitor } from './base-java-visitor.js';
3
+ import { VisitorConfig } from './visitor-config.js';
4
+ import { JavaApolloAndroidPluginConfig } from './plugin.js';
5
5
  export declare class CustomTypeClassVisitor extends BaseJavaVisitor<VisitorConfig> {
6
6
  constructor(schema: GraphQLSchema, rawConfig: JavaApolloAndroidPluginConfig);
7
7
  private extract;
@@ -1,3 +1,3 @@
1
1
  import { FieldNode } from 'graphql';
2
- import { ImportsSet } from './types';
2
+ import { ImportsSet } from './types.js';
3
3
  export declare function visitFieldArguments(selection: FieldNode, imports: ImportsSet): string;
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ export * from './plugin.js';
2
+ export * from './preset.js';
@@ -1,7 +1,7 @@
1
- import { JavaApolloAndroidPluginConfig } from './plugin';
1
+ import { JavaApolloAndroidPluginConfig } from './plugin.js';
2
2
  import { InputObjectTypeDefinitionNode, GraphQLSchema, InputValueDefinitionNode, VariableDefinitionNode } from 'graphql';
3
- import { BaseJavaVisitor } from './base-java-visitor';
4
- import { VisitorConfig } from './visitor-config';
3
+ import { BaseJavaVisitor } from './base-java-visitor.js';
4
+ import { VisitorConfig } from './visitor-config.js';
5
5
  export declare class InputTypeVisitor extends BaseJavaVisitor<VisitorConfig> {
6
6
  constructor(_schema: GraphQLSchema, rawConfig: JavaApolloAndroidPluginConfig);
7
7
  getPackage(): string;
@@ -1,9 +1,9 @@
1
- import { BaseJavaVisitor } from './base-java-visitor';
1
+ import { BaseJavaVisitor } from './base-java-visitor.js';
2
2
  import { LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
3
3
  import { JavaDeclarationBlock } from '@graphql-codegen/java-common';
4
4
  import { GraphQLSchema, OperationDefinitionNode, GraphQLNamedType, SelectionNode, GraphQLOutputType, FragmentDefinitionNode } from 'graphql';
5
- import { JavaApolloAndroidPluginConfig } from './plugin';
6
- import { VisitorConfig } from './visitor-config';
5
+ import { JavaApolloAndroidPluginConfig } from './plugin.js';
6
+ import { VisitorConfig } from './visitor-config.js';
7
7
  export interface ChildField {
8
8
  type: GraphQLNamedType;
9
9
  rawType: GraphQLOutputType;
@@ -1,6 +1,6 @@
1
1
  import { PluginFunction, Types } from '@graphql-codegen/plugin-helpers';
2
2
  import { RawConfig } from '@graphql-codegen/visitor-plugin-common';
3
- import { FileType } from './file-type';
3
+ import { FileType } from './file-type.js';
4
4
  /**
5
5
  * @description This plugin and presets creates generated mappers and parsers for a complete type-safe GraphQL requests, for developers that uses Apollo Android runtime.
6
6
  */
@@ -9,7 +9,7 @@ export interface JavaApolloAndroidPluginConfig extends RawConfig {
9
9
  * @description Customize the Java package name for the generated operations. The default package name will be generated according to the output file path.
10
10
  *
11
11
  * @exampleMarkdown
12
- * ```yml
12
+ * ```yaml
13
13
  * generates:
14
14
  * ./app/src/main/java/:
15
15
  * preset: java-apollo-android
@@ -24,7 +24,7 @@ export interface JavaApolloAndroidPluginConfig extends RawConfig {
24
24
  * @description Customize the Java package name for the types generated based on input types.
25
25
  *
26
26
  * @exampleMarkdown
27
- * ```yml
27
+ * ```yaml
28
28
  * generates:
29
29
  * ./app/src/main/java/:
30
30
  * preset: java-apollo-android
@@ -39,7 +39,7 @@ export interface JavaApolloAndroidPluginConfig extends RawConfig {
39
39
  * @description Customize the Java package name for the fragments generated classes.
40
40
  *
41
41
  * @exampleMarkdown
42
- * ```yml
42
+ * ```yaml
43
43
  * generates:
44
44
  * ./app/src/main/java/:
45
45
  * preset: java-apollo-android
File without changes
File without changes
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './plugin';
2
- export * from './preset';