@khanacademy/graphql-flow 0.0.1
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.
- package/.babelrc +6 -0
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +10 -0
- package/.flowconfig +13 -0
- package/.github/actions/filter-files/action.yml +37 -0
- package/.github/actions/full-or-limited/action.yml +27 -0
- package/.github/actions/json-args/action.yml +32 -0
- package/.github/actions/setup/action.yml +28 -0
- package/.github/workflows/changeset-release.yml +80 -0
- package/.github/workflows/pr-checks.yml +64 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +14 -0
- package/Readme.md +172 -0
- package/build-copy-source.js +28 -0
- package/dist/enums.js +57 -0
- package/dist/enums.js.flow +69 -0
- package/dist/generateResponseType.js +267 -0
- package/dist/generateResponseType.js.flow +419 -0
- package/dist/generateVariablesType.js +132 -0
- package/dist/generateVariablesType.js.flow +153 -0
- package/dist/index.js +88 -0
- package/dist/index.js.flow +93 -0
- package/dist/jest-mock-graphql-tag.js +169 -0
- package/dist/jest-mock-graphql-tag.js.flow +191 -0
- package/dist/schemaFromIntrospectionData.js +69 -0
- package/dist/schemaFromIntrospectionData.js.flow +68 -0
- package/dist/types.js +1 -0
- package/dist/types.js.flow +54 -0
- package/dist/utils.js +53 -0
- package/dist/utils.js.flow +50 -0
- package/flow-typed/npm/@babel/types_vx.x.x.js +5317 -0
- package/flow-typed/npm/jest_v23.x.x.js +1155 -0
- package/flow-typed/overrides.js +435 -0
- package/package.json +41 -0
- package/src/__test__/example-schema.graphql +65 -0
- package/src/__test__/graphql-flow.test.js +364 -0
- package/src/__test__/jest-mock-graphql-tag.test.js +51 -0
- package/src/enums.js +69 -0
- package/src/generateResponseType.js +419 -0
- package/src/generateVariablesType.js +153 -0
- package/src/index.js +93 -0
- package/src/jest-mock-graphql-tag.js +191 -0
- package/src/schemaFromIntrospectionData.js +68 -0
- package/src/types.js +54 -0
- package/src/utils.js +50 -0
- package/tools/find-files-with-gql.js +40 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
FragmentDefinitionNode,
|
|
5
|
+
IntrospectionEnumType,
|
|
6
|
+
IntrospectionField,
|
|
7
|
+
IntrospectionInputObjectType,
|
|
8
|
+
IntrospectionInterfaceType,
|
|
9
|
+
IntrospectionObjectType,
|
|
10
|
+
IntrospectionUnionType,
|
|
11
|
+
SelectionNode,
|
|
12
|
+
} from 'graphql';
|
|
13
|
+
|
|
14
|
+
export type Selections = $ReadOnlyArray<SelectionNode>;
|
|
15
|
+
|
|
16
|
+
export type Options = {|
|
|
17
|
+
strictNullability?: boolean, // default true
|
|
18
|
+
readOnlyArray?: boolean, // default true
|
|
19
|
+
scalars?: Scalars,
|
|
20
|
+
|};
|
|
21
|
+
|
|
22
|
+
export type Schema = {
|
|
23
|
+
interfacesByName: {
|
|
24
|
+
[key: string]: IntrospectionInterfaceType & {
|
|
25
|
+
fieldsByName: {[key: string]: IntrospectionField},
|
|
26
|
+
possibleTypesByName: {[key: string]: boolean},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
inputObjectsByName: {
|
|
30
|
+
[key: string]: IntrospectionInputObjectType,
|
|
31
|
+
},
|
|
32
|
+
typesByName: {
|
|
33
|
+
[key: string]: IntrospectionObjectType & {
|
|
34
|
+
fieldsByName: {[key: string]: IntrospectionField},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
unionsByName: {
|
|
38
|
+
[key: string]: IntrospectionUnionType,
|
|
39
|
+
},
|
|
40
|
+
enumsByName: {
|
|
41
|
+
[key: string]: IntrospectionEnumType,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type Config = {
|
|
46
|
+
strictNullability: boolean,
|
|
47
|
+
readOnlyArray: boolean,
|
|
48
|
+
fragments: {[key: string]: FragmentDefinitionNode},
|
|
49
|
+
|
|
50
|
+
schema: Schema,
|
|
51
|
+
scalars: Scalars,
|
|
52
|
+
errors: Array<string>,
|
|
53
|
+
};
|
|
54
|
+
export type Scalars = {[key: string]: 'string' | 'number' | 'boolean'};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addCommentAsLineComments = addCommentAsLineComments;
|
|
7
|
+
exports.transferLeadingComments = exports.maybeAddDescriptionComment = exports.liftLeadingPropertyComments = void 0;
|
|
8
|
+
|
|
9
|
+
var babelTypes = _interopRequireWildcard(require("@babel/types"));
|
|
10
|
+
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
|
|
15
|
+
const liftLeadingPropertyComments = property => {
|
|
16
|
+
return transferLeadingComments(property.value, property);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.liftLeadingPropertyComments = liftLeadingPropertyComments;
|
|
20
|
+
|
|
21
|
+
const maybeAddDescriptionComment = (description, node) => {
|
|
22
|
+
if (description) {
|
|
23
|
+
addCommentAsLineComments(description, node);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return node;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.maybeAddDescriptionComment = maybeAddDescriptionComment;
|
|
30
|
+
|
|
31
|
+
function addCommentAsLineComments(description, res) {
|
|
32
|
+
var _res$leadingComments;
|
|
33
|
+
|
|
34
|
+
if ((_res$leadingComments = res.leadingComments) !== null && _res$leadingComments !== void 0 && _res$leadingComments.length) {
|
|
35
|
+
res.leadingComments[0].value += '\n\n---\n\n' + description;
|
|
36
|
+
} else {
|
|
37
|
+
babelTypes.addComment(res, 'leading', '* ' + description, false // this specifies that it's a block comment, not a line comment
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const transferLeadingComments = (source, dest) => {
|
|
43
|
+
var _source$leadingCommen;
|
|
44
|
+
|
|
45
|
+
if ((_source$leadingCommen = source.leadingComments) !== null && _source$leadingCommen !== void 0 && _source$leadingCommen.length) {
|
|
46
|
+
dest.leadingComments = [...(dest.leadingComments || []), ...source.leadingComments];
|
|
47
|
+
source.leadingComments = [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return dest;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.transferLeadingComments = transferLeadingComments;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import * as babelTypes from '@babel/types';
|
|
4
|
+
import {BabelNodeObjectTypeProperty} from '@babel/types';
|
|
5
|
+
|
|
6
|
+
export const liftLeadingPropertyComments = (
|
|
7
|
+
property: BabelNodeObjectTypeProperty,
|
|
8
|
+
): BabelNodeObjectTypeProperty => {
|
|
9
|
+
return transferLeadingComments(property.value, property);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const maybeAddDescriptionComment = <T: babelTypes.BabelNode>(
|
|
13
|
+
description: ?string,
|
|
14
|
+
node: T,
|
|
15
|
+
): T => {
|
|
16
|
+
if (description) {
|
|
17
|
+
addCommentAsLineComments(description, node);
|
|
18
|
+
}
|
|
19
|
+
return node;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function addCommentAsLineComments(
|
|
23
|
+
description: string,
|
|
24
|
+
res: babelTypes.BabelNode,
|
|
25
|
+
) {
|
|
26
|
+
if (res.leadingComments?.length) {
|
|
27
|
+
res.leadingComments[0].value += '\n\n---\n\n' + description;
|
|
28
|
+
} else {
|
|
29
|
+
babelTypes.addComment(
|
|
30
|
+
res,
|
|
31
|
+
'leading',
|
|
32
|
+
'* ' + description,
|
|
33
|
+
false, // this specifies that it's a block comment, not a line comment
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const transferLeadingComments = <T: babelTypes.BabelNode>(
|
|
39
|
+
source: babelTypes.BabelNode,
|
|
40
|
+
dest: T,
|
|
41
|
+
): T => {
|
|
42
|
+
if (source.leadingComments?.length) {
|
|
43
|
+
dest.leadingComments = [
|
|
44
|
+
...(dest.leadingComments || []),
|
|
45
|
+
...source.leadingComments,
|
|
46
|
+
];
|
|
47
|
+
source.leadingComments = [];
|
|
48
|
+
}
|
|
49
|
+
return dest;
|
|
50
|
+
};
|