Skip to content

Commit

Permalink
chore: more ts conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Sep 20, 2019
1 parent 415a957 commit 1d42bfe
Show file tree
Hide file tree
Showing 27 changed files with 6,040 additions and 2,273 deletions.
19 changes: 12 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
const path = require('path');
const { jsWithTs: tsjPreset } = require('ts-jest/presets');
const { jsWithBabel: jsWithBabelPreset } = require('ts-jest/presets');

module.exports = {
globals: {
'ts-jest': {
tsConfig: './tsconfig.base.json'
}
},
verbose: true,
clearMocks: true,
collectCoverage: true,
setupFiles: [path.join(__dirname, '/resources/enzyme.config.js')],
testMatch: [
'<rootDir>/packages/*/src/**/*-test.js',
'<rootDir>/packages/*/src/**/*.spec.js',
'<rootDir>/packages/*/src/**/*-test.{js,ts}',
'<rootDir>/packages/*/src/**/*.spec.{js,ts}',
],
transform: {
'^.+\\.jsx?$': require.resolve('./resources/jestBabelTransform'),
...tsjPreset.transform,
...jsWithBabelPreset.transform
},
testEnvironment: require.resolve('jest-environment-jsdom-global'),
testPathIgnorePatterns: [
'node_modules',
'dist',
'codemirror-graphql',
],
testPathIgnorePatterns: ['node_modules', 'dist', 'codemirror-graphql'],
collectCoverageFrom: [
'**/src/**/*.{js,jsx}',
'!**/node_modules/**',
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"pretty": "node resources/pretty.js",
"pretty-check": "node resources/pretty.js --check",
"version:release": "lerna version",
"version:prerelease": "lerna versiton --conventional-prerelease",
"version:prerelease": "lerna version --conventional-prerelease",
"version:graduate": "lerna version --conventional-graduate"
},
"devDependencies": {
Expand All @@ -51,8 +51,8 @@
"@types/jest": "^24.0.18",
"babel-eslint": "^10.0.1",
"chai": "4.2.0",
"conventional-changelog-conventionalcommits": "^4.1.0",
"codecov": "^3.5.0",
"conventional-changelog-conventionalcommits": "^4.1.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "4.3.0",
"eslint-plugin-babel": "5.3.0",
Expand All @@ -64,12 +64,13 @@
"flow-bin": "^0.101.0",
"graphql": "^14.5.2",
"husky": "^3.0.5",
"lerna": "^3.16.4",
"mocha": "6.1.4",
"jest": "^24.8.0",
"jest-environment-jsdom": "^24.8.0",
"jest-environment-jsdom-global": "^1.2.0",
"lerna": "^3.16.4",
"mocha": "6.1.4",
"prettier": "^1.18.2",
"ts-jest": "^24.1.0",
"typescript": "^3.6.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import {
GraphQLConfig,
GraphQLProjectConfig,
Uri,
Position
} from 'graphql-language-service-types';

import { Position } from 'graphql-language-service-utils';
// import { Position } from 'graphql-language-service-utils';
import { Hover } from 'vscode-languageserver-types';

import { Kind, parse, print } from 'graphql';
Expand Down Expand Up @@ -69,6 +70,14 @@ export class GraphQLLanguageService {
this._graphQLConfig = cache.getGraphQLConfig();
}

getConfigForURI(uri: Uri) {
const config = this._graphQLConfig.getConfigForFile(uri);
if (config) {
return config;
}
throw Error(`No config found for uri: ${uri}`);
}

async getDiagnostics(
query: string,
uri: Uri,
Expand All @@ -77,10 +86,9 @@ export class GraphQLLanguageService {
// Perform syntax diagnostics first, as this doesn't require
// schema/fragment definitions, even the project configuration.
let queryHasExtensions = false;
const projectConfig = this._graphQLConfig.getConfigForFile(
uri,
) as GraphQLProjectConfig;
const schemaPath = projectConfig.schemaPath;
const projectConfig = this.getConfigForURI(uri);
const { schemaPath, projectName, extensions } = projectConfig;

try {
const queryAST = parse(query);
if (!schemaPath || uri !== schemaPath) {
Expand Down Expand Up @@ -148,8 +156,7 @@ export class GraphQLLanguageService {

// Check if there are custom validation rules to be used
let customRules;
const customRulesModulePath =
projectConfig.extensions.customValidationRules;
const customRulesModulePath = extensions.customValidationRules;
if (customRulesModulePath) {
/* eslint-disable no-implicit-coercion */
const rulesPath = require.resolve(`${customRulesModulePath}`);
Expand All @@ -160,7 +167,7 @@ export class GraphQLLanguageService {
}

const schema = await this._graphQLCache
.getSchema(projectConfig.projectName, queryHasExtensions)
.getSchema(projectName, queryHasExtensions)
.catch(() => null);

if (!schema) {
Expand All @@ -175,9 +182,7 @@ export class GraphQLLanguageService {
position: Position,
filePath: Uri,
): Promise<Array<CompletionItem>> {
const projectConfig = this._graphQLConfig.getConfigForFile(
filePath,
) as GraphQLProjectConfig;
const projectConfig = this.getConfigForURI(filePath);
const schema = await this._graphQLCache
.getSchema(projectConfig.projectName)
.catch(() => null);
Expand All @@ -193,9 +198,7 @@ export class GraphQLLanguageService {
position: Position,
filePath: Uri,
): Promise<Hover['contents']> {
const projectConfig = this._graphQLConfig.getConfigForFile(
filePath,
) as GraphQLProjectConfig;
const projectConfig = this.getConfigForURI(filePath);
const schema = await this._graphQLCache
.getSchema(projectConfig.projectName)
.catch(() => null);
Expand All @@ -211,9 +214,7 @@ export class GraphQLLanguageService {
position: Position,
filePath: Uri,
): Promise<DefinitionQueryResult | null | undefined> {
const projectConfig = this._graphQLConfig.getConfigForFile(
filePath,
) as GraphQLProjectConfig;
const projectConfig = this.getConfigForURI(filePath);

let ast;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
*/

import { Position } from 'graphql-language-service-types'
import { join } from 'path';
import * as fs from 'fs';
import { buildSchema } from 'graphql';
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('GraphQLLanguageService', () => {
},
};

let languageService;
let languageService: GraphQLLanguageService;
beforeEach(() => {
languageService = new GraphQLLanguageService(mockCache);
});
Expand Down Expand Up @@ -100,7 +101,7 @@ describe('GraphQLLanguageService', () => {
it('runs hover service as expected', async () => {
const hoverInformation = await languageService.getHoverInformation(
'type Query { hero(episode: String): String }',
{ line: 0, character: 28 },
{ line: 0, character: 28 } as Position,
'./queries/definitionQuery.graphql',
);
expect(hoverInformation).toEqual(
Expand Down

0 comments on commit 1d42bfe

Please sign in to comment.