Skip to content

Commit

Permalink
Merge pull request #185 from apollographql/fix-staging
Browse files Browse the repository at this point in the history
Add changelog github action
  • Loading branch information
michael-watson authored Apr 19, 2024
2 parents 883d810 + 59d12a5 commit 26d48c0
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 45 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Check Changelog
on:
pull_request:
types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
jobs:
Check-Changelog:
name: Check Changelog Action
runs-on: ubuntu-20.04
steps:
- uses: tarides/changelog-check-action@v2
with:
changelog: CHANGELOG.md
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Apollo Workbench VSCode 3.3.11

- Add changelog GitHub Action to ensure a changelog entry is there for every PR
- Fix error locations for `INVALID_GRAPHQL` errors. Workebnch now tries to rebuild the source schema from the error and then uses the `error.nodes.location` for the VS Code diagnostic.

## Apollo Workbench VSCode 3.3.10

- Fix `apolloApiUrl` setting to work with all `rover` commands. This is primarily for internal Apollo debugging purposes against pre-prod environments of GraphOS.
Expand Down
117 changes: 72 additions & 45 deletions src/workbench/diagnosticsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { getFileName } from '../utils/path';
import { ApolloRemoteSchemaProvider } from './docProviders';
import { existsSync, readFileSync } from 'fs';
import { resolvePath } from '../utils/uri';
import { buildSchema } from 'graphql';
import { buildSubgraphSchema } from '@apollo/subgraph';
import gql from 'graphql-tag';

interface WorkbenchDiagnosticCollections {
compositionDiagnostics: DiagnosticCollection;
Expand Down Expand Up @@ -115,51 +118,75 @@ export class WorkbenchDiagnostics {
const error = errors[i];
const errorMessage = error.message;

if (error.nodes && error.nodes.length > 0)
error.nodes.forEach((errorNode) => {
let subgraphName = errorNode.subgraph;
if (!subgraphName && errorMessage.slice(0, 1) == '[') {
subgraphName = errorMessage.split(']')[0].split('[')[1];
} else if (!subgraphName) {
Object.keys(wbFile.subgraphs).forEach((subgraph) => {
const schema = wbFile.subgraphs[subgraph].schema;
let schemaPath: Uri;
if (schema.workbench_design) {
schemaPath = resolvePath(schema.workbench_design);
} else if (schema.file) {
schemaPath = resolvePath(schema.file);
} else {
schemaPath = ApolloRemoteSchemaProvider.Uri(
wbFilePath,
subgraphName,
);
}
if (existsSync(schemaPath.fsPath)) {
const typeDefs = readFileSync(schemaPath.fsPath, {
encoding: 'utf-8',
});
if (errorNode.source == typeDefs) subgraphName = subgraph;
}
});

if (!subgraphName) subgraphName = getFileName(wbFilePath);
}

const range = new Range(
errorNode.start ? errorNode.start.line - 1 : 0,
errorNode.start ? errorNode.start.column - 1 : 0,
errorNode.end ? errorNode.end.line - 1 : 0,
errorNode.start && errorNode.end
? errorNode.start.column + errorNode.end.column - 1
: 0,
);
const diagnostic = this.generateDiagnostic(errorMessage, range);

if (!diagnosticsGroups[subgraphName])
diagnosticsGroups[subgraphName] = [diagnostic];
else diagnosticsGroups[subgraphName].push(diagnostic);
});
else {
if (error.nodes && error.nodes.length > 0) {
if (error.code == 'INVALID_GRAPHQL') {
console.log(error);
error.nodes.forEach((errorNode) => {
const subgraphName = errorNode.subgraph;
try {
buildSubgraphSchema({ typeDefs: gql(errorNode.source) });
} catch (error) {
console.log(error);
const location = (error as any)?.locations[0];
const range = new Range(
location.line - 1,
location.column - 1,
location.line - 1,
location.column - 1,
);
const diagnostic = this.generateDiagnostic(errorMessage, range);

if (!diagnosticsGroups[subgraphName])
diagnosticsGroups[subgraphName] = [diagnostic];
else diagnosticsGroups[subgraphName].push(diagnostic);
}
});
} else {
error.nodes.forEach((errorNode) => {
let subgraphName = errorNode.subgraph;
if (!subgraphName && errorMessage.slice(0, 1) == '[') {
subgraphName = errorMessage.split(']')[0].split('[')[1];
} else if (!subgraphName) {
Object.keys(wbFile.subgraphs).forEach((subgraph) => {
const schema = wbFile.subgraphs[subgraph].schema;
let schemaPath: Uri;
if (schema.workbench_design) {
schemaPath = resolvePath(schema.workbench_design);
} else if (schema.file) {
schemaPath = resolvePath(schema.file);
} else {
schemaPath = ApolloRemoteSchemaProvider.Uri(
wbFilePath,
subgraphName,
);
}
if (existsSync(schemaPath.fsPath)) {
const typeDefs = readFileSync(schemaPath.fsPath, {
encoding: 'utf-8',
});
if (errorNode.source == typeDefs) subgraphName = subgraph;
}
});

if (!subgraphName) subgraphName = getFileName(wbFilePath);
}

const range = new Range(
errorNode.start ? errorNode.start.line - 1 : 0,
errorNode.start ? errorNode.start.column - 1 : 0,
errorNode.end ? errorNode.end.line - 1 : 0,
errorNode.start && errorNode.end
? errorNode.start.column + errorNode.end.column - 1
: 0,
);
const diagnostic = this.generateDiagnostic(errorMessage, range);

if (!diagnosticsGroups[subgraphName])
diagnosticsGroups[subgraphName] = [diagnostic];
else diagnosticsGroups[subgraphName].push(diagnostic);
});
}
} else {
const diagnostic = this.generateDiagnostic(errorMessage);

if (!diagnosticsGroups[wbFilePath])
Expand Down

0 comments on commit 26d48c0

Please sign in to comment.