Skip to content

Commit fcaca86

Browse files
committed
chore: lint
1 parent 61a4717 commit fcaca86

15 files changed

+174
-152
lines changed

eslint.config.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import eslint from '@eslint/js';
22
import tseslint from 'typescript-eslint';
3+
import prettierRecommended from 'eslint-plugin-prettier/recommended';
34

45
export default tseslint.config(
56
eslint.configs.recommended,
@@ -15,4 +16,5 @@ export default tseslint.config(
1516
},
1617
},
1718
},
19+
prettierRecommended,
1820
);

src/__tests__/integration.test.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ describe('Persisted Query Plugin Integration Tests', () => {
99
// Load test schema and documents
1010
const schemaPath = join(__dirname, 'fixtures/test-schema.graphql');
1111
const documentsPath = join(__dirname, 'fixtures/test-documents.graphql');
12-
12+
1313
const schemaDoc = readFileSync(schemaPath, 'utf8');
1414
const documentsDoc = readFileSync(documentsPath, 'utf8');
15-
15+
1616
const schema = buildSchema(schemaDoc);
1717
const documentNode = parse(documentsDoc);
18-
18+
1919
const documents: Types.DocumentFile[] = [
2020
{
2121
document: documentNode,
@@ -28,65 +28,65 @@ describe('Persisted Query Plugin Integration Tests', () => {
2828
const result = plugin(schema, documents, { output: 'client' });
2929
// We know result is a string, but TypeScript sees it as Promisable<string>
3030
const manifest = JSON.parse(result as string);
31-
31+
3232
// Use snapshot for client manifest
3333
expect(manifest).toMatchSnapshot();
34-
});
35-
34+
});
35+
3636
test('generates valid client manifest with algorithm prefix', () => {
37-
const result = plugin(schema, documents, {
37+
const result = plugin(schema, documents, {
3838
output: 'client',
39-
includeAlgorithmPrefix: true
39+
includeAlgorithmPrefix: true,
4040
});
4141
// We know result is a string, but TypeScript sees it as Promisable<string>
4242
const manifest = JSON.parse(result as string);
43-
43+
4444
// Use snapshot for client manifest with algorithm prefix
4545
expect(manifest).toMatchSnapshot();
46-
});
47-
46+
});
47+
4848
test('generates valid client manifest with custom algorithm', () => {
49-
const result = plugin(schema, documents, {
49+
const result = plugin(schema, documents, {
5050
output: 'client',
51-
algorithm: 'md5'
51+
algorithm: 'md5',
5252
});
5353
// We know result is a string, but TypeScript sees it as Promisable<string>
5454
const manifest = JSON.parse(result as string);
55-
55+
5656
// Use snapshot for client manifest with custom algorithm
5757
expect(manifest).toMatchSnapshot();
5858
});
5959
});
60-
60+
6161
describe('Server Manifest Generation', () => {
6262
test('generates valid server manifest with default options', () => {
6363
const result = plugin(schema, documents, { output: 'server' });
6464
// We know result is a string, but TypeScript sees it as Promisable<string>
6565
const manifest = JSON.parse(result as string);
66-
66+
6767
// Use snapshot for server manifest
6868
expect(manifest).toMatchSnapshot();
6969
});
7070
});
71-
71+
7272
describe('Error Handling', () => {
7373
test('throws error on missing operation names', () => {
7474
const docWithUnnamedOperation = parse(`
7575
query {
7676
hello
7777
}
7878
`);
79-
79+
8080
const docs: Types.DocumentFile[] = [
8181
{
8282
document: docWithUnnamedOperation,
8383
location: 'test.graphql',
8484
},
8585
];
86-
87-
expect(() =>
88-
plugin(schema, docs, { output: 'client' })
89-
).toThrow('OperationDefinition missing name');
86+
87+
expect(() => plugin(schema, docs, { output: 'client' })).toThrow(
88+
'OperationDefinition missing name',
89+
);
9090
});
9191
});
92-
});
92+
});

src/core/generator.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { DocumentNode, visit } from 'graphql';
2-
import {
2+
import {
33
PluginConfig,
44
ClientOperationListManifest,
55
ServerOperationListManifest,
66
PersistedQueryManifestOperation,
7-
ProcessedOperation
7+
ProcessedOperation,
88
} from '../types';
99
import { createHash } from '../utils/hashing';
1010
import { addTypenameToDocument } from '../utils/transforms';
@@ -13,17 +13,20 @@ import { printDefinitions } from '../utils/transforms';
1313

1414
/**
1515
* Process documents and generate operation hashes with their details
16-
*
16+
*
1717
* @param docs - Array of GraphQL document nodes
1818
* @param config - Plugin configuration
1919
* @returns Array of processed operations with their details
2020
* @throws Error if an operation is missing a name
2121
*/
22-
function processOperations(docs: DocumentNode[], config: PluginConfig): ProcessedOperation[] {
22+
function processOperations(
23+
docs: DocumentNode[],
24+
config: PluginConfig,
25+
): ProcessedOperation[] {
2326
// Add __typename to all selection sets
2427
const processedDocs = docs.map(addTypenameToDocument);
2528
const operations: ProcessedOperation[] = [];
26-
29+
2730
const knownFragments = findFragments(processedDocs);
2831

2932
for (const doc of processedDocs) {
@@ -43,14 +46,14 @@ function processOperations(docs: DocumentNode[], config: PluginConfig): Processe
4346
const query = printDefinitions([def, ...usedFragments.values()]);
4447

4548
const hash = createHash(query, config);
46-
49+
4750
operations.push({
4851
name: operationName,
4952
hash,
5053
type: def.operation,
5154
query,
5255
definition: def,
53-
fragments: Array.from(usedFragments.values())
56+
fragments: Array.from(usedFragments.values()),
5457
});
5558
},
5659
},
@@ -63,7 +66,7 @@ function processOperations(docs: DocumentNode[], config: PluginConfig): Processe
6366
/**
6467
* Generates a client-side persisted query manifest
6568
* Client manifests map operation names to their hash
66-
*
69+
*
6770
* @param docs - Array of GraphQL document nodes
6871
* @param config - Plugin configuration
6972
* @returns Client-side manifest object
@@ -75,7 +78,7 @@ export function generateClientManifest(
7578
): ClientOperationListManifest {
7679
const operations = processOperations(docs, config);
7780
const manifest: ClientOperationListManifest = {};
78-
81+
7982
for (const operation of operations) {
8083
manifest[operation.name] = operation.hash;
8184
}
@@ -86,7 +89,7 @@ export function generateClientManifest(
8689
/**
8790
* Generates a server-side persisted query manifest
8891
* Server manifests map query hashes to operation details
89-
*
92+
*
9093
* @param docs - Array of GraphQL document nodes
9194
* @param config - Plugin configuration
9295
* @returns Server-side manifest object
@@ -97,22 +100,22 @@ export function generateServerManifest(
97100
config: PluginConfig,
98101
): ServerOperationListManifest {
99102
const operations = processOperations(docs, config);
100-
103+
101104
const manifest: ServerOperationListManifest = {
102105
format: 'apollo-persisted-query-manifest',
103106
version: 1,
104107
operations: {},
105108
};
106-
109+
107110
for (const operation of operations) {
108111
const operationDetails: PersistedQueryManifestOperation = {
109112
type: operation.type,
110113
name: operation.name,
111114
body: operation.query,
112115
};
113-
116+
114117
manifest.operations[operation.hash] = operationDetails;
115118
}
116119

117120
return manifest;
118-
}
121+
}

src/core/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './generator';
2-
export * from './plugin';
2+
export * from './plugin';

src/core/plugin.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ import { generateClientManifest, generateServerManifest } from './generator';
44

55
/**
66
* GraphQL CodeGen plugin for generating persisted operation manifests
7-
*
7+
*
88
* @param _schema - GraphQL schema (unused)
99
* @param documents - GraphQL documents to process
1010
* @param config - Plugin configuration
1111
* @returns JSON string representation of the generated manifest
1212
* @throws Error if no documents are provided or output format is not specified
13-
*
13+
*
1414
* For GraphQL over HTTP specification compliance, set `includeAlgorithmPrefix: true`
1515
* to enable the "Prefixed Document Identifier" format (e.g., `sha256:abc123...`).
1616
*/
17-
export const plugin: PersistedQueryPlugin = (
18-
_schema,
19-
documents,
20-
config,
21-
) => {
17+
export const plugin: PersistedQueryPlugin = (_schema, documents, config) => {
2218
// Validate input documents
2319
if (
2420
!documents ||
@@ -35,10 +31,18 @@ export const plugin: PersistedQueryPlugin = (
3531

3632
// Generate appropriate manifest format based on configuration
3733
if (config.output === 'client') {
38-
return JSON.stringify(generateClientManifest(documentNodes, config), null, ' ');
34+
return JSON.stringify(
35+
generateClientManifest(documentNodes, config),
36+
null,
37+
' ',
38+
);
3939
} else if (config.output === 'server') {
40-
return JSON.stringify(generateServerManifest(documentNodes, config), null, ' ');
40+
return JSON.stringify(
41+
generateServerManifest(documentNodes, config),
42+
null,
43+
' ',
44+
);
4145
} else {
4246
throw new Error("Must configure output to 'server' or 'client'");
4347
}
44-
};
48+
};

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
22
* GraphQL CodeGen Plugin for Persisted Query Lists
3-
*
3+
*
44
* The plugin can generate manifests in two formats:
55
* - Client format: Maps operation names to query hashes
66
* - Server format: Maps query hashes to full operation details
77
*/
88

99
export * from './types';
1010
export * from './core';
11-
export * from './utils';
11+
export * from './utils';

src/types/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import type { FragmentDefinitionNode, OperationDefinitionNode, OperationTypeNode } from 'graphql';
1+
import type {
2+
FragmentDefinitionNode,
3+
OperationDefinitionNode,
4+
OperationTypeNode,
5+
} from 'graphql';
26
import type { PluginFunction } from '@graphql-codegen/plugin-helpers';
37

48
/**
59
* Configuration for the persisted query generator plugin
610
*/
711
export interface PluginConfig {
8-
/**
12+
/**
913
* Output format - 'server' generates hash->operation mapping,
1014
* 'client' generates operation->hash mapping
1115
*/
1216
output: 'server' | 'client';
13-
17+
1418
/**
1519
* Hash algorithm to use (defaults to 'sha256')
1620
*/
@@ -54,7 +58,9 @@ export type ClientOperationListManifest = Record<string, string>;
5458
/**
5559
* Union type for both manifest formats
5660
*/
57-
export type OperationListManifest = ServerOperationListManifest | ClientOperationListManifest;
61+
export type OperationListManifest =
62+
| ServerOperationListManifest
63+
| ClientOperationListManifest;
5864

5965
/**
6066
* Internal type for a GraphQL definition

0 commit comments

Comments
 (0)