forked from graphql/graphiql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request graphql#48 from wincent/glh/extract-utils
Extract utils package
- Loading branch information
Showing
20 changed files
with
2,770 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[options] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
scripts | ||
src | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# graphql-language-service-utils | ||
|
||
Utilities to support the [GraphQL Language Service](https://github.com/graphql/graphql-language-service). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* | ||
!/.gitignore | ||
!/.npmignore |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"name": "graphql-language-service-utils", | ||
"repository": "https://github.com/graphql/graphql-language-service", | ||
"version": "0.0.1", | ||
"description": "Utilities to support the GraphQL Language Service", | ||
"contributors": [ | ||
"Greg Hurrell <greg@hurrell.net> (https://greg.hurrell.net/)", | ||
"Hyohyeon Jeong <asiandrummer@fb.com>", | ||
"Lee Byron <lee@leebyron.com> (http://leebyron.com/)" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/graphql/graphql-language-service/issues" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"graphql" | ||
], | ||
"main": "dist/index.js", | ||
"options": { | ||
"mocha": "--full-trace --require src/__tests__/mocha-bootload src/**/__tests__/**/*-test.js" | ||
}, | ||
"scripts": { | ||
"test": "npm run lint && npm run check && npm run testonly", | ||
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha", | ||
"lint": "eslint src || (printf '\\033[33mTry: \\033[7m npm run lint -- --fix \\033[0m\\n' && exit 1)", | ||
"build": "npm run build-js && npm run build-flow", | ||
"build-js": "babel-node scripts/build-js.js", | ||
"build-flow": "babel-node scripts/build-flow.js", | ||
"check": "flow check", | ||
"prepublish": "node scripts/prepublish.js" | ||
}, | ||
"dependencies": { | ||
"graphql": "^0.9.1", | ||
"graphql-language-service-types": "^0.0.6" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.23.0", | ||
"babel-eslint": "7.1.0", | ||
"babel-plugin-check-es2015-constants": "6.8.0", | ||
"babel-plugin-syntax-async-functions": "6.13.0", | ||
"babel-plugin-transform-class-properties": "6.23.0", | ||
"babel-plugin-transform-es2015-arrow-functions": "6.8.0", | ||
"babel-plugin-transform-es2015-block-scoped-functions": "6.8.0", | ||
"babel-plugin-transform-es2015-block-scoping": "6.23.0", | ||
"babel-plugin-transform-es2015-classes": "6.23.0", | ||
"babel-plugin-transform-es2015-computed-properties": "6.8.0", | ||
"babel-plugin-transform-es2015-destructuring": "6.22.0", | ||
"babel-plugin-transform-es2015-duplicate-keys": "6.8.0", | ||
"babel-plugin-transform-es2015-function-name": "6.9.0", | ||
"babel-plugin-transform-es2015-literals": "6.8.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "6.23.0", | ||
"babel-plugin-transform-es2015-object-super": "6.8.0", | ||
"babel-plugin-transform-es2015-parameters": "6.23.0", | ||
"babel-plugin-transform-es2015-shorthand-properties": "6.18.0", | ||
"babel-plugin-transform-es2015-spread": "6.8.0", | ||
"babel-plugin-transform-es2015-template-literals": "6.8.0", | ||
"babel-plugin-transform-flow-strip-types": "6.18.0", | ||
"babel-plugin-transform-object-rest-spread": "6.22.0", | ||
"babel-plugin-transform-regenerator": "6.16.1", | ||
"babel-polyfill": "^6.16.0", | ||
"babel-types": "6.22.0", | ||
"chai": "^3.5.0", | ||
"eslint": "3.15.0", | ||
"eslint-plugin-babel": "3.3.0", | ||
"eslint-plugin-dependencies": "2.0.0", | ||
"eslint-plugin-flowtype": "2.29.1", | ||
"eslint-plugin-prefer-object-spread": "1.1.0", | ||
"flow-bin": "0.39.0", | ||
"mocha": "^3.2.0" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/graphql-language-service-utils/scripts/build-flow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import {readdirSync} from 'fs'; | ||
import {join} from 'path'; | ||
import {cp} from './util'; | ||
|
||
// Non-recursively copy src/*.js to dist/*.js.flow: | ||
readdirSync('src').forEach(entry => { | ||
if (entry.endsWith('.js')) { | ||
const source = join('src', entry); | ||
const destination = join('dist', `${entry}.flow`); | ||
cp(source, destination); | ||
} | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/graphql-language-service-utils/scripts/build-js.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import {join} from 'path'; | ||
import {exec} from './util'; | ||
|
||
exec('babel', 'src', '--ignore', '**/__tests__/**', '--out-dir', 'dist'); |
40 changes: 40 additions & 0 deletions
40
packages/graphql-language-service-utils/scripts/prepublish.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// NOTE: Because prepublish is also invoked on "npm install", we can't | ||
// rely on babel-node being available. This means two things: | ||
// | ||
// (1) We must stick to a vanilla subset of ES6 features; and: | ||
// (2) We start off with a check to bail out when not invoked as part of | ||
// "npm publish". | ||
|
||
var config = require('../package.json'); | ||
if (config.scripts.prepublish.indexOf('node ') !== 0) { | ||
// Guard against somebody helpfully trying to make the package.json scripts | ||
// consistent by using "babel-node" instead of "node" (which would break | ||
// the initial "npm install"). | ||
console.error( | ||
'prepublish.js should be invoked with `node`, not `babel-node`' | ||
); | ||
process.exit(1); | ||
} | ||
|
||
// Bail unless we're running during `npm publish`. | ||
var argv = JSON.parse(process.env.npm_config_argv).original; | ||
var isPublishing = argv[0].indexOf('pu') === 0; | ||
if (!isPublishing) { | ||
process.exit(0); | ||
} | ||
|
||
// Otherwise, perform a build. | ||
var execFileSync = require('child_process').execFileSync; | ||
process.stdout.write( | ||
execFileSync('npm', ['run', 'build']) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import {execFileSync} from 'child_process'; | ||
import { | ||
createReadStream, | ||
createWriteStream, | ||
} from 'fs'; | ||
|
||
export function cp(source: string, destination: string): void { | ||
createReadStream(source).pipe(createWriteStream(destination)); | ||
} | ||
|
||
export function exec(executable: string, ...args: string[]): void { | ||
print(execFileSync(executable, args).toString()); | ||
} | ||
|
||
export function print(string: string): void { | ||
process.stdout.write(string); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* 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 {Location} from 'graphql/language'; | ||
import type { | ||
Range as RangeInterface, | ||
Position as PositionInterface, | ||
} from 'graphql-language-service-types'; | ||
|
||
export class Range implements RangeInterface { | ||
start: PositionInterface; | ||
end: PositionInterface; | ||
constructor(start: PositionInterface, end: PositionInterface): void { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
containsPosition = (position: PositionInterface): boolean => { | ||
const withinLine = | ||
this.start.line <= position.line && this.end.line >= position.line; | ||
const withinCharacter = | ||
this.start.character <= position.character && | ||
this.end.character >= position.character; | ||
return withinLine && withinCharacter; | ||
} | ||
} | ||
|
||
export class Position implements PositionInterface { | ||
line: number; | ||
character: number; | ||
constructor(line: number, character: number): void { | ||
this.line = line; | ||
this.character = character; | ||
} | ||
|
||
lessThanOrEqualTo = (position: PositionInterface): boolean => ( | ||
this.line < position.line || | ||
(this.line === position.line && this.character <= position.character) | ||
); | ||
} | ||
|
||
export function offsetToPosition(text: string, loc: number): Position { | ||
const EOL = '\n'; | ||
const buf = text.slice(0, loc); | ||
const lines = buf.split(EOL).length - 1; | ||
const lastLineIndex = buf.lastIndexOf(EOL); | ||
return new Position(lines, loc - lastLineIndex - 1); | ||
} | ||
|
||
export function locToRange(text: string, loc: Location): Range { | ||
const start = offsetToPosition(text, loc.start); | ||
const end = offsetToPosition(text, loc.end); | ||
return new Range(start, end); | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/graphql-language-service-utils/src/__tests__/__schema__/StarWarsSchema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
schema { | ||
query: Query | ||
} | ||
|
||
directive @test(testArg: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
|
||
enum Episode { | ||
NEWHOPE | ||
EMPIRE | ||
JEDI | ||
} | ||
|
||
interface Character { | ||
id: String! | ||
name: String | ||
friends: [Character] | ||
appearsIn: [Episode] | ||
secretBackstory: String | ||
} | ||
|
||
type Human implements Character { | ||
id: String! | ||
name: String | ||
friends: [Character] | ||
appearsIn: [Episode] | ||
secretBackstory: String | ||
} | ||
|
||
type Droid implements Character { | ||
id: String! | ||
name: String | ||
friends: [Character] | ||
appearsIn: [Episode] | ||
secretBackstory: String | ||
primaryFunction: String | ||
} | ||
|
||
input InputType { | ||
key: String! | ||
value: Int = 42 | ||
} | ||
|
||
type TestType { | ||
testField: String | ||
} | ||
|
||
type Query { | ||
hero(episode: Episode): Character | ||
human(id: String!): Human | ||
droid(id: String!): Droid | ||
inputTypeTest(args: InputType = {key: "key"}): TestType | ||
} |
Oops, something went wrong.