Skip to content

Commit

Permalink
aa
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Aug 3, 2024
1 parent 0d9ec01 commit f34f7ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-steaks-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-config': patch
---

should not throw `pattern is too long` from minimatch dependency when SDL schema contain more than 65536 characters
10 changes: 9 additions & 1 deletion src/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ export class GraphQLProjectConfig {
}
}

// XXX: it works but uses nodejs - expose normalization of file and dir paths in config
function isSDLSchemaLike(schema: string): boolean {
return schema.includes('\n');
}

// XXX: it works but uses Node.js - expose normalization of file and dir paths in config
function match(filepath: string, dirpath: string, pointer?: Pointer): boolean {
if (!pointer) {
return false;
Expand All @@ -202,6 +206,10 @@ function match(filepath: string, dirpath: string, pointer?: Pointer): boolean {
}

if (typeof pointer === 'string') {
if (isSDLSchemaLike(pointer)) {
return false;
}

const normalizedFilepath = normalize(isAbsolute(filepath) ? relative(dirpath, filepath) : filepath);
return minimatch(normalizedFilepath, normalize(pointer), { dot: true });
}
Expand Down
15 changes: 13 additions & 2 deletions test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { buildSchema, buildASTSchema } from 'graphql';
import { resolve, basename } from 'path';
import { TempDir } from './utils/temp-dir';
import { runTests } from './utils/runner';
import { loadConfig, loadConfigSync, ConfigNotFoundError } from 'graphql-config';
import { beforeEach, beforeAll, test, describe, expect, afterAll } from 'vitest';
import { loadConfig, loadConfigSync, ConfigNotFoundError, GraphQLConfig } from 'graphql-config';

const temp = new TempDir();

Expand Down Expand Up @@ -377,3 +376,15 @@ runTests({ async: loadConfig, sync: loadConfigSync })((load, mode) => {
});
});
});

describe('GraphQLConfig', () => {
const MINIMATCH_MAX_LENGTH = 65_536;

// https://github.com/dimaMachina/graphql-eslint/issues/2046
it(`should not throw \`pattern is too long\` from minimatch dependency when SDL schema contain more than ${MINIMATCH_MAX_LENGTH} characters`, async () => {
const schema = Array.from({ length: 2_150 }, (_, i) => `type Query${i} { foo: String }`).join('\n');
const graphQLConfig = new GraphQLConfig({ config: { schema }, filepath: '' }, []);
expect(schema.length).toBeGreaterThan(MINIMATCH_MAX_LENGTH);
expect(() => graphQLConfig.getProjectForFile('foo')).not.toThrow();
});
});
1 change: 0 additions & 1 deletion test/loaders.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DirectiveDefinitionNode, buildSchema, GraphQLSchema, Kind } from 'graphql';
import { Loader, Source } from '@graphql-tools/utils';

Check failure on line 2 in test/loaders.spec.ts

View workflow job for this annotation

GitHub Actions / Node 16 on ubuntu-latest

test/loaders.spec.ts

Error: There are some problems in resolving the mocks API. You may encounter this issue when importing the mocks API from another module other than 'vitest'. To fix this issue you can either: - import the mocks API directly from 'vitest' - enable the 'globals' options ❯ test/loaders.spec.ts:2:95

Check failure on line 2 in test/loaders.spec.ts

View workflow job for this annotation

GitHub Actions / Node 18 on ubuntu-latest

test/loaders.spec.ts

Error: There are some problems in resolving the mocks API. You may encounter this issue when importing the mocks API from another module other than 'vitest'. To fix this issue you can either: - import the mocks API directly from 'vitest' - enable the 'globals' options ❯ test/loaders.spec.ts:2:95

Check failure on line 2 in test/loaders.spec.ts

View workflow job for this annotation

GitHub Actions / Node 20 on ubuntu-latest

test/loaders.spec.ts

Error: There are some problems in resolving the mocks API. You may encounter this issue when importing the mocks API from another module other than 'vitest'. To fix this issue you can either: - import the mocks API directly from 'vitest' - enable the 'globals' options ❯ test/loaders.spec.ts:2:95
import { beforeAll, test, describe, expect, vi, Mock } from 'vitest';
import { LoadersRegistry } from 'graphql-config';
import { loadTypedefsSync, loadSchemaSync, loadSchema, LoadSchemaOptions } from '@graphql-tools/load';

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"types": ["vitest/globals"],
"paths": {
"graphql-config": ["./src/index.ts"]
}
Expand Down

0 comments on commit f34f7ce

Please sign in to comment.