Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:prettier/recommended"
],
"plugins": ["@typescript-eslint/eslint-plugin", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"ignorePatterns": ["dist/", "node_modules/", "examples/"],
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
"es2021": true,
"node": true
},
"rules": {
"no-unused-vars": "off",
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout source
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: Install
run: yarn install --frozen-lockfile
- name: Lint
run: npm run lint
run: yarn lint
- name: Test
run: npm test
run: yarn test:ci
- name: Build
run: yarn build
13 changes: 7 additions & 6 deletions .github/workflows/publish-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ jobs:
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: NPM install
- name: Install
run: yarn install --frozen-lockfile

- name: Lint
run: yarn lint
- name: Test
run: yarn test:ci
- name: Build
run: yarn build
- name: Get version from package.json
id: get_version
run: |
version=$(jq -r '.version' package.json)
echo "version=$version" >> $GITHUB_OUTPUT
echo "Read version $version from package.json"

- name: Verify version corresponds to branch
id: verify_version
run: |
Expand Down Expand Up @@ -61,7 +63,6 @@ jobs:

echo "version_tag=$version_tag" >> $GITHUB_OUTPUT;
echo "Will publish version ${{ steps.get_version.outputs.version }} as $version_tag"

- name: Publish to npm
if: ${{ steps.verify_version.outputs.version_tag != '' }}
uses: JS-DevTools/npm-publish@v1
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Ignore node_modules directory
node_modules

# Ignore build output directory
dist

# Ignore test coverage
coverage
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ yarn.lock

# Exclude .npmrc file
.npmrc

# Exclude types
dist/*
!dist/index.d.ts
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": true,
"singleQuote": true,
"semi": true,
"quoteProps": "consistent",
"trailingComma": "all",
"arrowParens": "avoid",
"endOfLine": "lf"
}
51 changes: 44 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,69 @@
{
"name": "@adobe/plugin-hooks",
"version": "0.3.4",
"version": "0.3.5-alpha.0",
"publishConfig": {
"access": "public"
},
"description": "Adobe API Mesh Hooks Plugin",
"main": "index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
}
},
"scripts": {
"test": "echo \"no test specified\" && exit 0",
"lint": "eslint .",
"lint:fix": "eslint --fix ."
"clean": "rimraf dist",
"build": "yarn clean && yarn build:esm && yarn build:cjs",
"build:esm": "tsc --project tsconfig.esm.json --outDir dist/esm",
"build:cjs": "tsc --project tsconfig.cjs.json --outDir dist/cjs",
"prepack": "yarn build",
"lint": "eslint src",
"lint:fix": "eslint --fix .",
"test": "vitest",
"test:ci": "vitest --run"
},
"dependencies": {
"@graphql-mesh/utils": "^0.43.4",
"@graphql-mesh/cross-helpers": "^0.4.10",
"@graphql-mesh/utils": "0.43.20",
"await-timeout": "^1.1.1",
"make-cancellable-promise": "^1.1.0",
"node-fetch": "^2"
},
"devDependencies": {
"@envelop/core": "^3.0.4",
"@graphql-mesh/types": "0.91.12",
"@graphql-tools/executor-http": "^2.0.1",
"@types/await-timeout": "^0.3.4",
"@types/node": "^22.15.18",
"@types/node-fetch": "^2.6.12",
"@typescript-eslint/eslint-plugin": "^8.32.1",
"@typescript-eslint/parser": "^8.32.1",
"@vitest/coverage-v8": "^3.1.3",
"@vitest/ui": "^3.1.4",
"eslint": "^8.31.0",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-prettier": "^5.4.0",
"graphql": "^16.6.0",
"jest": "^29.6.4"
"graphql-yoga": "5.3.1",
"jest": "^29.6.4",
"prettier": "^3.5.3",
"rimraf": "5.0.1",
"typescript": "^5.8.3",
"vitest": "^3.1.3"
},
"peerDependencies": {
"@envelop/core": "*",
"graphql": "*"
},
"resolutions": {
"@graphql-mesh/utils": "0.43.20"
},
"repository": {
"type": "git",
"url": "https://github.com/adobe/plugin-hooks"
Expand Down
4 changes: 0 additions & 4 deletions index.js → src/__fixtures__/badHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const hooksPlugin = require("./src");

module.exports = hooksPlugin;
20 changes: 20 additions & 0 deletions src/__fixtures__/hookAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

module.exports = {
mockHook: async ({ body: { status, message } }) => {
return {
status,
message,
};
},
};
18 changes: 18 additions & 0 deletions src/__fixtures__/hookDefaultExportAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

module.exports = async ({ body: { status, message } }) => {
return {
status,
message,
};
};
20 changes: 20 additions & 0 deletions src/__fixtures__/hookNamedDefaultExportAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

module.exports = {
default: async ({ body: { status, message } }) => {
return {
status,
message,
};
},
};
20 changes: 20 additions & 0 deletions src/__fixtures__/hookSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

module.exports = {
mockHook: ({ body: { status, message } }) => {
return {
status,
message,
};
},
};
75 changes: 75 additions & 0 deletions src/__fixtures__/hooksTestHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import { buildHTTPExecutor, SyncFetchFn } from '@graphql-tools/executor-http';
import { createSchema, YogaInitialContext, YogaServer } from 'graphql-yoga';
import { parse } from 'graphql';
import { HookFunctionPayload, HookResponse, HookStatus, UserContext } from '../types';

const mockSuccessResponse: HookResponse = {
status: HookStatus.SUCCESS,
message: 'mock ok',
};

const mockErrorResponse: HookResponse = {
status: HookStatus.ERROR,
message: 'mock error',
};

const convertMockResponseToContext = (mockResponse: HookResponse) =>
({
body: mockResponse,
}) as unknown as HookFunctionPayload;

const testFetch = (yogaServer: YogaServer<YogaInitialContext, UserContext>, query: string) => {
if (!('fetch' in yogaServer)) {
throw new Error('Unable to test YogaServer via fetch executor');
}

const executor = buildHTTPExecutor({
fetch: yogaServer.fetch as SyncFetchFn,
});

return Promise.resolve(
executor({
document: parse(query),
}),
);
};

const mockSchema = createSchema<UserContext>({
typeDefs: /* GraphQL */ `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => 'world',
},
},
});

const mockQuery = /* GraphQL */ `
query {
hello
}
`;

export {
convertMockResponseToContext,
mockErrorResponse,
mockSchema,
mockSuccessResponse,
mockQuery,
testFetch,
};
22 changes: 22 additions & 0 deletions src/__mocks__/yogaLogger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

import { YogaLogger } from 'graphql-yoga';

const mockLogger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
} as unknown as YogaLogger;

export { mockLogger };
Loading
Loading