-
-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create new graphql package #4688
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
23354fd
create new graphql package
saihaj 1e1399e
b uild
saihaj 9dca0e1
esm
saihaj 06491fb
skip docs for fork
saihaj ac87352
chore(dependencies): updated changesets for modified dependencies
github-actions[bot] 05d016a
remove
saihaj File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,5 @@ | ||
--- | ||
'@graphql-tools/graphql': patch | ||
--- | ||
|
||
initial release |
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
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-tools/graphql` | ||
|
||
Fork of GraphQL.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,65 @@ | ||
{ | ||
"name": "@graphql-tools/graphql", | ||
"version": "0.0.0", | ||
"author": "Saihajpreet Singh <saihajpreet.singh@gmail.com>", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ardatan/graphql-tools.git", | ||
"directory": "packages/graphql" | ||
}, | ||
"keywords": [ | ||
"gql", | ||
"graphql", | ||
"typescript" | ||
], | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"exports": { | ||
".": { | ||
"require": { | ||
"types": "./dist/typings/index.d.cts", | ||
"default": "./dist/cjs/index.js" | ||
}, | ||
"import": { | ||
"types": "./dist/typings/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
}, | ||
"default": { | ||
"types": "./dist/typings/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
} | ||
}, | ||
"./*": { | ||
"require": { | ||
"types": "./dist/typings/*.d.cts", | ||
"default": "./dist/cjs/*.js" | ||
}, | ||
"import": { | ||
"types": "./dist/typings/*.d.ts", | ||
"default": "./dist/esm/*.js" | ||
}, | ||
"default": { | ||
"types": "./dist/typings/*.d.ts", | ||
"default": "./dist/esm/*.js" | ||
} | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"typings": "dist/typings/index.d.ts", | ||
"typescript": { | ||
"definition": "dist/typings/index.d.ts" | ||
}, | ||
"devDependencies": { | ||
"typescript": "4.7.4" | ||
}, | ||
"buildOptions": { | ||
"input": "./src/index.ts" | ||
}, | ||
"publishConfig": { | ||
"directory": "dist", | ||
"access": "public" | ||
}, | ||
"type": "module" | ||
} |
102 changes: 102 additions & 0 deletions
102
packages/graphql/src/__testUtils__/__tests__/dedent-test.ts
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,102 @@ | ||
import { dedent, dedentString } from '../dedent.js'; | ||
|
||
describe('dedentString', () => { | ||
it('removes indentation in typical usage', () => { | ||
const output = dedentString(` | ||
type Query { | ||
me: User | ||
} | ||
|
||
type User { | ||
id: ID | ||
name: String | ||
} | ||
`); | ||
expect(output).toEqual( | ||
['type Query {', ' me: User', '}', '', 'type User {', ' id: ID', ' name: String', '}'].join('\n') | ||
); | ||
}); | ||
|
||
it('removes only the first level of indentation', () => { | ||
const output = dedentString(` | ||
first | ||
second | ||
third | ||
fourth | ||
`); | ||
expect(output).toEqual(['first', ' second', ' third', ' fourth'].join('\n')); | ||
}); | ||
|
||
it('does not escape special characters', () => { | ||
const output = dedentString(` | ||
type Root { | ||
field(arg: String = "wi\th de\fault"): String | ||
} | ||
`); | ||
expect(output).toEqual(['type Root {', ' field(arg: String = "wi\th de\fault"): String', '}'].join('\n')); | ||
}); | ||
|
||
it('also removes indentation using tabs', () => { | ||
const output = dedentString(` | ||
\t\t type Query { | ||
\t\t me: User | ||
\t\t } | ||
`); | ||
expect(output).toEqual(['type Query {', ' me: User', '}'].join('\n')); | ||
}); | ||
|
||
it('removes leading and trailing newlines', () => { | ||
const output = dedentString(` | ||
|
||
|
||
type Query { | ||
me: User | ||
} | ||
|
||
|
||
`); | ||
expect(output).toEqual(['type Query {', ' me: User', '}'].join('\n')); | ||
}); | ||
|
||
it('removes all trailing spaces and tabs', () => { | ||
const output = dedentString(` | ||
type Query { | ||
me: User | ||
} | ||
\t\t \t `); | ||
expect(output).toEqual(['type Query {', ' me: User', '}'].join('\n')); | ||
}); | ||
|
||
it('works on text without leading newline', () => { | ||
const output = dedentString(` type Query { | ||
me: User | ||
} | ||
`); | ||
expect(output).toEqual(['type Query {', ' me: User', '}'].join('\n')); | ||
}); | ||
}); | ||
|
||
describe('dedent', () => { | ||
it('removes indentation in typical usage', () => { | ||
const output = dedent` | ||
type Query { | ||
me: User | ||
} | ||
`; | ||
expect(output).toEqual(['type Query {', ' me: User', '}'].join('\n')); | ||
}); | ||
|
||
it('supports expression interpolation', () => { | ||
const name = 'John'; | ||
const surname = 'Doe'; | ||
const output = dedent` | ||
{ | ||
"me": { | ||
"name": "${name}", | ||
"surname": "${surname}" | ||
} | ||
} | ||
`; | ||
expect(output).toEqual(['{', ' "me": {', ' "name": "John",', ' "surname": "Doe"', ' }', '}'].join('\n')); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/graphql/src/__testUtils__/__tests__/genFuzzStrings-test.ts
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,38 @@ | ||
import { genFuzzStrings } from '../genFuzzStrings.js'; | ||
|
||
function expectFuzzStrings(options: { allowedChars: ReadonlyArray<string>; maxLength: number }) { | ||
return expect([...genFuzzStrings(options)]); | ||
} | ||
|
||
describe('genFuzzStrings', () => { | ||
it('always provide empty string', () => { | ||
expectFuzzStrings({ allowedChars: [], maxLength: 0 }).toEqual(['']); | ||
expectFuzzStrings({ allowedChars: [], maxLength: 1 }).toEqual(['']); | ||
expectFuzzStrings({ allowedChars: ['a'], maxLength: 0 }).toEqual(['']); | ||
}); | ||
|
||
it('generate strings with single character', () => { | ||
expectFuzzStrings({ allowedChars: ['a'], maxLength: 1 }).toEqual(['', 'a']); | ||
|
||
expectFuzzStrings({ | ||
allowedChars: ['a', 'b', 'c'], | ||
maxLength: 1, | ||
}).toEqual(['', 'a', 'b', 'c']); | ||
}); | ||
|
||
it('generate strings with multiple character', () => { | ||
expectFuzzStrings({ allowedChars: ['a'], maxLength: 2 }).toEqual(['', 'a', 'aa']); | ||
|
||
expectFuzzStrings({ | ||
allowedChars: ['a', 'b', 'c'], | ||
maxLength: 2, | ||
}).toEqual(['', 'a', 'b', 'c', 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']); | ||
}); | ||
|
||
it('generate strings longer than possible number of characters', () => { | ||
expectFuzzStrings({ | ||
allowedChars: ['a', 'b'], | ||
maxLength: 3, | ||
}).toEqual(['', 'a', 'b', 'aa', 'ab', 'ba', 'bb', 'aaa', 'aab', 'aba', 'abb', 'baa', 'bab', 'bba', 'bbb']); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/graphql/src/__testUtils__/__tests__/inspectStr-test.ts
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,16 @@ | ||
import { inspectStr } from '../inspectStr.js'; | ||
|
||
describe('inspectStr', () => { | ||
it('handles null and undefined values', () => { | ||
expect(inspectStr(null)).toEqual('null'); | ||
expect(inspectStr(undefined)).toEqual('null'); | ||
}); | ||
|
||
it('correctly print various strings', () => { | ||
expect(inspectStr('')).toEqual('``'); | ||
expect(inspectStr('a')).toEqual('`a`'); | ||
expect(inspectStr('"')).toEqual('`"`'); | ||
expect(inspectStr("'")).toEqual("`'`"); | ||
expect(inspectStr('\\"')).toEqual('`\\"`'); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/graphql/src/__testUtils__/__tests__/resolveOnNextTick-test.ts
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,18 @@ | ||
import { resolveOnNextTick } from '../resolveOnNextTick.js'; | ||
|
||
describe('resolveOnNextTick', () => { | ||
it('resolves promise on the next tick', async () => { | ||
const output = []; | ||
|
||
const promise1 = resolveOnNextTick().then(() => { | ||
output.push('second'); | ||
}); | ||
const promise2 = resolveOnNextTick().then(() => { | ||
output.push('third'); | ||
}); | ||
output.push('first'); | ||
|
||
await Promise.all([promise1, promise2]); | ||
expect(output).toEqual(['first', 'second', 'third']); | ||
}); | ||
}); |
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,38 @@ | ||
export function dedentString(string: string): string { | ||
const trimmedStr = string | ||
.replace(/^\n*/m, '') // remove leading newline | ||
.replace(/[ \t\n]*$/, ''); // remove trailing spaces and tabs | ||
|
||
// fixes indentation by removing leading spaces and tabs from each line | ||
let indent = ''; | ||
for (const char of trimmedStr) { | ||
if (char !== ' ' && char !== '\t') { | ||
break; | ||
} | ||
indent += char; | ||
} | ||
|
||
return trimmedStr.replace(RegExp('^' + indent, 'mg'), ''); // remove indent | ||
} | ||
|
||
/** | ||
* An ES6 string tag that fixes indentation and also trims string. | ||
* | ||
* Example usage: | ||
* ```ts | ||
* const str = dedent` | ||
* { | ||
* test | ||
* } | ||
* `; | ||
* str === "{\n test\n}"; | ||
* ``` | ||
*/ | ||
export function dedent(strings: ReadonlyArray<string>, ...values: ReadonlyArray<string>): string { | ||
let str = strings[0]; | ||
|
||
for (let i = 1; i < strings.length; ++i) { | ||
str += values[i - 1] + strings[i]; // interpolation | ||
} | ||
return dedentString(str); | ||
} |
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,51 @@ | ||
import { isObjectLike } from '../jsutils/isObjectLike.js'; | ||
import { mapValue } from '../jsutils/mapValue.js'; | ||
|
||
/** | ||
* Deeply transforms an arbitrary value to a JSON-safe value by calling toJSON | ||
* on any nested value which defines it. | ||
*/ | ||
function toJSONDeep(value: unknown): unknown { | ||
if (!isObjectLike(value)) { | ||
return value; | ||
} | ||
|
||
// @ts-expect-error: toJSON is not defined on all objects | ||
if (typeof value.toJSON === 'function') { | ||
// @ts-expect-error: toJSON is not defined on all objects | ||
return value.toJSON(); | ||
} | ||
|
||
if (Array.isArray(value)) { | ||
return value.map(toJSONDeep); | ||
} | ||
|
||
return mapValue(value, toJSONDeep); | ||
} | ||
|
||
export function expectJSON(actual: unknown) { | ||
const actualJSON = toJSONDeep(actual); | ||
|
||
return { | ||
toDeepEqual(expected: unknown) { | ||
const expectedJSON = toJSONDeep(expected); | ||
expect(actualJSON).toMatchObject(expectedJSON as any); | ||
}, | ||
toDeepNestedProperty(path: string, expected: unknown) { | ||
const expectedJSON = toJSONDeep(expected); | ||
expect(actualJSON).toHaveProperty(path, expectedJSON); | ||
}, | ||
}; | ||
} | ||
|
||
export function expectToThrowJSON(fn: () => unknown) { | ||
function mapException(): unknown { | ||
try { | ||
return fn(); | ||
} catch (error) { | ||
return error; | ||
} | ||
} | ||
|
||
return expect(mapException()); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry @B2o5T I will improve these in future PRs :)