Skip to content

Commit

Permalink
Merge branch 'main' into test/signout
Browse files Browse the repository at this point in the history
  • Loading branch information
cshfang authored Nov 13, 2023
2 parents 7d45086 + a5eb335 commit 579c758
Show file tree
Hide file tree
Showing 38 changed files with 642 additions and 292 deletions.
30 changes: 25 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,29 @@ jobs:
- github-actions-test
- tsc-compliance-test
runs-on: ubuntu-latest
# This is a bit of a hack - Branch protections depend upon selected
# workflows that run on hardware, not parents of many callable workflows.
# Adding this so that unit and bundle checks can be a single protection line.
if: success() # only run when all checks have passed
# store success output flag for ci job
outputs:
success: ${{ steps.setoutput.outputs.success }}
steps:
- name: All tests passed
run: echo "All tests passed"
- id: setoutput
run: echo "::set-output name=success::true"
ci:
runs-on: ubuntu-latest
if: always() # always run, so we never skip the check
name: ci - Unit and Bundle tests have passed
needs: all-unit-tests-pass
env:
PASSED: ${{ needs.all-unit-tests-pass.outputs.success }}
steps:
# this job passes only when output of all-unit-tests-pass job is set
# in case at least one of the checks fails, all-unit-tests-pass is skipped
# and the output will not be set, which will then cause the ci job to fail
- run: |
if [[ $PASSED == "true" ]]; then
echo "All checks have passed"
exit 0
else
echo "One or more checks have failed"
exit 1
fi
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
// Optionally specify a single test file to run/debug:
"generateClient.test.ts",
"GraphQLAPI.test.ts",
"--runInBand",
"--testTimeout",
"600000", // 10 min timeout so jest doesn't error while we're stepping through code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jest.mock(
);

describe('createServerRunner', () => {
let createServerRunner;
let createServerRunner: any;

const mockParseAWSExports = jest.fn();
const mockCreateAWSCredentialsAndIdentityIdProvider = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"jest-fetch-mock": "3.0.3",
"next": ">= 13.5.0 < 15.0.0",
"rollup": "3.29.4",
"typescript": "5.1.6"
"typescript": "5.0.2"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nextjs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"target": "es2020",
"noImplicitAny": false,
"noImplicitAny": true,
"lib": ["dom", "es2019", "esnext.asynciterable"],
"module": "commonjs",
"moduleResolution": "node",
Expand Down
10 changes: 7 additions & 3 deletions packages/api-graphql/__tests__/APIClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
SchemaModel,
ModelIntrospectionSchema,
} from '@aws-amplify/core/internals/utils';
import {
normalizeMutationInput,
flattenItems,
Expand All @@ -6,8 +10,8 @@ import {
} from '../src/internals/APIClient';

import config from './fixtures/modeled/amplifyconfiguration';
const modelIntroSchema = config.modelIntrospection;
//
const modelIntroSchema = config.modelIntrospection as ModelIntrospectionSchema;

describe('APIClient', () => {
describe('normalizeMutationInput', () => {
// TODO: test all relationship combinations
Expand All @@ -29,7 +33,7 @@ describe('APIClient', () => {
todoNotesId: todo.id,
};

const noteModelDef = modelIntroSchema.models.Note;
const noteModelDef = modelIntroSchema.models.Note as SchemaModel;

const normalized = normalizeMutationInput(
note,
Expand Down
6 changes: 3 additions & 3 deletions packages/api-graphql/__tests__/GraphQLAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ describe('API test', () => {
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
signingServiceInfo: null,
signingServiceInfo: undefined,
}),
});
});
Expand Down Expand Up @@ -1066,7 +1066,7 @@ describe('API test', () => {
someHeaderSetAtConfigThatWillBeOverridden: 'expectedValue',
someOtherHeaderSetAtConfig: 'expectedValue',
}),
signingServiceInfo: null,
signingServiceInfo: undefined,
}),
});
});
Expand Down Expand Up @@ -1146,7 +1146,7 @@ describe('API test', () => {
url: new URL('https://localhost/graphql'),
options: expect.objectContaining({
headers: expect.objectContaining({ 'X-Api-Key': 'FAKE-KEY' }),
signingServiceInfo: null,
signingServiceInfo: undefined,
withCredentials: true,
}),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/api-graphql/__tests__/fixtures/modeled/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ClientSchema, a } from '@aws-amplify/amplify-api-next-alpha';
import { type ClientSchema, a } from '@aws-amplify/data-schema';

const schema = a.schema({
Todo: a
Expand Down
9 changes: 8 additions & 1 deletion packages/api-graphql/__tests__/resolveOwnerFields.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
ModelIntrospectionSchema,
SchemaModel,
} from '@aws-amplify/core/dist/esm/singleton/API/types';
import { resolveOwnerFields } from '../src/utils/resolveOwnerFields';
import configFixture from './fixtures/modeled/amplifyconfiguration';

Expand All @@ -14,7 +18,10 @@ describe('owner field resolution', () => {

for (const [modelName, expected] of Object.entries(expectedResolutions)) {
it(`identifes ${JSON.stringify(expected)} for ${modelName}`, () => {
const model = configFixture.modelIntrospection.models[modelName];
const modelIntroSchema =
configFixture.modelIntrospection as ModelIntrospectionSchema;
const model: SchemaModel = modelIntroSchema.models[modelName];

const resolvedField = resolveOwnerFields(model);
expect(resolvedField).toEqual(expected);
});
Expand Down
8 changes: 4 additions & 4 deletions packages/api-graphql/__tests__/server/generateClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function mockApiResponse(value: any) {
describe('server generateClient', () => {
describe('with cookies', () => {
test('subscriptions are disabled', () => {
const getAmplify = async fn => await fn(Amplify);
const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClient<Schema, V6ClientSSRCookies<Schema>>({
amplify: getAmplify,
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('server generateClient', () => {
},
});

const getAmplify = async fn => await fn(Amplify);
const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClient<Schema, V6ClientSSRCookies<Schema>>({
amplify: getAmplify,
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('server generateClient', () => {
},
});

const getAmplify = async fn => await fn(Amplify);
const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClient<Schema, V6ClientSSRCookies<Schema>>({
amplify: getAmplify,
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('server generateClient', () => {
},
});

const getAmplify = async fn => await fn(Amplify);
const getAmplify = async (fn: any) => await fn(Amplify);

const client = generateClient<Schema, V6ClientSSRCookies<Schema>>({
amplify: getAmplify,
Expand Down
14 changes: 5 additions & 9 deletions packages/api-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@
},
"homepage": "https://aws-amplify.github.io/",
"devDependencies": {
"typescript": "5.1.6",
"typescript": "5.0.2",
"@rollup/plugin-typescript": "11.1.5",
"rollup": "3.29.4"
"rollup": "3.29.4",
"@aws-amplify/data-schema": "^0.11.0"
},
"files": [
"dist/cjs",
Expand Down Expand Up @@ -98,16 +99,11 @@
"jest": {
"globals": {
"ts-jest": {
"diagnostics": {
"pathRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$"
},
"diagnostics": false,
"tsConfig": {
"lib": [
"es5",
"es2015",
"dom",
"esnext.asynciterable",
"es2017.object"
"es2020"
],
"allowJs": true,
"noEmitOnError": false,
Expand Down
4 changes: 2 additions & 2 deletions packages/api-graphql/src/GraphQLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { InternalGraphQLAPIClass } from './internals/InternalGraphQLAPI';
import { Observable } from 'rxjs';

export const graphqlOperation = (
query,
query: any,
variables = {},
authToken?: string
) => ({
Expand Down Expand Up @@ -61,4 +61,4 @@ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
}
}

export const GraphQLAPI = new GraphQLAPIClass(null);
export const GraphQLAPI = new GraphQLAPIClass();
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
import { Observable, SubscriptionLike } from 'rxjs';
import { GraphQLError } from 'graphql';
import { Hub, fetchAuthSession, ConsoleLogger } from '@aws-amplify/core';
import {
Hub,
fetchAuthSession,
ConsoleLogger,
HubPayload,
} from '@aws-amplify/core';
import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
import {
base64Encoder,
Expand Down Expand Up @@ -48,7 +53,7 @@ import {

const logger = new ConsoleLogger('AWSAppSyncRealTimeProvider');

const dispatchApiEvent = payload => {
const dispatchApiEvent = (payload: HubPayload) => {
Hub.dispatch('api', payload, 'PubSub', AMPLIFY_SYMBOL);
};

Expand Down Expand Up @@ -111,7 +116,7 @@ export class AWSAppSyncRealTimeProvider {
private keepAliveAlertTimeoutId?: ReturnType<typeof setTimeout>;
private subscriptionObserverMap: Map<string, ObserverQuery> = new Map();
private promiseArray: Array<{ res: Function; rej: Function }> = [];
private connectionState: ConnectionState;
private connectionState: ConnectionState | undefined;
private readonly connectionStateMonitor = new ConnectionStateMonitor();
private readonly reconnectionMonitor = new ReconnectionMonitor();
private connectionStateMonitorSubscription: SubscriptionLike;
Expand Down Expand Up @@ -362,7 +367,7 @@ export class AWSAppSyncRealTimeProvider {
region,
additionalHeaders,
});
} catch (err) {
} catch (err: any) {
this._logStartSubscriptionError(subscriptionId, observer, err);
return;
}
Expand Down
Loading

0 comments on commit 579c758

Please sign in to comment.