Skip to content

Commit

Permalink
pnpm mode WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Feb 25, 2023
1 parent 9b8d603 commit 856f755
Show file tree
Hide file tree
Showing 27 changed files with 17,219 additions and 17,488 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
ecmaVersion: 6,
},
settings: {
'import/resolver': {
typescript: true,
node: true
},
react: {
version: 'detect',
},
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
engine-strict=true
access=public
auto-install-peers=true
2 changes: 1 addition & 1 deletion functions/schema-demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* example using https://github.com/awslabs/aws-serverless-express */
const express = require('express');
// eslint-disable-next-line import/no-extraneous-dependencies
const { graphqlHTTP } = require('express-graphql');
const awsServerlessExpress = require('aws-serverless-express');
const schema = require('../packages/graphiql/test/schema');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"execa": "^6.0.0",
"express": "^4.17.3",
"fetch-mock": "6.5.2",
"husky": "^4.2.3",
"husky": "^4.3.8",
"jest": "^27.5.1",
"js-green-licenses": "3.0.0",
"lint-staged": "^10.1.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/codemirror-graphql/src/variables/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

import CodeMirror, { Hints } from 'codemirror';
import { default as CodeMirror } from 'codemirror';
import type { Hints } from 'codemirror'
import {
getNullableType,
getNamedType,
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/response-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formatError } from '@graphiql/toolkit';
import type { Position, Token } from 'codemirror';
import { ComponentType, useEffect, useRef } from 'react';
import ReactDOM from 'react-dom';
import * as ReactDOM from 'react-dom';
import { useSchemaContext } from '../schema';

import {
Expand Down
3 changes: 2 additions & 1 deletion packages/graphiql/__mocks__/@graphiql/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
useResponseEditor as _useResponseEditor,
useVariableEditor as _useVariableEditor,
} from '@graphiql/react';
import React, { useEffect, useRef, useState } from 'react';
import * as React from 'react'
import { useEffect, useRef, useState } from 'react';

export {
Argument,
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql/src/components/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React, {
import * as React from 'react'
import {
ComponentType,
PropsWithChildren,
ReactNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import '@testing-library/jest-dom';
import { act, render, waitFor, fireEvent } from '@testing-library/react';
import React from 'react';
import * as React from 'react';
import { GraphiQL } from '../GraphiQL';
import { Fetcher } from '@graphiql/toolkit';
import { ToolbarButton } from '@graphiql/react';
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/test/afterDevServer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { useServer } = require('graphql-ws/lib/use/ws');
const { Server: WebSocketServer } = require('ws');
const schema = require('./schema');
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-language-service-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"graphql": "^15.5.0 || ^16.0.0"
},
"dependencies": {
"@types/yargs": "^16.0.0",
"@babel/polyfill": "^7.12.1",
"graphql-language-service": "^5.1.1",
"graphql-language-service-server": "^2.9.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/glob": "^8.1.0",
"cross-env": "^7.0.2",
"graphql": "^16.4.0",
"cross-fetch": "^3.1.5"
"cross-fetch": "^3.1.5",
"vscode-languageserver-protocol": "^3.17.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { UnnormalizedTypeDefPointer } from '@graphql-tools/load';

import { parseDocument } from './parseDocument';
import stringToHash from './stringToHash';
import glob from 'glob';
import * as glob from 'glob';
import { LoadConfigOptions } from './types';
import { URI } from 'vscode-uri';
import { Logger } from './Logger';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
*
*/

import {
AutocompleteSuggestionOptions,
CompletionItem,
} from 'graphql-language-service';

import fs from 'node:fs';
import {
buildSchema,
Expand All @@ -23,7 +18,13 @@ import {
import { Position } from '../../utils';
import path from 'node:path';

import { getAutocompleteSuggestions } from '../getAutocompleteSuggestions';
import {
getAutocompleteSuggestions,
AutocompleteSuggestionOptions,

} from '../getAutocompleteSuggestions';

import { CompletionItem } from '../../types'

const expectedResults = {
droid: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Hover } from 'vscode-languageserver-types';

import fs from 'node:fs';
import { buildSchema, GraphQLSchema } from 'graphql';
import { Position } from 'graphql-language-service';
import { Position } from '../../';
import path from 'node:path';

import { getHoverInformation } from '../getHoverInformation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import { getTokenAtPosition, getTypeInfo } from './getAutocompleteSuggestions';

export type HoverConfig = { useMarkdown?: boolean };

export type HoverContents = Hover['contents']

export function getHoverInformation(
schema: GraphQLSchema,
queryText: string,
cursor: IPosition,
contextToken?: ContextToken,
config?: HoverConfig,
): Hover['contents'] {
): HoverContents {
const token = contextToken || getTokenAtPosition(queryText, cursor);

if (!schema || !token || !token.state) {
Expand Down
14 changes: 8 additions & 6 deletions packages/monaco-graphql/src/GraphQLWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { FormattingOptions, ICreateData, SchemaConfig } from './typings';

import type { worker, Position } from 'monaco-editor';
import type * as monaco from 'monaco-editor';

import { getRange } from 'graphql-language-service';

Expand All @@ -20,16 +20,18 @@ import {
toCompletion,
GraphQLWorkerCompletionItem,
} from './utils';
import { HoverContents } from 'graphql-language-service/src/interface/getHoverInformation';

export type MonacoCompletionItem = monaco.languages.CompletionItem & {
isDeprecated?: boolean;
deprecationReason?: string | null;
};

export class GraphQLWorker {
private _ctx: worker.IWorkerContext;
private _ctx: monaco.worker.IWorkerContext;
private _languageService: LanguageService;
private _formattingOptions: FormattingOptions | undefined;
constructor(ctx: worker.IWorkerContext, createData: ICreateData) {
constructor(ctx: monaco.worker.IWorkerContext, createData: ICreateData) {
this._ctx = ctx;
this._languageService = new LanguageService(createData.languageConfig);
this._formattingOptions = createData.formattingOptions;
Expand All @@ -56,7 +58,7 @@ export class GraphQLWorker {

public async doComplete(
uri: string,
position: Position,
position: monaco.Position,
): Promise<GraphQLWorkerCompletionItem[]> {
try {
const documentModel = this._getTextModel(uri);
Expand All @@ -78,7 +80,7 @@ export class GraphQLWorker {
}
}

public async doHover(uri: string, position: Position) {
public async doHover(uri: string, position: monaco.Position): Promise<{ content: HoverContents | undefined, range: monaco.IRange } | null> {
try {
const documentModel = this._getTextModel(uri);
const document = documentModel?.getValue();
Expand Down Expand Up @@ -173,7 +175,7 @@ export default {
};

export function create(
ctx: worker.IWorkerContext,
ctx: monaco.worker.IWorkerContext,
createData: ICreateData,
): GraphQLWorker {
return new GraphQLWorker(ctx, createData);
Expand Down
7 changes: 4 additions & 3 deletions packages/monaco-graphql/src/LanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

import picomatch from 'picomatch-browser';

import type { IPosition } from 'graphql-language-service';
import type { Diagnostic, IPosition } from 'graphql-language-service';
import {
getAutocompleteSuggestions,
getDiagnostics,
Expand All @@ -31,6 +31,7 @@ import {
import { defaultSchemaLoader } from './schemaLoader';

import { SchemaConfig, SchemaLoader, GraphQLLanguageConfig } from './typings';
import { HoverContents } from 'graphql-language-service/src/interface/getHoverInformation';

type SchemaCacheItem = Omit<SchemaConfig, 'schema'> & { schema: GraphQLSchema };

Expand Down Expand Up @@ -230,7 +231,7 @@ export class LanguageService {
uri: string,
documentText: string,
customRules?: ValidationRule[],
) => {
): Diagnostic[] => {
const schema = this.getSchemaForFile(uri);
if (!documentText || documentText.trim().length < 2 || !schema?.schema) {
return [];
Expand All @@ -249,7 +250,7 @@ export class LanguageService {
documentText: string,
position: IPosition,
options?: HoverConfig,
) => {
): HoverContents | undefined => {
const schema = this.getSchemaForFile(uri);
if (schema && documentText?.length > 3) {
return getHoverInformation(
Expand Down
3 changes: 1 addition & 2 deletions packages/monaco-graphql/src/typings/refs.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/// <reference path='../../../../node_modules/monaco-editor/monaco.d.ts'/>
/// <reference path='./monaco.d.ts'/>
/// <reference types='monaco-editor'/>
4 changes: 2 additions & 2 deletions packages/monaco-graphql/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import type {
Diagnostic,
CompletionItem as GraphQLCompletionItem,
} from 'graphql-language-service';
import type { editor } from 'monaco-editor';
import type * as monaco from 'monaco-editor';

import { buildASTSchema, printSchema } from 'graphql';

import { Position } from 'graphql-language-service';

// for backwards compatibility
export const getModelLanguageId = (model: editor.ITextModel) => {
export const getModelLanguageId = (model: monaco.editor.ITextModel) => {
if ('getModeId' in model) {
// for <0.30.0 support
// @ts-expect-error
Expand Down
8 changes: 4 additions & 4 deletions packages/monaco-graphql/src/workerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { editor as monacoEditor } from 'monaco-editor';
import { MonacoGraphQLAPI } from './api';
import { GraphQLWorker } from './GraphQLWorker';

import IDisposable = monaco.IDisposable;
import Uri = monaco.Uri;
import type * as monaco from 'monaco-editor'

import { ICreateData } from './typings';
import { getStringSchema } from './utils';

Expand All @@ -19,7 +19,7 @@ export class WorkerManager {
private _defaults: MonacoGraphQLAPI;
private _idleCheckInterval: number;
private _lastUsedTime: number;
private _configChangeListener: IDisposable;
private _configChangeListener: monaco.IDisposable;
private _worker: monaco.editor.MonacoWebWorker<GraphQLWorker> | null;
private _client: GraphQLWorker | null;

Expand Down Expand Up @@ -98,7 +98,7 @@ export class WorkerManager {
return this._client as GraphQLWorker;
}

async getLanguageServiceWorker(...resources: Uri[]): Promise<GraphQLWorker> {
async getLanguageServiceWorker(...resources: monaco.Uri[]): Promise<GraphQLWorker> {
const client = await this._getClient();
await this._worker!.withSyncedResources(resources);

Expand Down
1 change: 1 addition & 0 deletions packages/monaco-graphql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"rootDir": "./src",
"outDir": "./dist",
"target": "es5",
"typeRoots": ["./types"],
"lib": [
"dom",
"es5",
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-graphql-execution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"vsce": "^2.13.0"
},
"dependencies": {
"wonka": "4.0.15",
"@urql/core": "2.6.1",
"capitalize": "2.0.4",
"dotenv": "10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-graphql-execution/src/helpers/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { gql } from 'graphql-tag';
import { fetch } from '@whatwg-node/fetch';
import { Agent } from 'node:https';
import * as ws from 'ws';
// eslint-disable-next-line import/no-extraneous-dependencies
import { pipe, subscribe } from 'wonka';

// eslint-disable-next-line import/no-unresolved
Expand Down
Loading

0 comments on commit 856f755

Please sign in to comment.