Skip to content

Commit 3fe3761

Browse files
authored
Add debug (#989)
* add debug for schema and operations loading * add fast-glob * add changeset * fix canary release
1 parent b926fb6 commit 3fe3761

File tree

9 files changed

+56
-20
lines changed

9 files changed

+56
-20
lines changed

.changeset/silly-zebras-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
print debug information with `DEBUG` env variable, example `DEBUG=graphql-eslint:* eslint .`

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Have a question?
4-
url: https://github.com/dotansimha/graphql-eslint/discussions/new
4+
url: https://github.com/B2o5T/graphql-eslint/discussions/new
55
about: Not sure about something? need help from the community? have a question to our team? please ask and answer questions here.

.github/workflows/canary.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Release Canary
4242
id: canary
4343
uses: 'kamilkisiela/release-canary@master'
44-
if: github.repository == 'dotansimha/graphql-eslint'
44+
if: github.repository == 'B2o5T/graphql-eslint'
4545
with:
4646
npm-token: ${{ secrets.NODE_AUTH_TOKEN }}
4747
npm-script: 'yarn release:canary'
@@ -66,4 +66,4 @@ jobs:
6666
The latest changes of this PR are not available as alpha, since there are no linked `changesets` for this PR.
6767
bot-token: ${{ secrets.GH_API_TOKEN }}
6868
bot: 'theguild-bot'
69-
github-token: ${{ secrets.GITHUB_TOKEN }}
69+
github-token: ${{ secrets.GITHUB_TOKEN }}

packages/plugin/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"@graphql-tools/graphql-tag-pluck": "7.1.5",
4040
"@graphql-tools/utils": "8.6.1",
4141
"chalk": "4.1.2",
42+
"debug": "4.3.3",
43+
"fast-glob": "3.2.11",
4244
"graphql-config": "4.1.0",
4345
"graphql-depth-limit": "1.1.0",
4446
"lodash.lowercase": "4.3.0"

packages/plugin/src/graphql-config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { dirname } from 'path';
2+
import debugFactory from 'debug';
13
import { GraphQLConfig, GraphQLExtensionDeclaration, loadConfigSync, SchemaPointer } from 'graphql-config';
24
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
35
import { ParserOptions } from './types';
4-
import { dirname } from 'path';
56

7+
const debug = debugFactory('graphql-eslint:graphql-config');
68
let graphQLConfig: GraphQLConfig;
79

810
export function loadGraphQLConfig(options: ParserOptions): GraphQLConfig {
@@ -22,6 +24,11 @@ export function loadGraphQLConfig(options: ParserOptions): GraphQLConfig {
2224
extensions: [addCodeFileLoaderExtension],
2325
});
2426

27+
debug('options.skipGraphQLConfig: %o', options.skipGraphQLConfig);
28+
if (onDiskConfig) {
29+
debug('Graphql-config path %o', onDiskConfig.filepath);
30+
}
31+
2532
const configOptions = options.projects
2633
? { projects: options.projects }
2734
: {

packages/plugin/src/parser.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { parseGraphQLSDL } from '@graphql-tools/utils';
22
import { ASTNode, GraphQLError, TypeInfo, Source } from 'graphql';
3-
import { Linter } from 'eslint';
3+
import debugFactory from 'debug';
44
import { convertToESTree, extractTokens } from './estree-parser';
55
import { GraphQLESLintParseResult, ParserOptions, ParserServices } from './types';
66
import { getSchema } from './schema';
77
import { getSiblingOperations } from './sibling-operations';
88
import { loadGraphQLConfig } from './graphql-config';
99

10-
export function parse(code: string, options?: ParserOptions): Linter.ESLintParseResult['ast'] {
11-
return parseForESLint(code, options).ast;
12-
}
10+
const debug = debugFactory('graphql-eslint:parser');
11+
12+
debug('cwd %o', process.cwd())
1313

1414
export function parseForESLint(code: string, options: ParserOptions = {}): GraphQLESLintParseResult {
1515
const gqlConfig = loadGraphQLConfig(options);
@@ -36,15 +36,14 @@ export function parseForESLint(code: string, options: ParserOptions = {}): Graph
3636

3737
return {
3838
services: parserServices,
39-
parserServices,
4039
ast: {
41-
type: 'Program',
42-
body: [rootTree as any],
43-
sourceType: 'script',
4440
comments,
41+
tokens,
4542
loc: rootTree.loc,
4643
range: rootTree.range as [number, number],
47-
tokens,
44+
type: 'Program',
45+
sourceType: 'script',
46+
body: [rootTree as any],
4847
},
4948
};
5049
} catch (e) {

packages/plugin/src/schema.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { GraphQLSchema } from 'graphql';
22
import { GraphQLConfig } from 'graphql-config';
33
import { asArray } from '@graphql-tools/utils';
4+
import debugFactory from 'debug'
5+
import fastGlob from 'fast-glob';
46
import { ParserOptions } from './types';
57
import { getOnDiskFilepath, loaderCache, logger } from './utils';
68

79
const schemaCache: Map<string, GraphQLSchema> = new Map();
10+
const debug = debugFactory('graphql-eslint:schema')
811

912
export function getSchema(options: ParserOptions = {}, gqlConfig: GraphQLConfig): GraphQLSchema | null {
1013
const realFilepath = options.filePath ? getOnDiskFilepath(options.filePath) : null;
@@ -21,10 +24,18 @@ export function getSchema(options: ParserOptions = {}, gqlConfig: GraphQLConfig)
2124

2225
let schema: GraphQLSchema | null;
2326
try {
27+
debug('Loading schema from %o', projectForFile.schema)
2428
schema = projectForFile.loadSchemaSync(projectForFile.schema, 'GraphQLSchema', {
2529
cache: loaderCache,
2630
...options.schemaOptions,
2731
});
32+
if (debug.enabled) {
33+
debug('Schema loaded: %o', schema instanceof GraphQLSchema);
34+
const schemaPaths = fastGlob.sync(projectForFile.schema as string | string[], {
35+
absolute: true,
36+
});
37+
debug('Schema pointers %O', schemaPaths)
38+
}
2839
} catch (e) {
2940
schema = null;
3041
logger.error('Error while loading schema\n', e);

packages/plugin/src/sibling-operations.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import {
99
} from 'graphql';
1010
import { Source, asArray } from '@graphql-tools/utils';
1111
import { GraphQLConfig } from 'graphql-config';
12+
import debugFactory from 'debug';
13+
import fastGlob from 'fast-glob';
1214
import { ParserOptions } from './types';
1315
import { getOnDiskFilepath, loaderCache, logger } from './utils';
1416

1517
export type FragmentSource = { filePath: string; document: FragmentDefinitionNode };
1618
export type OperationSource = { filePath: string; document: OperationDefinitionNode };
1719

20+
const debug = debugFactory('graphql-eslint:operations');
21+
1822
export type SiblingOperations = {
1923
available: boolean;
2024
getFragment(fragmentName: string): FragmentSource[];
@@ -61,10 +65,18 @@ const getSiblings = (filePath: string, gqlConfig: GraphQLConfig): Source[] => {
6165
let siblings = operationsCache.get(documentsKey);
6266

6367
if (!siblings) {
68+
debug('Loading operations from %o', projectForFile.documents);
6469
const documents = projectForFile.loadDocumentsSync(projectForFile.documents, {
6570
skipGraphQLImport: true,
6671
cache: loaderCache,
6772
});
73+
if (debug.enabled) {
74+
debug('Loaded %d operations', documents.length);
75+
const operationsPaths = fastGlob.sync(projectForFile.documents as string | string[], {
76+
absolute: true
77+
});
78+
debug('Operations pointers %O', operationsPaths);
79+
}
6880
siblings = handleVirtualPath(documents);
6981
operationsCache.set(documentsKey, siblings);
7082
}

yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,13 @@ debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2:
33143314
dependencies:
33153315
ms "2.1.2"
33163316

3317+
[email protected], debug@^4.3.1, debug@^4.3.3:
3318+
version "4.3.3"
3319+
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
3320+
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
3321+
dependencies:
3322+
ms "2.1.2"
3323+
33173324
debug@^2.6.9:
33183325
version "2.6.9"
33193326
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@@ -3328,13 +3335,6 @@ debug@^3.2.7:
33283335
dependencies:
33293336
ms "^2.1.1"
33303337

3331-
debug@^4.3.1, debug@^4.3.3:
3332-
version "4.3.3"
3333-
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
3334-
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
3335-
dependencies:
3336-
ms "2.1.2"
3337-
33383338
decamelize-keys@^1.1.0:
33393339
version "1.1.0"
33403340
resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.0.tgz#d171a87933252807eb3cb61dc1c1445d078df2d9"

0 commit comments

Comments
 (0)