Skip to content

Commit 2559ca2

Browse files
Merge pull request #1 from JoshRobertson/upgrade-yarn
upgrade yarn to latest
2 parents 942ca5d + d310bf0 commit 2559ca2

File tree

14 files changed

+4159
-2639
lines changed

14 files changed

+4159
-2639
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
.yarn

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

dist/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ Object.defineProperty(exports, "validate", {
1010
return _validate.validate;
1111
}
1212
});
13-
1413
var _validate = require("./validate");
15-
1614
var _utils = require("./utils");
17-
1815
// A list of common schema types to be ignored
1916
const DEFAULT_IGNORED_SUFFIXES = ["__Directive", "__EnumValue", "__Field", "__InputValue", "__Schema", "__Type"];
17+
2018
/**
2119
* Filters out and returns GraphQL type names that match the required criteria
22-
*
20+
*
2321
* @param {ObjMap<GraphQLNamedType>} typesMap - A map of all the GraphQL types in the schema
2422
* @param {string[]} [ignoredSuffixes=[]] - List of type suffixes or names to ignore
2523
* @returns {string[]} An array of GraphQL type names
2624
*/
27-
2825
const filterIgnoredSuffixes = (typesMap, ignoredSuffixes = []) => {
2926
return Object.keys(typesMap).filter(typeName => {
3027
const type = typesMap[typeName];
@@ -33,54 +30,50 @@ const filterIgnoredSuffixes = (typesMap, ignoredSuffixes = []) => {
3330
});
3431
});
3532
};
33+
3634
/**
3735
* Generates interface properties from the passed type names
38-
*
36+
*
3937
* @param {string[]} typeNames - A map of all the GraphQL types in the schema
4038
* @param {string} globalTypesNamespace - Namespace from which shared types are imported
4139
* @returns {string} Interface properties as one string
4240
*/
43-
44-
4541
const generateInterfaceProperties = (typeNames, globalTypesNamespace) => {
4642
return typeNames.map(typeName => {
4743
return ` ${typeName}: ${globalTypesNamespace}${typeName};`;
4844
}).join("\n");
4945
};
46+
5047
/**
5148
* Determines the name of the exported interface
52-
*
49+
*
5350
* @param {string | undefined} intefaceName - Interface name override if specified by config
5451
* @returns {string} Interface name
5552
*/
56-
57-
5853
const getInterfaceName = intefaceName => {
5954
return intefaceName || "GraphQLObjectTypes";
6055
};
56+
6157
/**
6258
* Generates an export statement for the generated interface
63-
*
59+
*
6460
* @param {boolean | undefined} typeExport - Whether to use type exports or not, specified by config
6561
* @param {string} interfaceName - The interface name to export
6662
* @returns {string} export statement
6763
*/
68-
69-
7064
const generateExportStatement = (typeExport, interfaceName) => {
7165
const exportStatement = `export ${typeExport ? "type " : ""}`;
7266
return `${exportStatement}{ ${interfaceName} };`;
7367
};
68+
7469
/**
7570
* Plugin for generating a single interface containing all Object types defined in a schema
76-
*
71+
*
7772
* @param {GraphQLSchema} schema - GraphQL schema from which to generate code
7873
* @param documents - Not used
7974
* @param {Config} config - Configuration for this plugin
8075
* @returns {string} Generated interface
8176
*/
82-
83-
8477
const plugin = (schema, _documents, config) => {
8578
const {
8679
namespacedImportName,
@@ -89,12 +82,11 @@ const plugin = (schema, _documents, config) => {
8982
interfaceName: configInterfaceName
9083
} = config;
9184
const typesMap = schema.getTypeMap();
92-
const globalTypesNamespace = namespacedImportName ? `${namespacedImportName}.` : '';
85+
const globalTypesNamespace = namespacedImportName ? `${namespacedImportName}.` : "";
9386
const filteredTypes = filterIgnoredSuffixes(typesMap, ignoredSuffixes);
9487
const interfaceProperties = generateInterfaceProperties(filteredTypes, globalTypesNamespace);
9588
const interfaceName = getInterfaceName(configInterfaceName);
9689
const exportStatement = generateExportStatement(useTypeImports, interfaceName);
9790
return `\ninterface ${interfaceName} {\n${interfaceProperties}\n}\n\n${exportStatement}`;
9891
};
99-
10092
exports.plugin = plugin;

dist/utils.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/utils.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66
exports.isInputEnumScalarOrUnionType = void 0;
7-
87
var _graphql = require("graphql");
9-
108
/**
119
* Determines wether the passed GraphQL type is a input, enum, scalar or union
12-
*
10+
*
1311
* @param {GraphQLNamedType} type - GraphQL type to evaluate
14-
* @returns {boolean}
12+
* @returns {boolean}
1513
*/
1614
const isInputEnumScalarOrUnionType = type => {
1715
return (0, _graphql.isInputObjectType)(type) || (0, _graphql.isEnumType)(type) || (0, _graphql.isScalarType)(type) || (0, _graphql.isUnionType)(type);
1816
};
19-
2017
exports.isInputEnumScalarOrUnionType = isInputEnumScalarOrUnionType;

dist/validate.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/validate.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66
exports.validate = void 0;
7-
87
const validate = (_schema, _documents, config, _outputFile, _allPlugins) => {
98
if (!config.namespacedImportName) {
109
throw new Error('Plugin "@fullscript/graphql-codegen-object-types" requires the "@graphql-codegen/import-types" preset');
1110
}
1211
};
13-
1412
exports.validate = validate;

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fullscript/graphql-codegen-object-types",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "GraphQL Code Generator plugin for generating an interface with all object types from your schema",
55
"license": "MIT",
66
"scripts": {
@@ -10,7 +10,7 @@
1010
"build": "concurrently \"yarn:build:*\"",
1111
"prettier-diff": "prettier --check src",
1212
"prettier-format": "prettier --write src",
13-
"test": "yarn check --integrity && jest --maxWorkers=2",
13+
"test": "yarn && jest --maxWorkers=2",
1414
"watch:types": "yarn run build:types --watch",
1515
"watch:babel": "yarn run build:babel --watch",
1616
"watch": "concurrently \"yarn:watch:*\""
@@ -38,5 +38,6 @@
3838
"resolutions": {
3939
"graphql": "16.5.0"
4040
},
41-
"main": "dist/index.js"
41+
"main": "dist/index.js",
42+
"packageManager": "yarn@4.9.1"
4243
}

src/index.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,52 @@ const DEFAULT_IGNORED_SUFFIXES = [
1818

1919
/**
2020
* Filters out and returns GraphQL type names that match the required criteria
21-
*
21+
*
2222
* @param {ObjMap<GraphQLNamedType>} typesMap - A map of all the GraphQL types in the schema
2323
* @param {string[]} [ignoredSuffixes=[]] - List of type suffixes or names to ignore
2424
* @returns {string[]} An array of GraphQL type names
2525
*/
26-
const filterIgnoredSuffixes = (typesMap: ObjMap<GraphQLNamedType>, ignoredSuffixes: string[] = []) => {
27-
return Object.keys(typesMap).filter((typeName) => {
26+
const filterIgnoredSuffixes = (
27+
typesMap: ObjMap<GraphQLNamedType>,
28+
ignoredSuffixes: string[] = []
29+
) => {
30+
return Object.keys(typesMap).filter(typeName => {
2831
const type = typesMap[typeName];
2932

30-
return ![...DEFAULT_IGNORED_SUFFIXES, ...ignoredSuffixes].some((ignoredType) => {
33+
return ![...DEFAULT_IGNORED_SUFFIXES, ...ignoredSuffixes].some(ignoredType => {
3134
return typeName.endsWith(ignoredType) || isInputEnumScalarOrUnionType(type);
32-
})
33-
})
34-
}
35+
});
36+
});
37+
};
3538

3639
/**
3740
* Generates interface properties from the passed type names
38-
*
41+
*
3942
* @param {string[]} typeNames - A map of all the GraphQL types in the schema
4043
* @param {string} globalTypesNamespace - Namespace from which shared types are imported
4144
* @returns {string} Interface properties as one string
4245
*/
4346
const generateInterfaceProperties = (typeNames: string[], globalTypesNamespace: string) => {
44-
return typeNames.map((typeName) => {
45-
return ` ${typeName}: ${globalTypesNamespace}${typeName};`
46-
}).join("\n");
47+
return typeNames
48+
.map(typeName => {
49+
return ` ${typeName}: ${globalTypesNamespace}${typeName};`;
50+
})
51+
.join("\n");
4752
};
4853

4954
/**
5055
* Determines the name of the exported interface
51-
*
56+
*
5257
* @param {string | undefined} intefaceName - Interface name override if specified by config
5358
* @returns {string} Interface name
5459
*/
5560
const getInterfaceName = (intefaceName: string | undefined) => {
5661
return intefaceName || "GraphQLObjectTypes";
57-
}
62+
};
5863

5964
/**
6065
* Generates an export statement for the generated interface
61-
*
66+
*
6267
* @param {boolean | undefined} typeExport - Whether to use type exports or not, specified by config
6368
* @param {string} interfaceName - The interface name to export
6469
* @returns {string} export statement
@@ -70,17 +75,22 @@ const generateExportStatement = (typeExport: boolean | undefined, interfaceName:
7075

7176
/**
7277
* Plugin for generating a single interface containing all Object types defined in a schema
73-
*
78+
*
7479
* @param {GraphQLSchema} schema - GraphQL schema from which to generate code
7580
* @param documents - Not used
7681
* @param {Config} config - Configuration for this plugin
7782
* @returns {string} Generated interface
7883
*/
7984
const plugin: PluginFunction<Config, Types.PluginOutput> = (schema, _documents, config) => {
80-
const { namespacedImportName, ignoredSuffixes, useTypeImports, interfaceName: configInterfaceName } = config;
85+
const {
86+
namespacedImportName,
87+
ignoredSuffixes,
88+
useTypeImports,
89+
interfaceName: configInterfaceName,
90+
} = config;
8191
const typesMap = schema.getTypeMap();
8292

83-
const globalTypesNamespace = namespacedImportName ? `${namespacedImportName}.` : '';
93+
const globalTypesNamespace = namespacedImportName ? `${namespacedImportName}.` : "";
8494
const filteredTypes = filterIgnoredSuffixes(typesMap, ignoredSuffixes);
8595

8696
const interfaceProperties = generateInterfaceProperties(filteredTypes, globalTypesNamespace);
@@ -90,4 +100,4 @@ const plugin: PluginFunction<Config, Types.PluginOutput> = (schema, _documents,
90100
return `\ninterface ${interfaceName} {\n${interfaceProperties}\n}\n\n${exportStatement}`;
91101
};
92102

93-
export { plugin, validate };
103+
export { plugin, validate };

0 commit comments

Comments
 (0)