@graphql-codegen/plugin-helpers 2.2.0-alpha-a09853373.0 → 2.4.0-alpha-23d229715.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.
- package/helpers.d.ts +1 -1
- package/index.d.ts +2 -0
- package/index.js +73 -6
- package/index.mjs +69 -5
- package/oldVisit.d.ts +9 -0
- package/package.json +5 -4
- package/profiler.d.ts +28 -0
- package/types.d.ts +4 -1
- package/utils.d.ts +1 -1
package/helpers.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Types } from './types';
|
|
|
2
2
|
import { DocumentNode, GraphQLSchema, GraphQLOutputType } from 'graphql';
|
|
3
3
|
export declare function isOutputConfigArray(type: any): type is Types.OutputConfig[];
|
|
4
4
|
export declare function isConfiguredOutput(type: any): type is Types.ConfiguredOutput;
|
|
5
|
-
export declare function normalizeOutputParam(config: Types.OutputConfig | Types.ConfiguredOutput): Types.ConfiguredOutput;
|
|
5
|
+
export declare function normalizeOutputParam(config: Types.OutputConfig | Types.ConfiguredPlugin[] | Types.ConfiguredOutput): Types.ConfiguredOutput;
|
|
6
6
|
export declare function normalizeInstanceOrArray<T>(type: T | T[]): T[];
|
|
7
7
|
export declare function normalizeConfig(config: Types.OutputConfig | Types.OutputConfig[]): Types.ConfiguredPlugin[];
|
|
8
8
|
export declare function hasNullableTypeRecursively(type: GraphQLOutputType): boolean;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
const module$1 = require('module');
|
|
8
|
-
const process = require('process');
|
|
8
|
+
const process$1 = require('process');
|
|
9
9
|
const changeCaseAll = require('change-case-all');
|
|
10
10
|
const graphql = require('graphql');
|
|
11
11
|
const merge = _interopDefault(require('lodash/merge.js'));
|
|
@@ -28,7 +28,7 @@ function resolveExternalModuleAndFn(pointer) {
|
|
|
28
28
|
else {
|
|
29
29
|
// we have to use a path to a filename here (it does not need to exist.)
|
|
30
30
|
// https://github.com/dotansimha/graphql-code-generator/issues/6553
|
|
31
|
-
const cwdRequire = module$1.createRequire(process.cwd() + '/index.js');
|
|
31
|
+
const cwdRequire = module$1.createRequire(process$1.cwd() + '/index.js');
|
|
32
32
|
loadedModule = cwdRequire(moduleName);
|
|
33
33
|
if (!(functionName in loadedModule) && typeof loadedModule !== 'function') {
|
|
34
34
|
throw new Error(`${functionName} couldn't be found in module ${moduleName}!`);
|
|
@@ -216,15 +216,17 @@ function isUsingTypes(document, externalFragments, schema) {
|
|
|
216
216
|
}
|
|
217
217
|
},
|
|
218
218
|
},
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
VariableDefinition: {
|
|
220
|
+
enter: (node, key, parent, path, anscestors) => {
|
|
221
221
|
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
222
222
|
if (insideIgnoredFragment) {
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
225
|
foundFields++;
|
|
226
226
|
},
|
|
227
|
-
|
|
227
|
+
},
|
|
228
|
+
InputValueDefinition: {
|
|
229
|
+
enter: (node, key, parent, path, anscestors) => {
|
|
228
230
|
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
229
231
|
if (insideIgnoredFragment) {
|
|
230
232
|
return;
|
|
@@ -396,7 +398,7 @@ class ApolloFederation {
|
|
|
396
398
|
extractKeyOrRequiresFieldSet(directive) {
|
|
397
399
|
const arg = directive.arguments.find(arg => arg.name.value === 'fields');
|
|
398
400
|
const value = arg.value.value;
|
|
399
|
-
return
|
|
401
|
+
return oldVisit(graphql.parse(`{${value}}`), {
|
|
400
402
|
leave: {
|
|
401
403
|
SelectionSet(node) {
|
|
402
404
|
return node.selections.reduce((accum, field) => {
|
|
@@ -499,9 +501,73 @@ function isDetailedError(error) {
|
|
|
499
501
|
|
|
500
502
|
const getCachedDocumentNodeFromSchema = utils.memoize1(utils.getDocumentNodeFromSchema);
|
|
501
503
|
|
|
504
|
+
function oldVisit(root, { enter: enterVisitors, leave: leaveVisitors, ...newVisitor }) {
|
|
505
|
+
if (typeof enterVisitors === 'object') {
|
|
506
|
+
for (const key in enterVisitors) {
|
|
507
|
+
newVisitor[key] = newVisitor[key] || {};
|
|
508
|
+
newVisitor[key].enter = enterVisitors[key];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (typeof leaveVisitors === 'object') {
|
|
512
|
+
for (const key in leaveVisitors) {
|
|
513
|
+
newVisitor[key] = newVisitor[key] || {};
|
|
514
|
+
newVisitor[key].leave = leaveVisitors[key];
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return graphql.visit(root, newVisitor);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function createNoopProfiler() {
|
|
521
|
+
return {
|
|
522
|
+
run(fn) {
|
|
523
|
+
return Promise.resolve().then(() => fn());
|
|
524
|
+
},
|
|
525
|
+
collect() {
|
|
526
|
+
return [];
|
|
527
|
+
},
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function createProfiler() {
|
|
531
|
+
const events = [];
|
|
532
|
+
return {
|
|
533
|
+
collect() {
|
|
534
|
+
return events;
|
|
535
|
+
},
|
|
536
|
+
run(fn, name, cat) {
|
|
537
|
+
let startTime;
|
|
538
|
+
return Promise.resolve()
|
|
539
|
+
.then(() => {
|
|
540
|
+
startTime = process.hrtime();
|
|
541
|
+
})
|
|
542
|
+
.then(() => fn())
|
|
543
|
+
.then(value => {
|
|
544
|
+
const duration = process.hrtime(startTime);
|
|
545
|
+
// Trace Event Format documentation:
|
|
546
|
+
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
|
|
547
|
+
const event = {
|
|
548
|
+
name,
|
|
549
|
+
cat,
|
|
550
|
+
ph: 'X',
|
|
551
|
+
ts: hrtimeToMicroseconds(startTime),
|
|
552
|
+
pid: 1,
|
|
553
|
+
tid: 0,
|
|
554
|
+
dur: hrtimeToMicroseconds(duration),
|
|
555
|
+
};
|
|
556
|
+
events.push(event);
|
|
557
|
+
return value;
|
|
558
|
+
});
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function hrtimeToMicroseconds(hrtime) {
|
|
563
|
+
return (hrtime[0] * 1e9 + hrtime[1]) / 1000;
|
|
564
|
+
}
|
|
565
|
+
|
|
502
566
|
exports.ApolloFederation = ApolloFederation;
|
|
503
567
|
exports.DetailedError = DetailedError;
|
|
504
568
|
exports.addFederationReferencesToSchema = addFederationReferencesToSchema;
|
|
569
|
+
exports.createNoopProfiler = createNoopProfiler;
|
|
570
|
+
exports.createProfiler = createProfiler;
|
|
505
571
|
exports.federationSpec = federationSpec;
|
|
506
572
|
exports.getBaseType = getBaseType;
|
|
507
573
|
exports.getCachedDocumentNodeFromSchema = getCachedDocumentNodeFromSchema;
|
|
@@ -516,6 +582,7 @@ exports.mergeOutputs = mergeOutputs;
|
|
|
516
582
|
exports.normalizeConfig = normalizeConfig;
|
|
517
583
|
exports.normalizeInstanceOrArray = normalizeInstanceOrArray;
|
|
518
584
|
exports.normalizeOutputParam = normalizeOutputParam;
|
|
585
|
+
exports.oldVisit = oldVisit;
|
|
519
586
|
exports.removeFederation = removeFederation;
|
|
520
587
|
exports.removeNonNullWrapper = removeNonNullWrapper;
|
|
521
588
|
exports.resolveExternalModuleAndFn = resolveExternalModuleAndFn;
|
package/index.mjs
CHANGED
|
@@ -210,15 +210,17 @@ function isUsingTypes(document, externalFragments, schema) {
|
|
|
210
210
|
}
|
|
211
211
|
},
|
|
212
212
|
},
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
VariableDefinition: {
|
|
214
|
+
enter: (node, key, parent, path, anscestors) => {
|
|
215
215
|
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
216
216
|
if (insideIgnoredFragment) {
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
219
|
foundFields++;
|
|
220
220
|
},
|
|
221
|
-
|
|
221
|
+
},
|
|
222
|
+
InputValueDefinition: {
|
|
223
|
+
enter: (node, key, parent, path, anscestors) => {
|
|
222
224
|
const insideIgnoredFragment = anscestors.find((f) => f.kind && f.kind === 'FragmentDefinition' && externalFragments.includes(f.name.value));
|
|
223
225
|
if (insideIgnoredFragment) {
|
|
224
226
|
return;
|
|
@@ -390,7 +392,7 @@ class ApolloFederation {
|
|
|
390
392
|
extractKeyOrRequiresFieldSet(directive) {
|
|
391
393
|
const arg = directive.arguments.find(arg => arg.name.value === 'fields');
|
|
392
394
|
const value = arg.value.value;
|
|
393
|
-
return
|
|
395
|
+
return oldVisit(parse(`{${value}}`), {
|
|
394
396
|
leave: {
|
|
395
397
|
SelectionSet(node) {
|
|
396
398
|
return node.selections.reduce((accum, field) => {
|
|
@@ -493,4 +495,66 @@ function isDetailedError(error) {
|
|
|
493
495
|
|
|
494
496
|
const getCachedDocumentNodeFromSchema = memoize1(getDocumentNodeFromSchema);
|
|
495
497
|
|
|
496
|
-
|
|
498
|
+
function oldVisit(root, { enter: enterVisitors, leave: leaveVisitors, ...newVisitor }) {
|
|
499
|
+
if (typeof enterVisitors === 'object') {
|
|
500
|
+
for (const key in enterVisitors) {
|
|
501
|
+
newVisitor[key] = newVisitor[key] || {};
|
|
502
|
+
newVisitor[key].enter = enterVisitors[key];
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (typeof leaveVisitors === 'object') {
|
|
506
|
+
for (const key in leaveVisitors) {
|
|
507
|
+
newVisitor[key] = newVisitor[key] || {};
|
|
508
|
+
newVisitor[key].leave = leaveVisitors[key];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return visit(root, newVisitor);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function createNoopProfiler() {
|
|
515
|
+
return {
|
|
516
|
+
run(fn) {
|
|
517
|
+
return Promise.resolve().then(() => fn());
|
|
518
|
+
},
|
|
519
|
+
collect() {
|
|
520
|
+
return [];
|
|
521
|
+
},
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function createProfiler() {
|
|
525
|
+
const events = [];
|
|
526
|
+
return {
|
|
527
|
+
collect() {
|
|
528
|
+
return events;
|
|
529
|
+
},
|
|
530
|
+
run(fn, name, cat) {
|
|
531
|
+
let startTime;
|
|
532
|
+
return Promise.resolve()
|
|
533
|
+
.then(() => {
|
|
534
|
+
startTime = process.hrtime();
|
|
535
|
+
})
|
|
536
|
+
.then(() => fn())
|
|
537
|
+
.then(value => {
|
|
538
|
+
const duration = process.hrtime(startTime);
|
|
539
|
+
// Trace Event Format documentation:
|
|
540
|
+
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
|
|
541
|
+
const event = {
|
|
542
|
+
name,
|
|
543
|
+
cat,
|
|
544
|
+
ph: 'X',
|
|
545
|
+
ts: hrtimeToMicroseconds(startTime),
|
|
546
|
+
pid: 1,
|
|
547
|
+
tid: 0,
|
|
548
|
+
dur: hrtimeToMicroseconds(duration),
|
|
549
|
+
};
|
|
550
|
+
events.push(event);
|
|
551
|
+
return value;
|
|
552
|
+
});
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function hrtimeToMicroseconds(hrtime) {
|
|
557
|
+
return (hrtime[0] * 1e9 + hrtime[1]) / 1000;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export { ApolloFederation, DetailedError, addFederationReferencesToSchema, createNoopProfiler, createProfiler, federationSpec, getBaseType, getCachedDocumentNodeFromSchema, hasNullableTypeRecursively, isComplexPluginOutput, isConfiguredOutput, isDetailedError, isOutputConfigArray, isUsingTypes, isWrapperType, mergeOutputs, normalizeConfig, normalizeInstanceOrArray, normalizeOutputParam, oldVisit, removeFederation, removeNonNullWrapper, resolveExternalModuleAndFn };
|
package/oldVisit.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ASTNode, visit } from 'graphql';
|
|
2
|
+
declare type VisitFn = typeof visit;
|
|
3
|
+
declare type NewVisitor = Partial<Parameters<VisitFn>[1]>;
|
|
4
|
+
declare type OldVisitor = {
|
|
5
|
+
enter?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['enter']>>;
|
|
6
|
+
leave?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['leave']>>;
|
|
7
|
+
} & NewVisitor;
|
|
8
|
+
export declare function oldVisit(root: ASTNode, { enter: enterVisitors, leave: leaveVisitors, ...newVisitor }: OldVisitor): any;
|
|
9
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/plugin-helpers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-alpha-23d229715.0",
|
|
4
4
|
"description": "GraphQL Code Generator common utils and types",
|
|
5
5
|
"peerDependencies": {
|
|
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"
|
|
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-tools/utils": "^8.
|
|
9
|
+
"@graphql-tools/utils": "^8.5.2",
|
|
10
10
|
"change-case-all": "1.0.14",
|
|
11
|
-
"common-tags": "1.8.
|
|
11
|
+
"common-tags": "1.8.2",
|
|
12
12
|
"import-from": "4.0.0",
|
|
13
13
|
"lodash": "~4.17.0",
|
|
14
14
|
"tslib": "~2.3.0"
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"definition": "index.d.ts"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
|
+
"./package.json": "./package.json",
|
|
29
30
|
".": {
|
|
30
31
|
"require": "./index.js",
|
|
31
32
|
"import": "./index.mjs"
|
package/profiler.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ProfilerEvent {
|
|
2
|
+
/** The name of the event, as displayed in Trace Viewer */
|
|
3
|
+
name: string;
|
|
4
|
+
/** The event categories. This is a comma separated list of categories for the event. The categories can be used to hide events in the Trace Viewer UI. */
|
|
5
|
+
cat: string;
|
|
6
|
+
/** The event type. This is a single character which changes depending on the type of event being output. The valid values are listed in the table below. We will discuss each phase type below. */
|
|
7
|
+
ph: string;
|
|
8
|
+
/** The tracing clock timestamp of the event. The timestamps are provided at microsecond granularity. */
|
|
9
|
+
ts: number;
|
|
10
|
+
/** Optional. The thread clock timestamp of the event. The timestamps are provided at microsecond granularity. */
|
|
11
|
+
tts?: string;
|
|
12
|
+
/** The process ID for the process that output this event. */
|
|
13
|
+
pid: number;
|
|
14
|
+
/** The thread ID for the thread that output this event. */
|
|
15
|
+
tid: number;
|
|
16
|
+
/** Any arguments provided for the event. Some of the event types have required argument fields, otherwise, you can put any information you wish in here. The arguments are displayed in Trace Viewer when you view an event in the analysis section. */
|
|
17
|
+
args?: any;
|
|
18
|
+
/** duration */
|
|
19
|
+
dur: number;
|
|
20
|
+
/** A fixed color name to associate with the event. If provided, cname must be one of the names listed in trace-viewer's base color scheme's reserved color names list */
|
|
21
|
+
cname?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Profiler {
|
|
24
|
+
run<T>(fn: () => Promise<T>, name: string, cat?: string): Promise<T>;
|
|
25
|
+
collect(): ProfilerEvent[];
|
|
26
|
+
}
|
|
27
|
+
export declare function createNoopProfiler(): Profiler;
|
|
28
|
+
export declare function createProfiler(): Profiler;
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GraphQLSchema, DocumentNode } from 'graphql';
|
|
2
2
|
import { Source } from '@graphql-tools/utils';
|
|
3
|
+
import type { Profiler } from './profiler';
|
|
3
4
|
export declare namespace Types {
|
|
4
5
|
interface GenerateOptions {
|
|
5
6
|
filename: string;
|
|
@@ -17,6 +18,7 @@ export declare namespace Types {
|
|
|
17
18
|
pluginContext?: {
|
|
18
19
|
[key: string]: any;
|
|
19
20
|
};
|
|
21
|
+
profiler?: Profiler;
|
|
20
22
|
}
|
|
21
23
|
type FileOutput = {
|
|
22
24
|
filename: string;
|
|
@@ -293,6 +295,7 @@ export declare namespace Types {
|
|
|
293
295
|
pluginContext?: {
|
|
294
296
|
[name: string]: any;
|
|
295
297
|
};
|
|
298
|
+
profiler?: Profiler;
|
|
296
299
|
};
|
|
297
300
|
type OutputPreset<TPresetConfig = any> = {
|
|
298
301
|
buildGeneratesSection: (options: PresetFnArgs<TPresetConfig>) => Promisable<GenerateOptions[]>;
|
|
@@ -367,7 +370,7 @@ export declare namespace Types {
|
|
|
367
370
|
* For more details: https://graphql-code-generator.com/docs/getting-started/codegen-config
|
|
368
371
|
*/
|
|
369
372
|
generates: {
|
|
370
|
-
[outputPath: string]: ConfiguredOutput;
|
|
373
|
+
[outputPath: string]: ConfiguredOutput | ConfiguredPlugin[];
|
|
371
374
|
};
|
|
372
375
|
/**
|
|
373
376
|
* @description A flag to overwrite files if they already exist when generating code (`true` by default).
|
package/utils.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { Types } from './types';
|
|
|
3
3
|
export declare function mergeOutputs(content: Types.PluginOutput | Array<Types.PluginOutput>): string;
|
|
4
4
|
export declare function isWrapperType(t: GraphQLOutputType): t is GraphQLNonNull<any> | GraphQLList<any>;
|
|
5
5
|
export declare function getBaseType(type: GraphQLOutputType): GraphQLNamedType;
|
|
6
|
-
export declare function removeNonNullWrapper(type: GraphQLOutputType):
|
|
6
|
+
export declare function removeNonNullWrapper(type: GraphQLOutputType): GraphQLOutputType;
|