Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add configurable schema linting #596

Merged
merged 28 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6bc5bcf
feat: schema linting
JivusAyrus Mar 1, 2024
a634923
feat: improve and add more tests
JivusAyrus Mar 2, 2024
866c24b
chore: update migrations
JivusAyrus Mar 2, 2024
89a4c0f
Merge branch 'main' into suvij/eng-4763-configurable-schema-linting
JivusAyrus Mar 2, 2024
5ab6756
chore: improve
JivusAyrus Mar 4, 2024
68fb560
fix: ci
JivusAyrus Mar 4, 2024
2890b00
chore: improve
JivusAyrus Mar 4, 2024
df555c5
fix: ci
JivusAyrus Mar 4, 2024
d248f31
Merge branch 'main' into suvij/eng-4763-configurable-schema-linting
JivusAyrus Mar 4, 2024
38badcb
chore: improve
JivusAyrus Mar 5, 2024
86f1be4
chore: improve
JivusAyrus Mar 5, 2024
1096b64
chore: improve
JivusAyrus Mar 5, 2024
ea71e00
fix: update db migrations
JivusAyrus Mar 5, 2024
406d767
Merge branch 'main' of github.com:wundergraph/cosmo into suvij/eng-47…
JivusAyrus Mar 5, 2024
7f46cfe
fix: ci
JivusAyrus Mar 5, 2024
8f353f6
feat: improve
JivusAyrus Mar 6, 2024
265e766
Merge branch 'main' of github.com:wundergraph/cosmo into suvij/eng-47…
JivusAyrus Mar 6, 2024
b8b7211
fix: tests
JivusAyrus Mar 6, 2024
797cfb5
chore: improve
JivusAyrus Mar 7, 2024
f92f061
chore: improve
JivusAyrus Mar 7, 2024
645dac4
Merge branch 'main' into suvij/eng-4763-configurable-schema-linting
JivusAyrus Mar 7, 2024
0f087a3
fix: pr suggestions
JivusAyrus Mar 8, 2024
07bcff9
fix: ci
JivusAyrus Mar 8, 2024
02c4fd0
fix: ci
JivusAyrus Mar 8, 2024
12cb373
fix: pr suggestions
JivusAyrus Mar 8, 2024
99a861d
chore: improve
JivusAyrus Mar 10, 2024
bc108d2
Merge branch 'main' into suvij/eng-4763-configurable-schema-linting
JivusAyrus Mar 10, 2024
c0623c8
fix: pr suggestion
JivusAyrus Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions cli/src/commands/subgraph/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export default (opts: BaseCommandOptions) => {

const changesTable = new Table({
head: [pc.bold(pc.white('CHANGE')), pc.bold(pc.white('TYPE')), pc.bold(pc.white('DESCRIPTION'))],
colWidths: [15, 30, 80],
wordWrap: true,
});

Expand All @@ -100,22 +99,34 @@ export default (opts: BaseCommandOptions) => {
wordWrap: true,
});

const lintIssuesTable = new Table({
head: [pc.bold(pc.white('LINT_RULE')), pc.bold(pc.white('ERROR_MESSAGE')), pc.bold(pc.white('LINE NUMBER'))],
colAligns: ['left', 'left', 'center'],
wordWrap: true,
});

let success = false;
let finalStatement = '';

let studioCheckDestination = '';
if (resp.checkId && resp.checkedFederatedGraphs.length > 0) {
studioCheckDestination = `Open in studio: ${config.webURL}/${resp.checkedFederatedGraphs[0].organizationSlug}/${resp.checkedFederatedGraphs[0].namespace}/graph/${resp.checkedFederatedGraphs[0].name}/checks/${resp.checkId}`;
studioCheckDestination = `${pc.bold('Open in studio')}: ${config.webURL}/${
resp.checkedFederatedGraphs[0].organizationSlug
}/${resp.checkedFederatedGraphs[0].namespace}/graph/${resp.checkedFederatedGraphs[0].name}/checks/${
resp.checkId
}`;
}

switch (resp.response?.code) {
case EnumStatusCode.OK: {
if (
resp.nonBreakingChanges.length === 0 &&
resp.breakingChanges.length === 0 &&
resp.compositionErrors.length === 0
resp.compositionErrors.length === 0 &&
resp.lintErrors.length === 0 &&
resp.lintWarnings.length === 0
) {
console.log(`\nDetected no changes.\n${studioCheckDestination}\n`);
console.log(`\nDetected no changes.\nDetected no lint issues.\n\n${studioCheckDestination}\n`);

success = true;

Expand Down Expand Up @@ -167,13 +178,21 @@ export default (opts: BaseCommandOptions) => {

if (resp.breakingChanges.length > 0) {
for (const breakingChange of resp.breakingChanges) {
changesTable.push([pc.red('BREAKING'), breakingChange.changeType, breakingChange.message]);
changesTable.push([
`${logSymbols.error} ${pc.red('BREAKING')}`,
breakingChange.changeType,
breakingChange.message,
]);
}
}

if (resp.nonBreakingChanges.length > 0) {
for (const nonBreakingChange of resp.nonBreakingChanges) {
changesTable.push(['NON-BREAKING', nonBreakingChange.changeType, nonBreakingChange.message]);
changesTable.push([
`${logSymbols.success} NON-BREAKING`,
nonBreakingChange.changeType,
nonBreakingChange.message,
]);
}
}

Expand All @@ -192,12 +211,32 @@ export default (opts: BaseCommandOptions) => {
console.log(compositionErrorsTable.toString());
}

if (resp.lintErrors.length > 0 || resp.lintWarnings.length > 0) {
success = resp.lintErrors.length === 0;
console.log('\nDetected lint issues:');
for (const error of resp.lintErrors) {
lintIssuesTable.push([
`${logSymbols.error} ${pc.red(error.lintRuleType)}`,
error.message,
error.issueLocation?.line,
]);
}
for (const warning of resp.lintWarnings) {
lintIssuesTable.push([
`${logSymbols.warning} ${pc.yellow(warning.lintRuleType)}`,
warning.message,
warning.issueLocation?.line,
]);
}
console.log(lintIssuesTable.toString());
}

if (success) {
console.log(
'\n' +
logSymbols.success +
pc.green(` Schema check passed. ${finalStatement}`) +
'\n' +
'\n\n' +
studioCheckDestination +
'\n',
);
Expand Down
180 changes: 101 additions & 79 deletions composition-go/index.global.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions composition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export * from './schema-building/type-merging';
export * from './schema-building/utils';
export * from './subgraph/subgraph';
export * from './utils/utils';
export * from './utils/constants';
export * from './warnings/warnings';
24 changes: 24 additions & 0 deletions composition/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,27 @@ export const SCOPE_SCALAR_DEFINITION: MutableScalarNode = {
export const MAXIMUM_TYPE_NESTING = 30;

export const INHERITABLE_DIRECTIVE_NAMES = [EXTERNAL, SHAREABLE];

export const baseDirectives = `
directive @deprecated(reason: String = "No longer supported") on ARGUMENT_DEFINITION | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION
directive @extends on INTERFACE | OBJECT
directive @external on FIELD_DEFINITION | OBJECT
directive @eventsPublish(topic: String!, sourceID: String) on FIELD_DEFINITION
directive @eventsRequest(topic: String!, sourceID: String) on FIELD_DEFINITION
directive @eventsSubscribe(topic: String!, sourceID: String) on FIELD_DEFINITION
directive @key(fields: openfed__FieldSet!, resolvable: Boolean = true) repeatable on INTERFACE | OBJECT
directive @provides(fields: openfed__FieldSet!) on FIELD_DEFINITION
directive @requires(fields: openfed__FieldSet!) on FIELD_DEFINITION
directive @specifiedBy(url: String!) on SCALAR
directive @tag(name: String!) repeatable on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION
directive @authenticated on ENUM | FIELD_DEFINITION | INTERFACE | OBJECT | SCALAR
directive @composeDirective(name: String!) repeatable on SCHEMA
directive @inaccessible on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION
directive @interfaceObject on OBJECT
directive @link(url: String!, as: String, for: String, import: [String]) repeatable on SCHEMA
directive @override(from: String!) on FIELD_DEFINITION
directive @requiresScopes(scopes: [[openfed__Scope!]!]!) on ENUM | FIELD_DEFINITION | INTERFACE | OBJECT | SCALAR
directive @shareable on FIELD_DEFINITION | OBJECT
scalar openfed__FieldSet
scalar openfed__Scope
`;
Loading
Loading