Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Greenkeeper/eslint plugin babel 5.1.0 #232

Closed
Show file tree
Hide file tree
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: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module.exports = {
atom: false,
document: false,
window: false,
Map: true,
Set: true
},

rules: {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "1.0.18"
"version": "1.1.2"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@
"chai": "4.1.2",
"eslint": "4.14.0",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-babel": "4.1.2",
"eslint-plugin-babel": "5.1.0",
"eslint-plugin-dependencies": "2.4.0",
"eslint-plugin-flowtype": "2.40.1",
"eslint-plugin-prefer-object-spread": "1.2.1",
"fetch-mock": "^6.0.0",
"flow-bin": "0.62.0",
"graphql": "^0.12.3",
"graphql-language-service-interface": "^1.0.0-0",
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql-language-service/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graphql-language-service",
"repository": "https://github.com/graphql/graphql-language-service",
"version": "1.0.18",
"version": "1.1.2",
"description": "An interface for building GraphQL language services for IDEs",
"contributors": [
"Hyohyeon Jeong <[email protected]>",
Expand Down Expand Up @@ -34,9 +34,9 @@
"dependencies": {
"babel-polyfill": "6.16.0",
"graphql-config": "1.1.4",
"graphql-language-service-interface": "^1.0.18",
"graphql-language-service-server": "^1.0.18",
"graphql-language-service-utils": "^1.0.18",
"graphql-language-service-interface": "^1.1.0",
"graphql-language-service-server": "^1.1.2",
"graphql-language-service-utils": "^1.1.0",
"yargs": "^3.32.0 || ^7.0.0"
}
}
8 changes: 4 additions & 4 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "graphql-language-service-interface",
"repository": "https://github.com/graphql/graphql-language-service",
"version": "1.0.18",
"version": "1.1.0",
"description": "Interface to the GraphQL Language Service",
"contributors": [
"Greg Hurrell <[email protected]> (https://greg.hurrell.net/)",
Expand Down Expand Up @@ -30,8 +30,8 @@
},
"dependencies": {
"graphql-config": "1.1.4",
"graphql-language-service-parser": "^1.0.18",
"graphql-language-service-types": "^1.0.18",
"graphql-language-service-utils": "^1.0.18"
"graphql-language-service-parser": "^1.1.0",
"graphql-language-service-types": "^1.1.0",
"graphql-language-service-utils": "^1.1.0"
}
}
47 changes: 31 additions & 16 deletions packages/interface/src/GraphQLLanguageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
Uri,
} from 'graphql-language-service-types';
import type {Position} from 'graphql-language-service-utils';
import type {Hover} from 'vscode-languageserver-types';

import {
FRAGMENT_DEFINITION,
Expand All @@ -46,6 +47,7 @@ import {

import {parse, print} from 'graphql';
import {getAutocompleteSuggestions} from './getAutocompleteSuggestions';
import {getHoverInformation} from './getHoverInformation';
import {validateQuery, getRange, SEVERITY} from './getDiagnostics';
import {
getDefinitionQueryResultForFragmentSpread,
Expand Down Expand Up @@ -107,10 +109,6 @@ export class GraphQLLanguageService {
];
}

if (!schemaPath) {
return [];
}

// If there's a matching config, proceed to prepare to run validation
let source = query;
const fragmentDefinitions = await this._graphQLCache.getFragmentDefinitions(
Expand Down Expand Up @@ -138,11 +136,6 @@ export class GraphQLLanguageService {
return [];
}

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

// Check if there are custom validation rules to be used
let customRules;
const customRulesModulePath =
Expand All @@ -156,6 +149,14 @@ export class GraphQLLanguageService {
/* eslint-enable no-implicit-coercion */
}

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

if (!schema) {
return [];
}

return validateQuery(validationAst, schema, customRules, isRelayCompatMode);
}

Expand All @@ -165,18 +166,32 @@ export class GraphQLLanguageService {
filePath: Uri,
): Promise<Array<CompletionItem>> {
const projectConfig = this._graphQLConfig.getConfigForFile(filePath);
if (projectConfig.schemaPath) {
const schema = await this._graphQLCache.getSchema(
projectConfig.projectName,
);
const schema = await this._graphQLCache
.getSchema(projectConfig.projectName)
.catch(() => null);

if (schema) {
return getAutocompleteSuggestions(schema, query, position);
}
if (schema) {
return getAutocompleteSuggestions(schema, query, position);
}
return [];
}

async getHoverInformation(
query: string,
position: Position,
filePath: Uri,
): Promise<Hover.contents> {
const projectConfig = this._graphQLConfig.getConfigForFile(filePath);
const schema = await this._graphQLCache
.getSchema(projectConfig.projectName)
.catch(() => null);

if (schema) {
return getHoverInformation(schema, query, position);
}
return '';
}

async getDefinition(
query: string,
position: Position,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
schema {
query: Query
}

""" This is type documentation for Chicken """
scalar Chicken

""" docs for color """
enum Color {
RED
GREEN
BLUE
}

union UnionType = String | Float | Boolean

interface TestInterface {
id: String!
}

""" This is type documentation for TestType """
type TestType implements TestInterface {
""" This is field documentation for TestType.testField """
testField: String
testDeprecatedField: Float @deprecated(reason: "deprecation reason")
testEnumField: Color
}

type Query {

""" This is field documentation for Query.thing """
thing: TestType
listOfThing: [TestType!]
parameterizedField(id: String!): TestType
cluck: Chicken
unionField: UnionType
}
119 changes: 119 additions & 0 deletions packages/interface/src/__tests__/getHoverInformation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Copyright (c) Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {Hover} from 'vscode-languageserver-types';

import {expect} from 'chai';
import {beforeEach, describe, it} from 'mocha';
import fs from 'fs';
import {buildSchema} from 'graphql';
import {Position} from 'graphql-language-service-utils';
import path from 'path';

import {getHoverInformation} from '../getHoverInformation';

describe('getHoverInformation', () => {
let schema;
beforeEach(async () => {
const schemaIDL = fs.readFileSync(
path.join(__dirname, '__schema__/HoverTestSchema.graphql'),
'utf8',
);
schema = buildSchema(schemaIDL);
});

function testHover(query: string, point: Position): Hover.contents {
return getHoverInformation(schema, query, point);
}

it('provides leaf field information', () => {
const actual = testHover(
'query { thing { testField } }',
new Position(0, 20),
);
expect(actual).to.deep.equal(
'TestType.testField: String\n\n This is field documentation for TestType.testField',
);
});

it('provides aliased field information', () => {
const actual = testHover(
'query { thing { other: testField } }',
new Position(0, 25),
);
expect(actual).to.deep.equal(
'TestType.testField: String\n\n This is field documentation for TestType.testField',
);
});

it('provides intermediate field information', () => {
const actual = testHover(
'query { thing { testField } }',
new Position(0, 10),
);
expect(actual).to.deep.equal(
'Query.thing: TestType\n\n This is field documentation for Query.thing',
);
});

it('provides list field information', () => {
const actual = testHover(
'query { listOfThing { testField } }',
new Position(0, 10),
);
expect(actual).to.deep.equal('Query.listOfThing: [TestType!]');
});

it('provides deprecated field information', () => {
const actual = testHover(
'query { thing { testDeprecatedField } }',
new Position(0, 20),
);
expect(actual).to.deep.equal(
'TestType.testDeprecatedField: Float\n\nDeprecated: deprecation reason',
);
});

it('provides enum field information', () => {
const actual = testHover(
'query { thing { testEnumField } }',
new Position(0, 20),
);
expect(actual).to.deep.equal('TestType.testEnumField: Color');
});

it('provides scalar field information', () => {
const actual = testHover('query { cluck }', new Position(0, 10));
expect(actual).to.deep.equal('Query.cluck: Chicken');
});

it('provides parameter type information', () => {
const actual = testHover(
'query { parameterizedField(id: "foo") { testField } }',
new Position(0, 28),
);
expect(actual).to.deep.equal('Query.parameterizedField(id: String!)');
});

it('provides directive information', () => {
const actual = testHover(
'query { thing { testField @skip(if:true) } }',
new Position(0, 30),
);
expect(actual).to.deep.equal(
'@skip\n\nDirects the executor to skip this field or fragment when the `if` argument is true.',
);
});

it('provides union information', () => {
const actual = testHover('query { unionField }', new Position(0, 12));
expect(actual).to.deep.equal('Query.unionField: UnionType');
});
});
10 changes: 8 additions & 2 deletions packages/interface/src/getAutocompleteSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ function getSuggestionsForDirective(
return [];
}

function getTokenAtPosition(queryText: string, cursor: Position): ContextToken {
export function getTokenAtPosition(
queryText: string,
cursor: Position,
): ContextToken {
let styleAtCursor = null;
let stateAtCursor = null;
let stringAtCursor = null;
Expand Down Expand Up @@ -513,7 +516,10 @@ function canUseDirective(

// Utility for collecting rich type information given any token's state
// from the graphql-mode parser.
function getTypeInfo(schema: GraphQLSchema, tokenState: State): TypeInfo {
export function getTypeInfo(
schema: GraphQLSchema,
tokenState: State,
): TypeInfo {
let argDef;
let argDefs;
let directiveDef;
Expand Down
Loading