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

update to GraphQL 17 #2439

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/cm6-graphql-parcel/package.json
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
"@codemirror/language": "^0.20.0",
"codemirror-graphql": "file:../../packages/codemirror-graphql",
"graphql": "^16.4.0",
"typescript": "^4.1.3"
"typescript": "^4.6.3"
},
"devDependencies": {
"parcel-bundler": "^1.12.4",
2 changes: 1 addition & 1 deletion examples/graphiql-parcel/package.json
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
"graphql": "^16.4.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"typescript": "^3.4.4"
"typescript": "^4.6.3"
},
"devDependencies": {
"parcel": "^2.5.0",
2 changes: 1 addition & 1 deletion examples/monaco-graphql-webpack/package.json
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
"monaco-editor-webpack-plugin": "^5.0.0",
"react-dom": "^17.0.2",
"style-loader": "^1.1.3",
"typescript": "^4.1.3",
"typescript": "^4.6.3",
"webpack": "4.42.1",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3",
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -140,8 +140,11 @@
"serverless-http": "^2.7.0",
"ts-jest": "^25.3.1",
"typedoc": "^0.19.2",
"typescript": "^4.1.3",
"typescript": "^4.6.3",
"whatwg-url": "^8.4.0",
"wsrun": "^5.2.4"
},
"resolutions": {
"graphql": "17.0.0-alpha.1"
}
}
12 changes: 11 additions & 1 deletion packages/codemirror-graphql/src/utils/jsonParse.ts
Original file line number Diff line number Diff line change
@@ -155,8 +155,18 @@ function expect(str: string) {
throw syntaxError(`Expected ${str} but found ${found}.`);
}

type SyntaxErrorPosition = { start: number; end: number };

export class JSONSyntaxError extends Error {
readonly position: SyntaxErrorPosition;
constructor(message: string, position: SyntaxErrorPosition) {
super(message);
this.position = position;
}
}

function syntaxError(message: string) {
return { message, start, end };
return new JSONSyntaxError(message, { start, end });
}

function skip(k: string) {
9 changes: 5 additions & 4 deletions packages/codemirror-graphql/src/variables/lint.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import {
} from 'graphql';

import jsonParse, {
JSONSyntaxError,
ParseArrayOutput,
ParseObjectOutput,
ParseValueOutput,
@@ -57,11 +58,11 @@ CodeMirror.registerHelper(
let ast;
try {
ast = jsonParse(text);
} catch (syntaxError) {
if (syntaxError.stack) {
throw syntaxError;
} catch (error) {
if (error instanceof JSONSyntaxError) {
return [lintError(editor, error.position, error.message)];
}
return [lintError(editor, syntaxError, syntaxError.message)];
throw error;
}

// If there are not yet known variables, do nothing.
2 changes: 1 addition & 1 deletion packages/graphiql-2-rfc-context/package.json
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@
"start-server-and-test": "^1.10.11",
"style-loader": "^1.1.3",
"ts-loader": "^7.0.0",
"typescript": "^4.1.3",
"typescript": "^4.6.3",
"webpack": "4.42.1",
"webpack-bundle-analyzer": "^3.6.1",
"webpack-cli": "^3.3.11",
2 changes: 1 addition & 1 deletion packages/graphiql/package.json
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@
"style-loader": "^1.1.3",
"subscriptions-transport-ws": "0.11.0",
"ts-loader": "^7.0.0",
"typescript": "^4.1.3",
"typescript": "^4.6.3",
"webpack": "^4.42.1",
"webpack-bundle-analyzer": "^3.6.1",
"webpack-cli": "^3.3.11",
6 changes: 5 additions & 1 deletion packages/graphiql/src/components/ToolbarButton.tsx
Original file line number Diff line number Diff line change
@@ -49,7 +49,11 @@ export class ToolbarButton extends React.Component<
this.props.onClick();
this.setState({ error: null });
} catch (error) {
this.setState({ error });
if (error instanceof Error) {
this.setState({ error });
return;
}
throw error;
}
};
}
2 changes: 1 addition & 1 deletion packages/graphql-language-service-cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ switch (command) {
startServer(options);
} catch (error) {
const logger = new Logger();
logger.error(error);
logger.error(String(error));
}
break;
default: {
16 changes: 12 additions & 4 deletions packages/graphql-language-service-cli/src/client.ts
Original file line number Diff line number Diff line change
@@ -79,6 +79,14 @@ interface AutocompleteResultsMap {
[i: number]: CompletionItem;
}

function formatUnknownError(error: unknown) {
let message: string | undefined;
if (error instanceof Error) {
message = error.stack;
}
return message ?? String(error);
}

function _getAutocompleteSuggestions(
queryText: string,
point: Position,
@@ -104,7 +112,7 @@ function _getAutocompleteSuggestions(
process.stdout.write(JSON.stringify(resultObject, null, 2));
return GRAPHQL_SUCCESS_CODE;
} catch (error) {
process.stderr.write((error?.stack ?? String(error)) + '\n');
process.stderr.write(formatUnknownError(error) + '\n');
return GRAPHQL_FAILURE_CODE;
}
}
@@ -133,7 +141,7 @@ function _getDiagnostics(
process.stdout.write(JSON.stringify(resultObject, null, 2));
return GRAPHQL_SUCCESS_CODE;
} catch (error) {
process.stderr.write((error?.stack ?? String(error)) + '\n');
process.stderr.write(formatUnknownError(error) + '\n');
return GRAPHQL_FAILURE_CODE;
}
}
@@ -147,7 +155,7 @@ function _getOutline(queryText: string): EXIT_CODE {
throw Error('Error parsing or no outline tree found');
}
} catch (error) {
process.stderr.write((error?.stack ?? String(error)) + '\n');
process.stderr.write(formatUnknownError(error) + '\n');
return GRAPHQL_FAILURE_CODE;
}
return GRAPHQL_SUCCESS_CODE;
@@ -161,7 +169,7 @@ function ensureText(queryText: string, filePath: string): string {
try {
text = fs.readFileSync(filePath, 'utf8');
} catch (error) {
throw new Error(error);
throw new Error(String(error));
}
}
return text;
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import {
TypeDefinitionNode,
NamedTypeNode,
ValidationRule,
GraphQLError,
} from 'graphql';

import {
@@ -153,15 +154,22 @@ export class GraphQLLanguageService {
});
}
} catch (error) {
const range = getRange(error.locations[0], document);
return [
{
severity: DIAGNOSTIC_SEVERITY.Error,
message: error.message,
source: 'GraphQL: Syntax',
range,
},
];
if (error instanceof GraphQLError) {
const range = getRange(
error.locations?.[0] ?? { column: 0, line: 0 },
document,
);
return [
{
severity: DIAGNOSTIC_SEVERITY.Error,
message: error.message,
source: 'GraphQL: Syntax',
range,
},
];
}

throw error;
}

// If there's a matching config, proceed to prepare to run validation
Original file line number Diff line number Diff line change
@@ -256,7 +256,7 @@ export class MessageProcessor {
}
}
} catch (err) {
this._logger.warn(err);
this._logger.warn(String(err));
}

// Here, we set the workspace settings in memory,
@@ -834,7 +834,7 @@ export class MessageProcessor {
await this._updateObjectTypeDefinition(uri, contents);
}
} catch (err) {
this._logger.error(err);
this._logger.error(String(err));
}
}
async _cacheSchemaFile(
@@ -1002,7 +1002,7 @@ export class MessageProcessor {
}
}
} catch (err) {
this._logger.error(err);
this._logger.error(String(err));
}
}
/**
@@ -1043,7 +1043,7 @@ export class MessageProcessor {
this._logger.error(
`invalid/unknown file in graphql config documents entry:\n '${project.documents}'`,
);
this._logger.error(err);
this._logger.error(String(err));
}
}
/**
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ export function findGraphQLTags(
logger.error(
`Could not parse the ${type} file at ${uri} to extract the graphql tags:`,
);
logger.error(error);
logger.error(String(error));
return [];
}
const ast = parsedAST!;
4 changes: 2 additions & 2 deletions packages/graphql-language-service-server/src/startServer.ts
Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@ export default async function startServer(
serverWithHandlers.listen();
} catch (err) {
logger.error('There was a Graphql LSP handler exception:');
logger.error(err);
logger.error(String(err));
}
}
}
@@ -236,7 +236,7 @@ async function initializeHandlers({
return connection;
} catch (err) {
logger.error('There was an error initializing the server connection');
logger.error(err);
logger.error(String(err));
process.exit(1);
}
}
2 changes: 1 addition & 1 deletion packages/graphql-language-service/package.json
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@
"lodash": "^4.17.15",
"platform": "^1.3.5",
"ts-node": "^8.10.2",
"typescript": "^4.1.3"
"typescript": "^4.6.3"
},
"scripts": {
"benchmark": "ts-node benchmark/index.ts"
25 changes: 16 additions & 9 deletions packages/graphql-language-service/src/interface/getDiagnostics.ts
Original file line number Diff line number Diff line change
@@ -81,15 +81,22 @@ export function getDiagnostics(
try {
ast = parse(query);
} catch (error) {
const range = getRange(error.locations[0], query);
return [
{
severity: DIAGNOSTIC_SEVERITY.Error as DiagnosticSeverity,
message: error.message,
source: 'GraphQL: Syntax',
range,
},
];
if (error instanceof GraphQLError) {
const range = getRange(
error.locations?.[0] ?? { line: 0, column: 0 },
query,
);

return [
{
severity: DIAGNOSTIC_SEVERITY.Error as DiagnosticSeverity,
message: error.message,
source: 'GraphQL: Syntax',
range,
},
];
}
throw error;
}

return validateQuery(ast, schema, customRules, isRelayCompatMode);
2 changes: 1 addition & 1 deletion packages/graphql-language-service/src/parser/Rules.ts
Original file line number Diff line number Diff line change
@@ -196,7 +196,7 @@ export const ParseRules: { [name: string]: ParseRule } = {
StringValue: [
{
style: 'string',
match: token => token.kind === 'String',
match: (token: Token) => token.kind === 'String',
update(state: State, token: Token) {
if (token.value.startsWith('"""')) {
state.inBlockstring = !token.value.slice(3).endsWith('"""');
18 changes: 4 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -12457,15 +12457,10 @@ graphql-ws@^5.4.1, graphql-ws@^5.5.5:
resolved "https://registry.yarnpkg.com/graphql-ws/-/graphql-ws-5.5.5.tgz#f375486d3f196e2a2527b503644693ae3a8670a9"
integrity sha512-hvyIS71vs4Tu/yUYHPvGXsTgo0t3arU820+lT5VjZS2go0ewp2LqyCgxEN56CzOG7Iys52eRhHBiD1gGRdiQtw==

[email protected]:
version "16.0.0-experimental-stream-defer.5"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.0.0-experimental-stream-defer.5.tgz#d668566fd33053a054dc5367c38c20a4ac4e4224"
integrity sha512-bluMjYpxh3a1lwZuNP+FAaEDMWzccVhkv+STcw0ckB2EPtLRTYUdXQhF9YBbUHd3tZSAR7LXzsxIw2GZXhg5rw==

graphql@^16.1.0, graphql@^16.4.0:
version "16.5.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.5.0.tgz#41b5c1182eaac7f3d47164fb247f61e4dfb69c85"
integrity sha512-qbHgh8Ix+j/qY+a/ZcJnFQ+j8ezakqPiHwPiZhV/3PgGlgf96QMBB5/f2rkiC9sgLoy/xvT6TSiaf2nTHJh5iA==
[email protected], [email protected], graphql@^16.1.0, graphql@^16.4.0:
version "17.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-17.0.0-alpha.1.tgz#e20c7ebd2c093274a01ccd7c37982f99a84dfe94"
integrity sha512-D59afb/GOC2ie47EONn574mVU5mjUPOyplPGME5US0rZBEIPLbzFdp8OBWX6uo9PqySDMnEjYp0OtfKjk0wjig==

growly@^1.3.0:
version "1.3.0"
@@ -21533,11 +21528,6 @@ typedoc@^0.19.2:
shelljs "^0.8.4"
typedoc-default-themes "^0.11.4"

typescript@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==

typescript@^4.6.3:
version "4.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"