diff --git a/.travis.yml b/.travis.yml index cf1b8b48..f5d72d43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ before_install: - node resources/hoistDependencies.js - mkdir -p node_modules - (cd node_modules && ln -s ../packages/graphql-language-service-types) - - (cd node_modules && ln -s ../packages/graphql-language-service-config) - (cd node_modules && ln -s ../packages/graphql-language-service-parser) - (cd node_modules && ln -s ../packages/graphql-language-service-interface) - (cd node_modules && ln -s ../packages/graphql-language-service-server) diff --git a/README.md b/README.md index 8ed0f9ac..dcade31c 100644 --- a/README.md +++ b/README.md @@ -35,30 +35,7 @@ The library includes a node executable file which you can find in `./node_module ### GraphQL configuration file (`.graphqlconfig`) -GraphQL Language Service, to provide its full feature set, will need to know some information about your GraphQL development environment. `.graphqlconfig` is a GraphQL configuration file that contains this information. -``` -{ - "projects": { - "product-name": { - "includeDirs": [ - "/dir/paths/to/your/graphql/files" - ], - "excludeDirs": [ - "/dir/paths/to/ignore/" - ], - "schemaPath": "/path/to/the/schema/" // supports `.graphql` IDL or `.json` file - } - } -} -``` -`.graphqlconfig` can define mutliple configurations for each GraphQL environment, should you have more than one. - -The GraphQL configurations will be used to perform two things in a nutshell: - -1. Using `includeDirs` and `excludeDirs`, cache all fragment definitions per each product. This information will be used to compute dependencies between GraphQL queries and fragments. -2. Using `schemaPath`, build and cache `GraphQLSchema`s (per product). The schema will be used to perform query validations, autocomplete suggestions etc. - -Also, if GraphQL Language Service receives an RPC message that contains the path of the file being operated on, `includDirs` and `excludeDirs` are used to determine which product configuration the file is associated with. Refer to [GraphQLConfig class](https://github.com/graphql/graphql-language-service/blob/master/packages/graphql-language-service-config/src/index.js) for more information. +Check out [graphql-config](https://github.com/graphcool/graphql-config) ### Using the command-line interface diff --git a/package-lock.json b/package-lock.json index 1c32ccd9..8eafd3fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "graphql-language-service", - "version": "0.0.35", + "version": "0.0.38", "lockfileVersion": 1, "dependencies": { "acorn": { @@ -62,8 +62,7 @@ "argparse": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", - "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=", - "dev": true + "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=" }, "arr-diff": { "version": "2.0.0", @@ -557,8 +556,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "binary-extensions": { "version": "1.8.0", @@ -570,8 +568,7 @@ "brace-expansion": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", - "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", - "dev": true + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=" }, "braces": { "version": "1.8.5", @@ -705,8 +702,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "concat-stream": { "version": "1.6.0", @@ -792,6 +788,11 @@ "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", "dev": true }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=" + }, "error-ex": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.1.tgz", @@ -1049,8 +1050,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "1.1.2", @@ -1741,8 +1741,7 @@ "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", - "dev": true + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==" }, "glob-base": { "version": "0.3.0", @@ -1785,10 +1784,22 @@ "resolved": "https://registry.npmjs.org/graphql/-/graphql-0.10.3.tgz", "integrity": "sha1-wxOv1VGOZzNRvuGPtj4qDkh0B6s=" }, - "graphql-language-service-config": { - "version": "0.0.18", - "resolved": "https://registry.npmjs.org/graphql-language-service-config/-/graphql-language-service-config-0.0.18.tgz", - "integrity": "sha512-mtUowgmBC+kgSMx3RWLL5MfMiheGwTSzmJdDh5DPUYLmP0dsL968c1wIoxNGIF442O6bNoBZiFsHk1Vb72w/Ow==" + "graphql-config": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/graphql-config/-/graphql-config-1.0.0.tgz", + "integrity": "sha512-vimY++a8rTFc4HTNvHLBOSmqE7/RhrEhzCySu28wJiOp1z7bjJXAWPjuUbIq0EvU54R3IN2MS7jCer/O526ZKg==", + "dependencies": { + "esprima": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", + "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==" + }, + "js-yaml": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.9.0.tgz", + "integrity": "sha512-0LoUNELX4S+iofCT8f4uEHIiRBR+c2AINyC8qRWfC6QNruLtxVZRJaPcu/xwMgFIgDxF25tGHaDjvxzJCNE9yw==" + } + } }, "graphql-language-service-interface": { "version": "0.0.20", @@ -1815,6 +1826,11 @@ "resolved": "https://registry.npmjs.org/graphql-language-service-utils/-/graphql-language-service-utils-0.0.18.tgz", "integrity": "sha512-IZJVihJwqZ+B8D1RBrXXZ6RmA3n+FRWDp8Qkk7G6tF1hkdrnkE+uYD4CQ5gqISjxzPZDb4mgzgxhR0R0V73nTg==" }, + "graphql-request": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-1.3.3.tgz", + "integrity": "sha1-gTj2tTkU2MZZOB+6W9ONzKP2sfE=" + }, "growl": { "version": "1.9.2", "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", @@ -1844,6 +1860,11 @@ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz", "integrity": "sha512-pNgbURSuab90KbTqvRPsseaTxOJCZBD0a7t+haSN33piP9cCM4l0CqdzAif2hUqm716UovKB2ROmiabGAKVXyg==" }, + "iconv-lite": { + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.18.tgz", + "integrity": "sha512-sr1ZQph3UwHTR0XftSbK85OvBbxe/abLGzEnPENCQwmHf7sck8Oyu4ob3LgBxWWxRoM+QszeUyl7jbqapu2TqA==" + }, "ignore": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.3.tgz", @@ -1859,14 +1880,12 @@ "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=" }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "inquirer": { "version": "0.12.0", @@ -2014,6 +2033,11 @@ "integrity": "sha1-jfV8YeouPFAUCNEA+wE8+NbgzGI=", "dev": true }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, "is-utf8": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", @@ -2032,6 +2056,11 @@ "dev": true, "optional": true }, + "isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=" + }, "iterall": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz", @@ -2201,8 +2230,7 @@ "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==" }, "minimist": { "version": "0.0.8", @@ -2279,6 +2307,11 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "node-fetch": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.1.tgz", + "integrity": "sha512-j8XsFGCLw79vWXkZtMSmmLaOk9z5SQ9bV/tkbZVCqvgwzrjAGq66igobLofHtF63NvMTp2WjytpsNTGKa+XRIQ==" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -2322,8 +2355,7 @@ "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=" }, "onetime": { "version": "1.1.0", @@ -2380,8 +2412,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-is-inside": { "version": "1.0.2", @@ -2646,8 +2677,7 @@ "rimraf": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.1.tgz", - "integrity": "sha1-wjOOxkPfeht/5cVPqG9XQopV8z0=", - "dev": true + "integrity": "sha1-wjOOxkPfeht/5cVPqG9XQopV8z0=" }, "run-async": { "version": "0.1.0", @@ -2732,8 +2762,7 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, "string_decoder": { "version": "1.0.3", @@ -2886,6 +2915,11 @@ "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.3.0.tgz", "integrity": "sha512-5BMClM4D3mRl5JlWFxIxhhJAbcVW9dFviz8ubppmG8epCTzl1bPpndcnvsjOjUlVsO9V8l8Ktklqc70Ew6soew==" }, + "whatwg-fetch": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", + "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=" + }, "which-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-1.0.0.tgz", @@ -2905,8 +2939,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "0.2.1", diff --git a/package.json b/package.json index 49b40238..87c89288 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "babel-polyfill": "6.16.0", "fb-watchman": "^2.0.0", "graphql": "^0.10.5", - "graphql-language-service-config": "0.0.18", + "graphql-config": "~1.0.0", "graphql-language-service-interface": "0.0.22", "graphql-language-service-parser": "0.0.16", "graphql-language-service-server": "0.0.34", diff --git a/packages/graphql-language-service-config/.babelrc b/packages/graphql-language-service-config/.babelrc deleted file mode 100644 index a7f45b75..00000000 --- a/packages/graphql-language-service-config/.babelrc +++ /dev/null @@ -1,25 +0,0 @@ -{ - "plugins": [ - "syntax-async-functions", - "transform-class-properties", - "transform-flow-strip-types", - "transform-object-rest-spread", - "transform-es2015-template-literals", - "transform-es2015-literals", - "transform-es2015-function-name", - "transform-es2015-arrow-functions", - "transform-es2015-block-scoped-functions", - ["transform-es2015-classes", {loose: true}], - "transform-es2015-object-super", - "transform-es2015-shorthand-properties", - "transform-es2015-duplicate-keys", - "transform-es2015-computed-properties", - "check-es2015-constants", - ["transform-es2015-spread", {loose: true}], - "transform-es2015-parameters", - ["transform-es2015-destructuring", {loose: true}], - "transform-es2015-block-scoping", - "transform-es2015-modules-commonjs", - "transform-regenerator", - ] -} diff --git a/packages/graphql-language-service-config/.npmignore b/packages/graphql-language-service-config/.npmignore deleted file mode 100644 index 1e433b22..00000000 --- a/packages/graphql-language-service-config/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -src -yarn.lock diff --git a/packages/graphql-language-service-config/README.md b/packages/graphql-language-service-config/README.md deleted file mode 100644 index cea26e5e..00000000 --- a/packages/graphql-language-service-config/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# graphql-language-service-config - -A tool-kit for accessing and using `.graphqlrc` configuration files, as used by the [GraphQL Language Service](https://github.com/graphql/graphql-language-service). diff --git a/packages/graphql-language-service-config/package.json b/packages/graphql-language-service-config/package.json deleted file mode 100644 index 18590d3d..00000000 --- a/packages/graphql-language-service-config/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "graphql-language-service-config", - "repository": "https://github.com/graphql/graphql-language-service", - "version": "0.0.19", - "description": "A tool-kit for accessing and using `.graphqlrc` configuration files", - "contributors": [ - "Greg Hurrell (https://greg.hurrell.net/)", - "Hyohyeon Jeong ", - "Lee Byron (http://leebyron.com/)" - ], - "bugs": { - "url": "https://github.com/graphql/graphql-language-service/issues" - }, - "files": [ - "dist" - ], - "keywords": [ - "graphql" - ], - "main": "dist/index.js", - "scripts": { - "test": "echo 'Please run `npm test` from the root of the repo' && exit 1", - "build": "npm run build-js && npm run build-flow", - "build-js": "babel-node ../../resources/buildJs.js", - "build-flow": "babel-node ../../resources/buildFlow.js", - "prepublish": "node ../../resources/prepublish.js" - }, - "dependencies": { - "graphql-language-service-types": "0.0.22" - } -} diff --git a/packages/graphql-language-service-config/src/GraphQLConfig.js b/packages/graphql-language-service-config/src/GraphQLConfig.js deleted file mode 100644 index d4559c72..00000000 --- a/packages/graphql-language-service-config/src/GraphQLConfig.js +++ /dev/null @@ -1,238 +0,0 @@ -/** - * 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 { - GraphQLConfig as GraphQLConfigInterface, - GraphQLConfiguration, - GraphQLProjectConfiguration, - Uri, -} from 'graphql-language-service-types'; - -import path from 'path'; - -const PROJECTS_NAME = 'projects'; -const EXTENSIONS_NAME = 'extensions'; -const CUSTOM_DIRECTIVES_NAME = 'customDirectives'; -const CUSTOM_VALIDATION_RULES_NAME = 'customValidationRules'; - -export const GRAPHQL_CONFIG_NAME = '.graphqlconfig'; - -/** - * GraphQLConfig class holds various information about the GraphQL app by - * reading the GraphQL configuration file (.graphqlconfig) located somewhere - * in the app directory tree. For more information of how to write a - * configuration for your GraphQL app, please refer to `GraphQLConfigTypes.js` - * file. - */ -export class GraphQLConfig implements GraphQLConfigInterface { - _config: GraphQLConfiguration; - _rootDir: Uri; - - constructor(config: GraphQLConfiguration, rootDir: Uri): void { - this._rootDir = rootDir; - this._config = config; - } - - // This function searches for the additional app configurations and - // returns the name of the app configuration if found. - getAppConfigNameByFilePath(filePath: Uri): ?string { - const appConfigs = this._config[PROJECTS_NAME]; - if (!appConfigs) { - return null; - } - - const appConfigNames = Object.keys(appConfigs); - - const name = appConfigNames.find(appName => { - const appConfig = this._config[PROJECTS_NAME] && - this._config[PROJECTS_NAME][appName]; - if (appConfig) { - // check if the file is included in includeDirs, - // and is not included in excludeDirs - return this.isFileInIncludeDirs(filePath, appName) && - !this.isFileInExcludeDirs(filePath, appName); - } - return false; - }); - - if (!name) { - return null; - } - - return appConfigs[name].name || name || null; - } - - getAppConfigByName(name: string): ?GraphQLProjectConfiguration { - if (this._config.name === name) { - return this._config; - } - - const appConfigs = this._config[PROJECTS_NAME]; - if (!appConfigs) { - return null; - } - - if (appConfigs[name]) { - return appConfigs[name]; - } - - const appConfigNames = Object.keys(appConfigs); - - const appConfigName = appConfigNames.find( - configName => - appConfigs[configName] && - appConfigs[configName].name && - appConfigs[configName].name === name, - ); - - return appConfigName ? appConfigs[appConfigName] : null; - } - - getRootDir(): Uri { - return this._rootDir; - } - - getConfig(): GraphQLConfiguration { - return this._config; - } - - /** - * Below getters inspect the GraphQL configuration in two steps: - * 1. If `appName` is provided, look for the app configuration and try - * returning app-specific properties, overriding the configuration options - * at the top level. - * 2. If step 1 fails and/or `appName` is not passed in, look for the property - * at the top level (the "root" configuration). - */ - - getIncludeDirs(appName: ?string): Array { - return this._getPropertyFromConfig('includeDirs', appName, []); - } - - getExcludeDirs(appName: ?string): Array { - return this._getPropertyFromConfig('excludeDirs', appName, []); - } - - getSchemaPath(appName: ?string): ?Uri { - return this._getPropertyFromConfig('schemaPath', appName, null); - } - - getCustomDirectives(appName: ?string): Array { - const appConfig = this._getPropertyFromConfig( - EXTENSIONS_NAME, - appName, - null, - ); - if (appConfig && appConfig[CUSTOM_DIRECTIVES_NAME]) { - return appConfig[CUSTOM_DIRECTIVES_NAME] || []; - } - // As a default fallback, search the top level extensions - const fallbackExtension = this._getPropertyFromConfig( - 'extensions', - null, - null, - ); - - return fallbackExtension ? fallbackExtension[CUSTOM_DIRECTIVES_NAME] : []; - } - - isFileInIncludeDirs(fileName: Uri, appName: ?string): boolean { - if (appName) { - if ( - this._config[PROJECTS_NAME] && - this._config[PROJECTS_NAME][appName] && - this._config[PROJECTS_NAME][appName].includeDirs - ) { - return this._config[PROJECTS_NAME][appName].includeDirs.some( - dirPath => fileName.indexOf(dirPath) !== -1, - ); - } - } - return this._config.includeDirs - ? this._config.includeDirs.some( - dirPath => fileName.indexOf(dirPath) !== -1, - ) - : false; - } - - isFileInExcludeDirs(fileName: Uri, appName: ?string): boolean { - if (appName) { - if ( - this._config[PROJECTS_NAME] && - this._config[PROJECTS_NAME][appName] && - this._config[PROJECTS_NAME][appName].excludeDirs - ) { - return this._config[PROJECTS_NAME][appName].excludeDirs.some( - dirPath => fileName.indexOf(dirPath) !== -1, - ); - } - } - return this._config.excludeDirs - ? this._config.excludeDirs.some( - dirPath => fileName.indexOf(dirPath) !== -1, - ) - : false; - } - - getCustomValidationRulesModulePath(appName: ?string): ?Uri { - let modulePath; - if (appName) { - if ( - this._config[PROJECTS_NAME] && - this._config[PROJECTS_NAME][appName] && - this._config[PROJECTS_NAME][appName][CUSTOM_VALIDATION_RULES_NAME] - ) { - const appConfig = this._config[PROJECTS_NAME][appName]; - modulePath = appConfig[CUSTOM_VALIDATION_RULES_NAME]; - } - } else { - modulePath = this._config[CUSTOM_VALIDATION_RULES_NAME]; - } - if (!modulePath) { - return null; - } - return this._normalizePath(modulePath); - } - - _normalizePath(modulePath: Uri): Uri { - let resolvedPath; - if (modulePath.startsWith('~')) { - // home directory - const homeDirPath = process.platform === 'win32' - ? process.env.USERPROFILE - : process.env.HOME; - resolvedPath = path.join(homeDirPath || '', modulePath.slice(1)); - } else if (modulePath.startsWith('./')) { - // relative local directory - resolvedPath = path.join(this._rootDir, modulePath); - } else { - // `/` or an actual module name (node_modules) - resolvedPath = modulePath; - } - - return resolvedPath; - } - - _getPropertyFromConfig( - key: string, - appName: ?string, - defaultValue: T, - ): T { - if ( - appName && - this._config[PROJECTS_NAME] && - this._config[PROJECTS_NAME][appName] && - this._config[PROJECTS_NAME][appName][key] - ) { - return this._config[PROJECTS_NAME][appName][key]; - } - return this._config[key] || defaultValue; - } -} diff --git a/packages/graphql-language-service-config/src/__tests__/.graphqlconfig b/packages/graphql-language-service-config/src/__tests__/.graphqlconfig deleted file mode 100644 index bcfa089b..00000000 --- a/packages/graphql-language-service-config/src/__tests__/.graphqlconfig +++ /dev/null @@ -1,26 +0,0 @@ -{ - "includeDirs": ["__queries__"], - "excludeDirs": ["__excludedQueries__"], - "projects": { - "testWithName": { - "name": "testWithName" - }, - "testWithSchema": { - "schemaPath": "__schema__/StarWarsSchema.graphql" - }, - "testWithoutSchema": { - }, - "testWithCustomDirectives": { - "extensions": { - "customDirectives": [ - "directive @customDirective on FIELD" - ] - } - } - }, - "extensions": { - "customDirectives": [ - "directive @customDirective on FRAGMENT_SPREAD" - ] - } -} diff --git a/packages/graphql-language-service-config/src/__tests__/GraphQLConfig-test.js b/packages/graphql-language-service-config/src/__tests__/GraphQLConfig-test.js deleted file mode 100644 index 616dfe48..00000000 --- a/packages/graphql-language-service-config/src/__tests__/GraphQLConfig-test.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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 {expect} from 'chai'; -import {beforeEach, describe, it} from 'mocha'; - -import {getGraphQLConfig} from '../getGraphQLConfig'; - -const CONFIG_DIR = __dirname; - -describe('GraphQLConfig', () => { - let config; - beforeEach(async () => { - config = await getGraphQLConfig(CONFIG_DIR); - }); - - it('returns a correct name', () => { - const testWithNameConfig = config.getAppConfigByName('testWithName'); - expect(testWithNameConfig.name).to.equal('testWithName'); - - const testWithSchemaConfig = config.getAppConfigByName('testWithSchema'); - expect(testWithSchemaConfig).to.not.be.undefined; - }); - - it('returns a correct root dir', () => - expect(config.getRootDir()).to.equal(CONFIG_DIR)); - it('returns a correct schema path', () => { - expect(config.getSchemaPath('testWithSchema')).to.equal( - '__schema__/StarWarsSchema.graphql', - ); - expect(config.getSchemaPath('testWithoutSchema')).to.equal(null); - }); - - it('returns a correct array of custom directives', () => { - expect( - config.getCustomDirectives('testWithCustomDirectives'), - ).to.deep.equal(['directive @customDirective on FIELD']); - expect(config.getCustomDirectives('someWeirdProjectName')).to.deep.equal([ - 'directive @customDirective on FRAGMENT_SPREAD', - ]); - }); -}); diff --git a/packages/graphql-language-service-config/src/__tests__/__queries__/test.graphql b/packages/graphql-language-service-config/src/__tests__/__queries__/test.graphql deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/graphql-language-service-config/src/__tests__/findGraphQLConfigDir-test.js b/packages/graphql-language-service-config/src/__tests__/findGraphQLConfigDir-test.js deleted file mode 100644 index 0a7364ee..00000000 --- a/packages/graphql-language-service-config/src/__tests__/findGraphQLConfigDir-test.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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 {expect} from 'chai'; -import {describe, it} from 'mocha'; -import path from 'path'; - -import {findGraphQLConfigDir} from '../findGraphQLConfigDir'; - -const CONFIG_DIR = __dirname; - -describe('findGraphQLConfigDir', () => { - it('finds GraphQLConfigDir correctly', () => - expect(findGraphQLConfigDir(CONFIG_DIR)).to.equal(CONFIG_DIR) && - expect(findGraphQLConfigDir(path.join(CONFIG_DIR, '__queries__'))).to.equal( - CONFIG_DIR, - )); -}); diff --git a/packages/graphql-language-service-config/src/__tests__/getGraphQLConfig-test.js b/packages/graphql-language-service-config/src/__tests__/getGraphQLConfig-test.js deleted file mode 100644 index 75169afd..00000000 --- a/packages/graphql-language-service-config/src/__tests__/getGraphQLConfig-test.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * 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 {expect} from 'chai'; -import {describe, it} from 'mocha'; - -import {getGraphQLConfig} from '../getGraphQLConfig'; -import {GraphQLConfig} from '../GraphQLConfig'; - -const CONFIG_DIR = __dirname; - -describe('getGraphQLConfig', () => { - it('generates GraphQLConfig correctly', async () => { - const config = await getGraphQLConfig(CONFIG_DIR); - expect(config instanceof GraphQLConfig).to.equal(true); - }); -}); diff --git a/packages/graphql-language-service-config/src/findGraphQLConfigDir.js b/packages/graphql-language-service-config/src/findGraphQLConfigDir.js deleted file mode 100644 index af285961..00000000 --- a/packages/graphql-language-service-config/src/findGraphQLConfigDir.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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 {Uri} from 'graphql-language-service-types'; - -import fs from 'fs'; -import path from 'path'; - -import {GRAPHQL_CONFIG_NAME} from './GraphQLConfig'; - -/** - * Finds a .graphqlrc configuration file, and returns null if not found. - * If the file isn't present in the provided directory path, walk up the - * directory tree until the file is found or it reaches the root directory. - */ -export function findGraphQLConfigDir(dirPath: Uri): ?string { - let currentPath = path.resolve(dirPath); - while (true) { - const filePath = path.join(currentPath, GRAPHQL_CONFIG_NAME); - if (fs.existsSync(filePath)) { - break; - } - if (isRootDir(currentPath)) { - break; - } - currentPath = path.dirname(currentPath); - } - - return !isRootDir(currentPath) ? currentPath : null; -} - -function isRootDir(dirPath: Uri): boolean { - return path.dirname(dirPath) === dirPath; -} diff --git a/packages/graphql-language-service-config/src/getGraphQLConfig.js b/packages/graphql-language-service-config/src/getGraphQLConfig.js deleted file mode 100644 index 6434f72b..00000000 --- a/packages/graphql-language-service-config/src/getGraphQLConfig.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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 {Uri} from 'graphql-language-service-types'; - -import fs from 'fs'; -import path from 'path'; - -import {GRAPHQL_CONFIG_NAME, GraphQLConfig} from './GraphQLConfig'; - -/** - * Given a config directory, returns a GraphQLConfig object. - * Throws errors if GraphQLConfig object isn't available or fails to be built. - */ -export async function getGraphQLConfig(configDir: Uri): Promise { - const rawGraphQLConfig = await new Promise((resolve, reject) => - fs.readFile( - path.join(configDir, GRAPHQL_CONFIG_NAME), - 'utf8', - (error, response) => { - if (error) { - // eslint-disable-next-line no-console - console.error( - '${GRAPHQL_CONFIG_NAME} file is not available in the provided ' + - `config directory: ${configDir}\nPlease check the config ` + - 'directory path and try again.', - ); - reject(); - } - resolve(response); - }, - )); - try { - return new GraphQLConfig(JSON.parse(rawGraphQLConfig), configDir); - } catch (error) { - // eslint-disable-next-line no-console - console.error('Parsing JSON in .graphqlrc file has failed.'); - throw new Error(error); - } -} diff --git a/packages/graphql-language-service-config/src/index.js b/packages/graphql-language-service-config/src/index.js deleted file mode 100644 index 3678f9f0..00000000 --- a/packages/graphql-language-service-config/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * 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 - */ - -export {findGraphQLConfigDir} from './findGraphQLConfigDir'; -export {getGraphQLConfig} from './getGraphQLConfig'; -export {GraphQLConfig} from './GraphQLConfig'; diff --git a/packages/graphql-language-service-interface/package.json b/packages/graphql-language-service-interface/package.json index 1ca0fdba..3f214ff1 100644 --- a/packages/graphql-language-service-interface/package.json +++ b/packages/graphql-language-service-interface/package.json @@ -17,7 +17,7 @@ "keywords": [ "graphql" ], - "main": "dist/index.js", + "main": "src/index.js", "scripts": { "test": "echo 'Please run `npm test` from the root of the repo' && exit 1", "build": "npm run build-js && npm run build-flow", @@ -27,7 +27,7 @@ }, "dependencies": { "graphql": "^0.10.5", - "graphql-language-service-config": "0.0.18", + "graphql-config": "~1.0.0", "graphql-language-service-parser": "0.0.16", "graphql-language-service-types": "0.0.22", "graphql-language-service-utils": "0.0.20" diff --git a/packages/graphql-language-service-interface/src/GraphQLLanguageService.js b/packages/graphql-language-service-interface/src/GraphQLLanguageService.js index f03d128c..a4566b52 100644 --- a/packages/graphql-language-service-interface/src/GraphQLLanguageService.js +++ b/packages/graphql-language-service-interface/src/GraphQLLanguageService.js @@ -20,6 +20,7 @@ import type { Diagnostic, GraphQLCache, GraphQLConfig, + GraphQLProjectConfig, Uri, } from 'graphql-language-service-types'; import type {Position} from 'graphql-language-service-utils'; @@ -54,18 +55,14 @@ export class GraphQLLanguageService { isRelayCompatMode?: boolean, ): Promise> { let source = query; - const appName = this._graphQLConfig.getAppConfigNameByFilePath(uri); + const projectConfig = this._graphQLConfig.getConfigForFile(uri); // If there's a matching config, proceed to prepare to run validation let schema; let customRules; - if (this._graphQLConfig.getSchemaPath(appName)) { - schema = await this._graphQLCache.getSchema( - this._graphQLConfig.getSchemaPath(appName), - appName, - ); + if (projectConfig.schemaPath) { + schema = await this._graphQLCache.getSchema(projectConfig.projectName); const fragmentDefinitions = await this._graphQLCache.getFragmentDefinitions( - this._graphQLConfig, - appName, + projectConfig, ); const fragmentDependencies = await this._graphQLCache.getFragmentDependencies( query, @@ -79,9 +76,7 @@ export class GraphQLLanguageService { source = `${source} ${dependenciesSource}`; // Check if there are custom validation rules to be used - const customRulesModulePath = this._graphQLConfig.getCustomValidationRulesModulePath( - appName, - ); + const customRulesModulePath = projectConfig.extensions.customValidationRules; if (customRulesModulePath) { /* eslint-disable no-implicit-coercion */ const rulesPath = require.resolve('' + customRulesModulePath); @@ -100,13 +95,9 @@ export class GraphQLLanguageService { position: Position, filePath: Uri, ): Promise> { - const appName = this._graphQLConfig.getAppConfigNameByFilePath(filePath); - let schema; - if (this._graphQLConfig.getSchemaPath(appName)) { - schema = await this._graphQLCache.getSchema( - this._graphQLConfig.getSchemaPath(appName), - appName, - ); + const projectConfig = this._graphQLConfig.getConfigForFile(filePath); + if (projectConfig.schemaPath) { + const schema = projectConfig.getSchema(); if (schema) { return getAutocompleteSuggestions(schema, query, position); @@ -120,7 +111,7 @@ export class GraphQLLanguageService { position: Position, filePath: Uri, ): Promise { - const appName = this._graphQLConfig.getAppConfigNameByFilePath(filePath); + const projectConfig = this._graphQLConfig.getConfigForFile(filePath); let ast; try { @@ -138,8 +129,7 @@ export class GraphQLLanguageService { ast, node, filePath, - this._graphQLConfig, - appName, + projectConfig, ); case FRAGMENT_DEFINITION: case OPERATION_DEFINITION: @@ -158,12 +148,10 @@ export class GraphQLLanguageService { ast: DocumentNode, node: FragmentSpreadNode, filePath: Uri, - graphQLConfig: GraphQLConfig, - appName: ?string, + projectConfig: GraphQLProjectConfig, ): Promise { const fragmentDefinitions = await this._graphQLCache.getFragmentDefinitions( - graphQLConfig, - appName, + projectConfig, ); const dependencies = await this._graphQLCache.getFragmentDependenciesForAST( diff --git a/packages/graphql-language-service-interface/src/__tests__/GraphQLLanguageService-test.js b/packages/graphql-language-service-interface/src/__tests__/GraphQLLanguageService-test.js index 209e5e6f..b5f65738 100644 --- a/packages/graphql-language-service-interface/src/__tests__/GraphQLLanguageService-test.js +++ b/packages/graphql-language-service-interface/src/__tests__/GraphQLLanguageService-test.js @@ -10,18 +10,19 @@ import {expect} from 'chai'; import {beforeEach, describe, it} from 'mocha'; +import {join} from 'path'; -import {GraphQLConfig} from 'graphql-language-service-config'; +import {GraphQLConfig} from 'graphql-config'; import {GraphQLLanguageService} from '../GraphQLLanguageService'; const MOCK_CONFIG = { - inputDirs: ['./queries'], + includes: ['./queries/**'], }; describe('GraphQLLanguageService', () => { const mockCache: any = { getGraphQLConfig() { - return new GraphQLConfig(MOCK_CONFIG, __dirname); + return new GraphQLConfig(MOCK_CONFIG, join(__dirname, '.graphqlconfig')); }, }; diff --git a/packages/graphql-language-service-parser/package.json b/packages/graphql-language-service-parser/package.json index 8cdd15d1..d97b9e50 100644 --- a/packages/graphql-language-service-parser/package.json +++ b/packages/graphql-language-service-parser/package.json @@ -17,7 +17,7 @@ "keywords": [ "graphql" ], - "main": "dist/index.js", + "main": "src/index.js", "scripts": { "test": "echo 'Please run `npm test` from the root of the repo' && exit 1", "build": "npm run build-js && npm run build-flow", diff --git a/packages/graphql-language-service-server/package.json b/packages/graphql-language-service-server/package.json index 612aa2b7..f0728810 100644 --- a/packages/graphql-language-service-server/package.json +++ b/packages/graphql-language-service-server/package.json @@ -17,7 +17,7 @@ "keywords": [ "graphql" ], - "main": "dist/index.js", + "main": "src/index.js", "scripts": { "test": "echo 'Please run `npm test` from the root of the repo' && exit 1", "build": "npm run build-js && npm run build-flow", @@ -28,7 +28,7 @@ "dependencies": { "fb-watchman": "^2.0.0", "graphql": "^0.10.5", - "graphql-language-service-config": "0.0.18", + "graphql-config": "~1.0.0", "graphql-language-service-interface": "0.0.22", "graphql-language-service-types": "0.0.22", "graphql-language-service-utils": "0.0.20", diff --git a/packages/graphql-language-service-server/src/GraphQLCache.js b/packages/graphql-language-service-server/src/GraphQLCache.js index bbf033b5..39aa164a 100644 --- a/packages/graphql-language-service-server/src/GraphQLCache.js +++ b/packages/graphql-language-service-server/src/GraphQLCache.js @@ -16,18 +16,12 @@ import type { GraphQLFileInfo, FragmentInfo, Uri, + GraphQLProjectConfig, } from 'graphql-language-service-types'; import fs from 'fs'; import path from 'path'; -import { - GraphQLSchema, - buildSchema, - buildClientSchema, - extendSchema, - parse, - visit, -} from 'graphql'; +import {GraphQLSchema, extendSchema, parse, visit} from 'graphql'; import nullthrows from 'nullthrows'; import { @@ -42,7 +36,7 @@ import { TYPE_EXTENSION_DEFINITION, DIRECTIVE_DEFINITION, } from 'graphql/language/kinds'; -import {getGraphQLConfig, GraphQLConfig} from 'graphql-language-service-config'; +import {getGraphQLConfig, GraphQLConfig} from 'graphql-config'; import {GraphQLWatchman} from './GraphQLWatchman'; import {getQueryAndRange} from './MessageProcessor'; @@ -155,20 +149,18 @@ export class GraphQLCache { }; getFragmentDefinitions = async ( - graphQLConfig: GraphQLConfigInterface, - appName: ?string, + projectConfig: GraphQLProjectConfig, ): Promise> => { // This function may be called from other classes. // If then, check the cache first. - const rootDir = graphQLConfig.getRootDir(); + const rootDir = projectConfig.configDir; if (this._fragmentDefinitionsCache.has(rootDir)) { return this._fragmentDefinitionsCache.get(rootDir) || new Map(); } - const includeDirs = graphQLConfig.getIncludeDirs(appName); - const excludeDirs = graphQLConfig.getExcludeDirs(appName); + const includes = projectConfig.includes; const filesFromInputDirs = await this._watchmanClient.listFiles(rootDir, { - path: includeDirs, + path: includes, }); const list = filesFromInputDirs @@ -176,12 +168,8 @@ export class GraphQLCache { filePath: path.join(rootDir, fileInfo.name), size: fileInfo.size, mtime: fileInfo.mtime, - // Filter any files with path starting with ExcludeDirs })) - .filter(fileInfo => - excludeDirs.every( - exclude => !fileInfo.filePath.startsWith(path.join(rootDir, exclude)), - )); + .filter(fileInfo => projectConfig.includesFile(fileInfo.filePath)); const { fragmentDefinitions, @@ -191,7 +179,7 @@ export class GraphQLCache { this._fragmentDefinitionsCache.set(rootDir, fragmentDefinitions); this._graphQLFileListCache.set(rootDir, graphQLFileMap); - this._subscribeToFileChanges(rootDir, includeDirs, excludeDirs); + this._subscribeToFileChanges(rootDir, projectConfig); return fragmentDefinitions; }; @@ -202,8 +190,7 @@ export class GraphQLCache { */ _subscribeToFileChanges( rootDir: Uri, - includeDirs: Array, - excludeDirs: Array, + projectConfig: GraphQLProjectConfig, ): void { this._watchmanClient.subscribe(this._configDir, result => { if (result.files && result.files.length > 0) { @@ -213,10 +200,7 @@ export class GraphQLCache { } result.files.forEach(async ({name, exists, size, mtime}) => { // Prune the file using the input/excluded directories - if ( - !includeDirs.some(dir => name.startsWith(dir)) || - excludeDirs.some(dir => name.startsWith(dir)) - ) { + if (!projectConfig.includesFile(name)) { return; } const filePath = path.join(result.root, result.subscription, name); @@ -387,53 +371,40 @@ export class GraphQLCache { }); } - getSchema = async ( - configSchemaPath: ?Uri, - appName: ?string, - ): Promise => { - if (!configSchemaPath) { + getSchema = async (appName: ?string): Promise => { + const projectConfig = this._graphQLConfig.getProjectConfig(appName); + + if (!projectConfig) { return null; } - const schemaPath = path.join(this._configDir, configSchemaPath); - if (this._schemaMap.has(schemaPath)) { - const schema = this._schemaMap.get(schemaPath); - return schema ? this._extendSchema(schema, schemaPath) : schema; - } - const schemaDSL = await new Promise(resolve => - fs.readFile(schemaPath, 'utf8', (error, content) => { - if (error) { - throw new Error(error); - } - resolve( - content + - '\n' + - this._graphQLConfig.getCustomDirectives(appName).join('\n'), - ); - })); + if (this._schemaMap.has(projectConfig.schemaPath)) { + const schema = this._schemaMap.get(projectConfig.schemaPath); + return schema + ? this._extendSchema(schema, projectConfig.schemaPath) + : schema; + } - const schemaFileExt = path.extname(schemaPath); let schema; - try { - switch (schemaFileExt) { - case '.graphql': - schema = buildSchema(schemaDSL); - break; - case '.json': - schema = buildClientSchema(JSON.parse(schemaDSL)); - break; - default: - throw new Error('Unsupported schema file extention'); - } - } catch (error) { - throw new Error(error); + if (projectConfig.schemaPath) { + schema = projectConfig.getSchema(); + } + + const customDirectives = projectConfig.extensions.customDirectives; + if (customDirectives && schema) { + const directivesSDL = customDirectives.join('\n\n'); + schema = extendSchema(schema, parse(directivesSDL)); + } + + if (!schema) { + return null; } if (this._graphQLFileListCache.has(this._configDir)) { - schema = this._extendSchema(schema, schemaPath); + schema = this._extendSchema(schema, projectConfig.schemaPath); } - this._schemaMap.set(schemaPath, schema); + this._schemaMap.set(projectConfig.schemaPath, schema); return schema; }; diff --git a/packages/graphql-language-service-server/src/MessageProcessor.js b/packages/graphql-language-service-server/src/MessageProcessor.js index 8c081ad1..bf52452d 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.js +++ b/packages/graphql-language-service-server/src/MessageProcessor.js @@ -16,9 +16,9 @@ import type { Range as RangeType, } from 'graphql-language-service-types'; -import {extname} from 'path'; +import {extname, dirname} from 'path'; import {URL} from 'url'; -import {findGraphQLConfigDir} from 'graphql-language-service-config'; +import {findGraphQLConfigFile} from 'graphql-config'; import {GraphQLLanguageService} from 'graphql-language-service-interface'; import {Position, Range} from 'graphql-language-service-utils'; import { @@ -83,8 +83,8 @@ export class MessageProcessor { }, }; - const rootPath = findGraphQLConfigDir( - configDir ? configDir.trim() : params.rootPath, + const rootPath = dirname( + findGraphQLConfigFile(configDir ? configDir.trim() : params.rootPath), ); if (!rootPath) { throw new Error( @@ -162,7 +162,7 @@ export class MessageProcessor { messageType: 'textDocument/didOpen', projectName: this._graphQLCache .getGraphQLConfig() - .getAppConfigNameByFilePath(uri), + .getProjectNameForFile(uri), fileName: uri, }), ); @@ -230,7 +230,7 @@ export class MessageProcessor { messageType: 'textDocument/didChange', projectName: this._graphQLCache .getGraphQLConfig() - .getAppConfigNameByFilePath(uri), + .getProjectNameForFile(uri), fileName: uri, }), ); @@ -261,7 +261,7 @@ export class MessageProcessor { messageType: 'textDocument/didClose', projectName: this._graphQLCache .getGraphQLConfig() - .getAppConfigNameByFilePath(uri), + .getProjectNameForFile(uri), fileName: uri, }), ); @@ -335,7 +335,7 @@ export class MessageProcessor { messageType: 'textDocument/completion', projectName: this._graphQLCache .getGraphQLConfig() - .getAppConfigNameByFilePath(textDocument.uri), + .getProjectNameForFile(textDocument.uri), fileName: textDocument.uri, }), ); @@ -407,7 +407,7 @@ export class MessageProcessor { messageType: 'textDocument/definition', projectName: this._graphQLCache .getGraphQLConfig() - .getAppConfigNameByFilePath(textDocument.uri), + .getProjectNameForFile(textDocument.uri), fileName: textDocument.uri, }), ); @@ -423,8 +423,7 @@ export class MessageProcessor { uri: Uri, contents: Array, ): Promise { - const graphQLConfig = this._graphQLCache.getGraphQLConfig(); - const rootDir = graphQLConfig.getRootDir(); + const rootDir = this._graphQLCache.getGraphQLConfig().rootDir; await this._graphQLCache.updateFragmentDefinition( rootDir, diff --git a/packages/graphql-language-service-server/src/__tests__/.graphqlconfig b/packages/graphql-language-service-server/src/__tests__/.graphqlconfig index 7522f828..47f76464 100644 --- a/packages/graphql-language-service-server/src/__tests__/.graphqlconfig +++ b/packages/graphql-language-service-server/src/__tests__/.graphqlconfig @@ -1,6 +1,6 @@ { - "includeDirs": ["__queries__"], - "excludeDirs": ["__excludedQueries__"], + "includes": ["__queries__"], + "excludes": ["__excludedQueries__"], "projects": { "testWithSchema": { "schemaPath": "__schema__/StarWarsSchema.graphql" @@ -22,4 +22,3 @@ ] } } - diff --git a/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.js b/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.js index b25d095b..fbd012be 100644 --- a/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.js +++ b/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.js @@ -11,7 +11,7 @@ import {expect} from 'chai'; import {GraphQLSchema} from 'graphql/type'; import {parse} from 'graphql/language'; -import {getGraphQLConfig} from 'graphql-language-service-config'; +import {getGraphQLConfig} from 'graphql-config'; import {beforeEach, describe, it} from 'mocha'; import {GraphQLCache} from '../GraphQLCache'; @@ -26,37 +26,46 @@ function wihtoutASTNode(definition: object) { describe('GraphQLCache', () => { let cache; - let config; beforeEach(async () => { const watchmanClient = new MockWatchmanClient(); const configDir = __dirname; - const graphQLRC = await getGraphQLConfig(configDir); + const graphQLRC = getGraphQLConfig(configDir); cache = new GraphQLCache(configDir, graphQLRC, watchmanClient); - config = cache.getGraphQLConfig(); }); describe('getSchema', () => { it('generates the schema correctly for the test app config', async () => { - const schemaPath = config.getSchemaPath('testWithSchema'); - const schema = await cache.getSchema(schemaPath); + const schema = await cache.getSchema('testWithSchema'); expect(schema instanceof GraphQLSchema).to.equal(true); }); it('does not generate a schema without a schema path', async () => { - const schemaPath = config.getSchemaPath('testWithoutSchema'); - const schema = await cache.getSchema(schemaPath); + const schema = await cache.getSchema('testWithoutSchema'); expect(schema instanceof GraphQLSchema).to.equal(false); }); it('extend the schema with appropriate custom directive', async () => { - const schemaPath = config.getSchemaPath('testWithCustomDirectives'); - const schema = await cache.getSchema(schemaPath); + const schema = await cache.getSchema('testWithCustomDirectives'); expect( wihtoutASTNode(schema.getDirective('customDirective')), ).to.deep.equal({ args: [], - description: '', + description: undefined, // change to empty string when + // https://github.com/graphql/graphql-js/pull/961 is merged + locations: ['FIELD'], + name: 'customDirective', + }); + }); + + it('extend the schema with appropriate custom directive 2', async () => { + const schema = await cache.getSchema('testWithSchema'); + expect( + wihtoutASTNode(schema.getDirective('customDirective')), + ).to.deep.equal({ + args: [], + description: undefined, // change to empty string when + // https://github.com/graphql/graphql-js/pull/961 is merged locations: ['FRAGMENT_SPREAD'], name: 'customDirective', }); diff --git a/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.js b/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.js index a0dff472..109503a8 100644 --- a/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.js +++ b/packages/graphql-language-service-server/src/__tests__/MessageProcessor-test.js @@ -36,11 +36,13 @@ describe('MessageProcessor', () => { messageProcessor._graphQLCache = { getGraphQLConfig() { return { - getAppConfigNameByFilePath() { + configDir: __dirname, + getProjectNameForFile() { return null; }, }; }, + updateFragmentDefinition() {}, }; messageProcessor._languageService = { getAutocompleteSuggestions: (query, position, uri) => { @@ -88,7 +90,7 @@ describe('MessageProcessor', () => { }); it('properly changes the file cache with the didChange handler', async () => { - const uri = `${queryDir}test.graphql`; + const uri = `file://${queryDir}/test.graphql`; messageProcessor._textDocumentCache.set(uri, { contents: [ { diff --git a/packages/graphql-language-service-types/package.json b/packages/graphql-language-service-types/package.json index 64aa01cd..2238c3b8 100644 --- a/packages/graphql-language-service-types/package.json +++ b/packages/graphql-language-service-types/package.json @@ -17,7 +17,7 @@ "keywords": [ "graphql" ], - "main": "dist/index.js", + "main": "src/index.js", "scripts": { "test": "echo 'Please run `npm test` from the root of the repo' && exit 1", "build": "npm run build-js && npm run build-flow", diff --git a/packages/graphql-language-service-types/src/index.js b/packages/graphql-language-service-types/src/index.js index 077d62b9..7e63e8bd 100644 --- a/packages/graphql-language-service-types/src/index.js +++ b/packages/graphql-language-service-types/src/index.js @@ -23,6 +23,9 @@ import type { GraphQLType, } from 'graphql/type/definition'; +export type {GraphQLConfig, GraphQLProjectConfig} from 'graphql-config'; +import type {GraphQLConfig, GraphQLProjectConfig} from 'graphql-config'; + export type TokenPattern = string | ((char: string) => boolean) | RegExp; export interface CharacterStream { @@ -58,36 +61,21 @@ export type GraphQLProjectConfiguration = { // If not supplied, the object key can be used for the project name. name?: string, schemaPath?: string, // a file with schema IDL - schemaUrl?: URL, // For multiple applications with overlapping files, // these configuration options may be helpful - includeDirs?: Array, - excludeDirs?: Array, + includes?: Array, + excludes?: Array, // If you'd like to specify any other configurations, // we provide a reserved namespace for it extensions?: GraphQLConfigurationExtension, - customValidationRules?: Uri, }; export type GraphQLConfigurationExtension = { [name: string]: mixed, }; -export interface GraphQLConfig { - +getAppConfigNameByFilePath: (filePath: Uri) => ?string, - +getAppConfigByName: (name: string) => ?GraphQLProjectConfiguration, - +getRootDir: () => Uri, - +getConfig: () => GraphQLConfiguration, - +getIncludeDirs: (appName: ?string) => Array, - +getExcludeDirs: (appName: ?string) => Array, - +getCustomDirectives: (appName: ?string) => Array, - +isFileInIncludeDirs: (fileName: Uri, appName: ?string) => boolean, - +getSchemaPath: (appName: ?string) => ?Uri, - +getCustomValidationRulesModulePath: (appName: ?string) => ?Uri, -} - export interface GraphQLCache { getGraphQLConfig: () => GraphQLConfig, @@ -102,8 +90,7 @@ export interface GraphQLCache { ) => Promise>, getFragmentDefinitions: ( - graphQLConfig: GraphQLConfig, - appName: ?string, + graphQLConfig: GraphQLProjectConfig, ) => Promise>, +updateFragmentDefinition: ( @@ -112,10 +99,7 @@ export interface GraphQLCache { contents: Array, ) => Promise, - getSchema: ( - configSchemaPath: ?Uri, - appName: ?string, - ) => Promise, + getSchema: (appName: ?string) => Promise, } // online-parser related diff --git a/packages/graphql-language-service-utils/package.json b/packages/graphql-language-service-utils/package.json index beb1b427..a0d691f1 100644 --- a/packages/graphql-language-service-utils/package.json +++ b/packages/graphql-language-service-utils/package.json @@ -17,7 +17,7 @@ "keywords": [ "graphql" ], - "main": "dist/index.js", + "main": "src/index.js", "scripts": { "test": "echo 'Please run `npm test` from the root of the repo' && exit 1", "build": "npm run build-js && npm run build-flow", @@ -27,6 +27,7 @@ }, "dependencies": { "graphql": "^0.10.5", - "graphql-language-service-types": "0.0.22" + "graphql-language-service-types": "0.0.22", + "graphql-config": "~1.0.0" } } diff --git a/resources/bumpVersion.js b/resources/bumpVersion.js index 5834f109..0f17f4e6 100755 --- a/resources/bumpVersion.js +++ b/resources/bumpVersion.js @@ -51,7 +51,6 @@ const PACKAGE_NAMES = { server: 'graphql-language-service-server', interface: 'graphql-language-service-interface', parser: 'graphql-language-service-parser', - config: 'graphql-language-service-config', utils: 'graphql-language-service-utils', types: 'graphql-language-service-types', }; diff --git a/versions.json b/versions.json index 0ee79dab..97114563 100644 --- a/versions.json +++ b/versions.json @@ -5,9 +5,6 @@ "graphql-language-server": { "version": "0.0.4" }, - "graphql-language-service-config": { - "version": "0.0.19" - }, "graphql-language-service-interface": { "version": "0.0.22" },