Skip to content

Commit

Permalink
Simplify CI (#6769)
Browse files Browse the repository at this point in the history
* Simplify Test flow

* S

* ..

* More

* Lets go

* Go

* Lets go

* Lets go

* Fix import

* ..

* Concurrency

* Try again

* ..

* Lets go

* Force exit
  • Loading branch information
ardatan authored Dec 14, 2024
1 parent b1146e6 commit 6a8123b
Show file tree
Hide file tree
Showing 22 changed files with 530 additions and 459 deletions.
7 changes: 7 additions & 0 deletions .changeset/sharp-carrots-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-tools/executor-urql-exchange': patch
'@graphql-tools/executor-apollo-link': patch
'@graphql-tools/utils': patch
---

Improvements for `fakePromise` so it can be used without params to create a `void` Promise
3 changes: 3 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
dependencies:
uses: the-guild-org/shared-config/.github/workflows/changesets-dependencies.yaml@main
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
stable:
permissions:
Expand Down
83 changes: 20 additions & 63 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,20 @@ env:
NODE_OPTIONS: '--max-old-space-size=8192'
CI: true

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches:
- master
pull_request:

jobs:
prettier-check:
name: 🧹 Prettier Check
runs-on: ubuntu-latest
steps:
- name: Checkout Master
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup env
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 22

- name: Prettier Check
run: yarn prettier:check
lint:
name: Lint
uses: the-guild-org/shared-config/.github/workflows/lint.yml@main
with:
script: yarn ci:lint
secrets:
githubToken: ${{ secrets.GITHUB_TOKEN }}

build:
name: Type Check on GraphQL v${{matrix.graphql_version}}
typecheck-15:
name: Type Check on GraphQL v15
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
graphql_version:
- 15
- 16
steps:
- name: Checkout Master
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand All @@ -52,25 +28,27 @@ jobs:
with:
nodeVersion: 22

- name: Use GraphQL v${{matrix.graphql_version}}
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
- name: Use GraphQL v15
run: node ./scripts/match-graphql.js 15
- name: Install Dependencies using Yarn
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Type Check
run: yarn ts:check
test_esm:
name: ESM Test
check:
name: Full Check on GraphQL v16
runs-on: ubuntu-latest
steps:
- name: Checkout Master
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup env
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 22

- name: Build Packages
- name: Prettier
run: yarn prettier:check
- name: Lint
run: yarn lint
- name: Build
run: yarn build
- name: Test ESM and CJS integrity
run: yarn bob check
Expand All @@ -83,7 +61,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest] # remove windows to speed up the tests
node-version: [18, 20, 22]
node-version: [18, 20, 22, 23]
graphql_version:
- 15
- 16
Expand Down Expand Up @@ -113,34 +91,13 @@ jobs:
hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{matrix.node-version}}-${{matrix.graphql_version}}-jest-
- name: Test
if: ${{ matrix.node-version >= 20 }}
- name: Build
run: yarn build
- name: Unit Tests
run: yarn test --ci
- name: Test
if: ${{ matrix.node-version < 20 }}
- name: Leak Tests
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 5
command: yarn test:leaks --ci

test_browser:
name: Browser Test
runs-on: ubuntu-latest
steps:
- name: Checkout Master
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup env
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 22
- name: Setup Chrome
uses: browser-actions/setup-chrome@v1
- name: Build Packages
run: yarn build
- name: Test
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 5
command: TEST_BROWSER=true yarn jest --no-watchman --ci browser
3 changes: 3 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- master
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
deployment:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ externalToolsPackages.forEach(mod => {
});

module.exports = {
displayName: process.env.LEAK_TEST ? 'Leak Test' : 'Unit Test',
testEnvironment: 'node',
rootDir: ROOT_DIR,
prettierPath: null, // disable prettier for inline snapshots
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"prettier:check": "prettier --cache --ignore-path .prettierignore --check .",
"release": "changeset publish",
"test": "jest --no-watchman",
"test:leaks": "cross-env \"LEAK_TEST=1\" jest --no-watchman --detectOpenHandles --detectLeaks --logHeapUsage",
"test:leaks": "cross-env \"LEAK_TEST=1\" jest --no-watchman --detectOpenHandles --detectLeaks --forceExit",
"ts:check": "tsc --noEmit"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimplePubSub } from './simplePubSub.js';
import { SimplePubSub } from '../../../../testing/simplePubSub.js';

describe('SimplePubSub', () => {
it('subscribe async-iterator mock', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { ExecutionResult, isAsyncIterable, isPromise, MaybePromise } from '@grap
import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick.js';
import { assertAsyncIterable } from '../../../../loaders/url/tests/test-utils.js';
import { SimplePubSub } from '../../../../testing/simplePubSub.js';
import { ExecutionArgs, subscribe } from '../execute.js';
import { normalizedExecutor } from '../normalizedExecutor.js';
import { SimplePubSub } from './simplePubSub.js';

interface Email {
from: string;
Expand Down
43 changes: 23 additions & 20 deletions packages/executors/apollo-link/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as apolloImport from '@apollo/client';
import { ExecutionRequest, Executor, isAsyncIterable } from '@graphql-tools/utils';
import { Executor, fakePromise, isAsyncIterable } from '@graphql-tools/utils';

const apollo: typeof apolloImport = (apolloImport as any)?.default ?? apolloImport;

Expand All @@ -8,34 +8,37 @@ function createApolloRequestHandler(executor: Executor): apolloImport.RequestHan
operation: apolloImport.Operation,
): apolloImport.Observable<apolloImport.FetchResult> {
return new apollo.Observable(observer => {
Promise.resolve().then(async () => {
const executionRequest: ExecutionRequest = {
document: operation.query,
variables: operation.variables,
operationName: operation.operationName,
extensions: operation.extensions,
context: operation.getContext(),
};
try {
const results = await executor(executionRequest);
fakePromise()
.then(() =>
executor({
document: operation.query,
variables: operation.variables,
operationName: operation.operationName,
extensions: operation.extensions,
context: operation.getContext(),
}),
)
.then(results => {
if (isAsyncIterable(results)) {
for await (const result of results) {
if (observer.closed) {
return;
return fakePromise().then(async () => {
for await (const result of results) {
if (observer.closed) {
return;
}
observer.next(result);
}
observer.next(result);
}
observer.complete();
observer.complete();
});
} else if (!observer.closed) {
observer.next(results);
observer.complete();
}
} catch (e) {
})
.catch(e => {
if (!observer.closed) {
observer.error(e);
}
}
});
});
});
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { setTimeout } from 'timers/promises';
import { parse } from 'graphql';
import { createSchema, createYoga } from 'graphql-yoga';
import { ApolloClient, FetchResult, InMemoryCache } from '@apollo/client/core';
import { buildHTTPExecutor } from '@graphql-tools/executor-http';
import { testIf } from '../../../testing/utils.js';
import { ExecutorLink } from '../src/index.js';

describe('Apollo Link', () => {
if (!process.env['TEST_BROWSER']) {
it('skips', () => {});
return;
}
const yoga = createYoga({
logging: false,
maskedErrors: false,
Expand Down Expand Up @@ -36,7 +34,7 @@ describe('Apollo Link', () => {
time: {
async *subscribe() {
while (true) {
await new Promise(resolve => setTimeout(resolve, 1000));
await setTimeout(300);
yield new Date().toISOString();
}
},
Expand All @@ -58,6 +56,13 @@ describe('Apollo Link', () => {
cache: new InMemoryCache(),
});

beforeEach(() => {});

afterAll(() => {
client.stop();
return client.clearStore();
});

it('should handle queries correctly', async () => {
const result = await client.query({
query: parse(/* GraphQL */ `
Expand All @@ -72,7 +77,7 @@ describe('Apollo Link', () => {
hello: 'Hello Apollo Client!',
});
});
it('should handle subscriptions correctly', async () => {
testIf(!process.env['LEAK_TEST'])('should handle subscriptions correctly', async () => {
expect.assertions(5);
const observable = client.subscribe({
query: parse(/* GraphQL */ `
Expand All @@ -83,15 +88,15 @@ describe('Apollo Link', () => {
});
const collectedValues: string[] = [];
let i = 0;
await new Promise<void>(resolve => {
await new Promise<void>((resolve, reject) => {
const subscription = observable.subscribe((result: FetchResult) => {
collectedValues.push(result.data?.['time']);
i++;
if (i > 2) {
subscription.unsubscribe();
resolve();
}
});
}, reject);
});
expect(collectedValues.length).toBe(3);
expect(i).toBe(3);
Expand Down
34 changes: 19 additions & 15 deletions packages/executors/urql-exchange/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OperationTypeNode } from 'graphql';
import { filter, make, merge, mergeMap, pipe, share, Source, takeUntil } from 'wonka';
import { ExecutionRequest, Executor, isAsyncIterable } from '@graphql-tools/utils';
import { ExecutionRequest, Executor, fakePromise, isAsyncIterable } from '@graphql-tools/utils';
import {
AnyVariables,
Exchange,
Expand Down Expand Up @@ -37,31 +37,35 @@ export function executorExchange(executor: Executor): Exchange {
};
return make<OperationResult<TData>>(observer => {
let ended = false;
Promise.resolve(executor(executionRequest))
.then(async result => {
fakePromise()
.then(() => executor(executionRequest))
.then(result => {
if (ended || !result) {
return;
}
if (!isAsyncIterable(result)) {
observer.next(makeResult(operation, result as ExecutionResult));
observer.complete();
} else {
let prevResult: OperationResult<TData, AnyVariables> | null = null;

for await (const value of result) {
if (value) {
if (prevResult && value.incremental) {
prevResult = mergeResultPatch(prevResult, value as ExecutionResult);
} else {
prevResult = makeResult(operation, value as ExecutionResult);
return fakePromise().then(async () => {
for await (const value of result) {
if (value) {
if (prevResult && value.incremental) {
prevResult = mergeResultPatch(prevResult, value as ExecutionResult);
} else {
prevResult = makeResult(operation, value as ExecutionResult);
}
observer.next(prevResult);
}
if (ended) {
break;
}
observer.next(prevResult);
}
if (ended) {
break;
}
}
observer.complete();
});
}
observer.complete();
})
.catch(error => {
observer.next(makeErrorResult(operation, error));
Expand Down
Loading

0 comments on commit 6a8123b

Please sign in to comment.