Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/entbit/graphql-tools into…
Browse files Browse the repository at this point in the history
… guild-docs-integration
  • Loading branch information
alinsimoc committed Jun 23, 2021
2 parents b9cf457 + 7ea4b11 commit e831c50
Show file tree
Hide file tree
Showing 284 changed files with 4,146 additions and 6,561 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-crews-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/webpack-loader': minor
---

feat(webpack-loader): export Options
5 changes: 5 additions & 0 deletions .changeset/cuddly-horses-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': major
---

BREAKING - Remove fieldToFieldConfig, fieldToFieldConfig, argsToFieldConfigArgument and argumentToArgumentConfig
5 changes: 5 additions & 0 deletions .changeset/fifty-wombats-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/mock': patch
---

Safer use of Object.prototype.hasOwnProperty #3069
7 changes: 7 additions & 0 deletions .changeset/forty-ducks-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-tools/schema': major
'@graphql-tools/stitch': major
'@graphql-tools/utils': major
---

BREAKING - deprecate legacy schema directives and directive resolvers
5 changes: 5 additions & 0 deletions .changeset/grumpy-months-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/resolvers-composition': patch
---

BugFix: Handle parsing endpoints when there are no mutations #3076
5 changes: 5 additions & 0 deletions .changeset/heavy-vans-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/schema': major
---

breaking - remove logger and addErrorLoggingToSchema - use envelop instead
5 changes: 5 additions & 0 deletions .changeset/long-rings-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-tools': major
---

Add deprecation notice and export makeExecutableSchema only
8 changes: 8 additions & 0 deletions .changeset/mean-news-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@graphql-tools/delegate': major
'@graphql-tools/apollo-engine-loader': major
'@graphql-tools/utils': major
'@graphql-tools/wrap': major
---

BREAKING - Use native AggregateError if possible. Native AggregateError doesn't have iterator but errors prop
5 changes: 5 additions & 0 deletions .changeset/new-balloons-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/schema': major
---

BREAKING - enhance(schema): remove schema level resolvers and addSchemaLevelResolver
5 changes: 5 additions & 0 deletions .changeset/ninety-shirts-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': major
---

BREAKING - remove debugLog
5 changes: 5 additions & 0 deletions .changeset/polite-yaks-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': major
---

BREAKING - do not apply camelCase naming convention in buildOperationNodeForField
5 changes: 5 additions & 0 deletions .changeset/silent-comics-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/schema': major
---

BREAKING(schema) - remove allowUndefinedResolve option, buildSchemaFromTypeDefinitions and use buildSchema instead
5 changes: 5 additions & 0 deletions .changeset/smooth-tips-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': major
---

BREAKING - Remove SchemaVisitor, visitSchema and VisitSchemaKind
5 changes: 5 additions & 0 deletions .changeset/twelve-suns-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/schema': patch
---

enhance(schema): use merge package to handle typeDefs and resolvers merging
5 changes: 5 additions & 0 deletions .changeset/yellow-pumas-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/jest-transform': major
---

new jest transform
7 changes: 3 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ jobs:
- name: Build
run: yarn ts:transpile
test:
name: Test on ${{matrix.os}}, Node ${{matrix.node_version}} and GraphQL v${{matrix.graphql_version}}
runs-on: ${{matrix.os}}
name: Test, Node ${{matrix.node_version}} and GraphQL v${{matrix.graphql_version}}
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest] # remove windows to speed up the tests
node_version: [10, 16]
node_version: [12, 16]
graphql_version: [14, 15]
steps:
- name: Checkout Master
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
key: ${{ runner.os }}-16-16-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-16-16-yarn-
- name: Align TypeScript version with typedoc
run: node scripts/install-typedocs-typescript-version.js
- name: Install Dependencies using Yarn
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Deploy 🚀
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,37 @@
},
"devDependencies": {
"bob-the-bundler": "1.4.1",
"@babel/core": "7.14.5",
"@babel/core": "7.14.6",
"@babel/plugin-proposal-class-properties": "7.14.5",
"@babel/preset-env": "7.14.5",
"@babel/preset-env": "7.14.7",
"@babel/preset-typescript": "7.14.5",
"@changesets/cli": "2.16.0",
"@types/jest": "26.0.23",
"@types/node": "14.17.3",
"@typescript-eslint/eslint-plugin": "4.26.1",
"@typescript-eslint/parser": "4.26.1",
"babel-jest": "27.0.2",
"@typescript-eslint/eslint-plugin": "4.28.0",
"@typescript-eslint/parser": "4.28.0",
"babel-jest": "27.0.5",
"concurrently": "6.2.0",
"eslint": "7.28.0",
"eslint": "7.29.0",
"eslint-config-prettier": "8.3.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.23.4",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-standard": "5.0.0",
"graphql": "15.5.0",
"graphql": "15.5.1",
"graphql-helix": "1.6.1",
"graphql-subscriptions": "1.2.1",
"husky": "6.0.0",
"jest": "27.0.4",
"jest": "27.0.5",
"lint-staged": "11.0.0",
"nock": "13.1.0",
"patch-package": "6.4.7",
"prettier": "2.3.1",
"ts-jest": "27.0.3",
"typedoc": "0.20.36",
"typedoc-plugin-markdown": "3.9.0",
"typescript": "4.3.2"
"typedoc": "0.21.0",
"typedoc-plugin-markdown": "3.10.0",
"typescript": "4.3.4"
},
"lint-staged": {
"packages/**/src/**/*.{ts,tsx}": [
Expand All @@ -94,7 +94,7 @@
]
},
"resolutions": {
"graphql": "15.5.0",
"graphql": "15.5.1",
"@changesets/apply-release-plan": "5.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/batch-delegate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@graphql-tools/delegate": "^7.1.4",
"@graphql-tools/utils": "^7.8.1",
"dataloader": "2.0.0",
"tslib": "~2.2.0"
"tslib": "~2.3.0"
},
"devDependencies": {
"@graphql-tools/schema": "^7.1.4",
Expand Down
28 changes: 22 additions & 6 deletions packages/batch-delegate/src/getLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@ import { BatchDelegateOptions } from './types';

const cache1: WeakMap<
ReadonlyArray<FieldNode>,
WeakMap<GraphQLSchema | SubschemaConfig, Record<string, DataLoader<any, any>>>
WeakMap<GraphQLSchema | SubschemaConfig<any, any, any, any>, Record<string, DataLoader<any, any>>>
> = new WeakMap();

function createBatchFn<K = any>(options: BatchDelegateOptions) {
const argsFromKeys = options.argsFromKeys ?? ((keys: ReadonlyArray<K>) => ({ ids: keys }));
const fieldName = options.fieldName ?? options.info.fieldName;
const { valuesFromResults, lazyOptionsFn } = options;

return async (keys: ReadonlyArray<K>) => {
const results = await delegateToSchema({
returnType: new GraphQLList(getNamedType(options.info.returnType) as GraphQLOutputType),
onLocatedError: originalError =>
relocatedError(originalError, originalError.path.slice(0, 0).concat(originalError.path.slice(2))),
onLocatedError: originalError => {
if (originalError.path == null) {
return originalError;
}

const [pathFieldName, pathNumber] = originalError.path;

if (pathFieldName !== fieldName) {
throw new Error(`Error path value at index 0 should be '${fieldName}', received '${pathFieldName}'.`);
}
const pathNumberType = typeof pathNumber;
if (pathNumberType !== 'number') {
throw new Error(`Error path value at index 1 should be of type number, received '${pathNumberType}'.`);
}

return relocatedError(originalError, originalError.path.slice(0, 0).concat(originalError.path.slice(2)));
},
args: argsFromKeys(keys),
...(lazyOptionsFn == null ? options : lazyOptionsFn(options)),
});
Expand All @@ -35,10 +51,10 @@ function createBatchFn<K = any>(options: BatchDelegateOptions) {
};
}

export function getLoader<K = any, V = any, C = K>(options: BatchDelegateOptions): DataLoader<K, V, C> {
export function getLoader<K = any, V = any, C = K>(options: BatchDelegateOptions<any>): DataLoader<K, V, C> {
const fieldName = options.fieldName ?? options.info.fieldName;

let cache2: WeakMap<GraphQLSchema | SubschemaConfig, Record<string, DataLoader<K, V, C>>> = cache1.get(
let cache2: WeakMap<GraphQLSchema | SubschemaConfig, Record<string, DataLoader<K, V, C>>> | undefined = cache1.get(
options.info.fieldNodes
);

Expand All @@ -56,7 +72,7 @@ export function getLoader<K = any, V = any, C = K>(options: BatchDelegateOptions
let loaders = cache2.get(options.schema);

if (loaders === undefined) {
loaders = Object.create(null);
loaders = Object.create(null) as Record<string, DataLoader<K, V, C>>;
cache2.set(options.schema, loaders);
const batchFn = createBatchFn(options);
const loader = new DataLoader<K, V, C>(keys => batchFn(keys), options.dataLoaderOptions);
Expand Down
10 changes: 5 additions & 5 deletions packages/batch-delegate/tests/basic.example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('batch delegation within basic stitching example', () => {

expect(numCalls).toEqual(1);
expect(result.errors).toBeUndefined();
expect(result.data.trendingChirps[0].chirpedAtUser.email).not.toBe(null);
expect(result.data!.trendingChirps[0].chirpedAtUser.email).not.toBe(null);
});

test('works with key arrays', async () => {
Expand All @@ -108,9 +108,9 @@ describe('batch delegation within basic stitching example', () => {
`,
resolvers: {
Query: {
posts: (obj, args) => {
posts: (_, args) => {
numCalls += 1;
return args.ids.map(id => ({ id, title: `Post ${id}` }));
return args.ids.map((id: unknown) => ({ id, title: `Post ${id}` }));
}
}
}
Expand All @@ -129,8 +129,8 @@ describe('batch delegation within basic stitching example', () => {
`,
resolvers: {
Query: {
users: (obj, args) => {
return args.ids.map(id => {
users: (_, args) => {
return args.ids.map((id: unknown) => {
return { id, postIds: [Number(id)+1, Number(id)+2] };
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/batch-delegate/tests/withTransforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('works with complex transforms', () => {
context,
info,
transforms: [queryTransform],
returnType: new GraphQLList(new GraphQLList(info.schema.getType('Book')))
returnType: new GraphQLList(new GraphQLList(info.schema.getType('Book')!))
}),
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/batch-execute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@graphql-tools/utils": "^7.7.0",
"dataloader": "2.0.0",
"tslib": "~2.2.0",
"tslib": "~2.3.0",
"value-or-promise": "1.0.10"
},
"publishConfig": {
Expand Down
43 changes: 27 additions & 16 deletions packages/batch-execute/src/createBatchingExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,37 @@ import { splitResult } from './splitResult';
export function createBatchingExecutor(
executor: Executor,
dataLoaderOptions?: DataLoader.Options<any, any, any>,
extensionsReducer?: (mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>
extensionsReducer: (
mergedExtensions: Record<string, any>,
executionParams: ExecutionParams
) => Record<string, any> = defaultExtensionsReducer
): Executor {
const loader = new DataLoader(
createLoadFn(executor, extensionsReducer ?? defaultExtensionsReducer),
dataLoaderOptions
);
const loader = new DataLoader(createLoadFn(executor, extensionsReducer), dataLoaderOptions);
return (executionParams: ExecutionParams) => loader.load(executionParams);
}

function createLoadFn(
executor: ({ document, context, variables, info }: ExecutionParams) => ExecutionResult | Promise<ExecutionResult>,
executor: Executor,
extensionsReducer: (mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>
) {
return async (execs: Array<ExecutionParams>): Promise<Array<ExecutionResult>> => {
return async (execs: ReadonlyArray<ExecutionParams>): Promise<Array<ExecutionResult>> => {
const execBatches: Array<Array<ExecutionParams>> = [];
let index = 0;
const exec = execs[index];
let currentBatch: Array<ExecutionParams> = [exec];
execBatches.push(currentBatch);
const operationType = getOperationAST(exec.document, undefined).operation;

const operationType = getOperationAST(exec.document, undefined)?.operation;
if (operationType == null) {
throw new Error('Could not identify operation type of document.');
}

while (++index < execs.length) {
const currentOperationType = getOperationAST(execs[index].document, undefined).operation;
const currentOperationType = getOperationAST(execs[index].document, undefined)?.operation;
if (operationType == null) {
throw new Error('Could not identify operation type of document.');
}

if (operationType === currentOperationType) {
currentBatch.push(execs[index]);
} else {
Expand All @@ -48,13 +57,15 @@ function createLoadFn(
executionResults.push(new ValueOrPromise(() => executor(mergedExecutionParams)));
});

return ValueOrPromise.all(executionResults).then(resultBatches => {
let results: Array<ExecutionResult> = [];
resultBatches.forEach((resultBatch, index) => {
results = results.concat(splitResult(resultBatch, execBatches[index].length));
});
return results;
}).resolve();
return ValueOrPromise.all(executionResults)
.then(resultBatches => {
let results: Array<ExecutionResult> = [];
resultBatches.forEach((resultBatch, index) => {
results = [...results, ...splitResult(resultBatch!, execBatches[index].length)];
});
return results;
})
.resolve();
};
}

Expand Down
6 changes: 4 additions & 2 deletions packages/batch-execute/src/getBatchingExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { memoize2of4 } from './memoize';
export const getBatchingExecutor = memoize2of4(function (
_context: Record<string, any> = self ?? window ?? global,
executor: Executor,
dataLoaderOptions?: DataLoader.Options<any, any, any>,
extensionsReducer?: (mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>
dataLoaderOptions?: DataLoader.Options<any, any, any> | undefined,
extensionsReducer?:
| undefined
| ((mergedExtensions: Record<string, any>, executionParams: ExecutionParams) => Record<string, any>)
): Executor {
return createBatchingExecutor(executor, dataLoaderOptions, extensionsReducer);
});
Loading

0 comments on commit e831c50

Please sign in to comment.