Skip to content
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

Fix NodeJS runtime compatibility #94

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
59 changes: 0 additions & 59 deletions .circleci/config.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test-and-build:
runs-on: ubuntu-latest
strategy:
matrix:
graphql-version: ['~15.0', '~16.0']
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'

- name: Restore cache
uses: actions/cache@v2
with:
path: node_modules
key: v1-dependencies-${{ hashFiles('package.json') }}-${{ matrix.graphql-version }}
restore-keys: |
v1-dependencies-

- name: Install dependencies
if: matrix.graphql-version != ''
run: yarn install --ignore-scripts

- name: Add specific graphql version
if: matrix.graphql-version != ''
run: yarn --ignore-scripts add --dev graphql@${{ matrix.graphql-version }}

- name: Install dependencies with frozen lockfile
if: matrix.graphql-version == ''
run: yarn install --frozen-lockfile

- name: Save cache
uses: actions/cache@v2
with:
path: node_modules
key: v1-dependencies-${{ hashFiles('package.json') }}-${{ matrix.graphql-version }}

- name: Run tests
run: yarn test

test-and-build-with-typecheck:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'latest'

- name: Restore cache
uses: actions/cache@v2
with:
path: node_modules
key: v1-dependencies-${{ hashFiles('package.json') }}
restore-keys: |
v1-dependencies-

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

- name: Save cache
uses: actions/cache@v2
with:
path: node_modules
key: v1-dependencies-${{ hashFiles('package.json') }}

- name: Run tests
run: yarn test
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![npm](https://img.shields.io/npm/dm/graphql-query-complexity)](https://www.npmjs.com/package/graphql-query-complexity)
[![npm version](https://badge.fury.io/js/graphql-query-complexity.svg)](https://badge.fury.io/js/graphql-query-complexity)
[![CircleCI](https://circleci.com/gh/slicknode/graphql-query-complexity.svg?style=shield)](https://circleci.com/gh/slicknode/graphql-query-complexity)
[![Twitter Follow](https://img.shields.io/twitter/follow/slicknode?style=social)](https://twitter.com/slicknode)

This library provides GraphQL query analysis to reject complex queries to your GraphQL server.
Expand Down
29 changes: 29 additions & 0 deletions fix-hybrid-module.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
#!/bin/bash

# Create package.json for CommonJS
cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

# Define the file paths
cjs_file_path="dist/cjs/QueryComplexity.js"
esm_file_path="dist/esm/QueryComplexity.js"
find_path="dist/esm"

# Detect the operating system and use the appropriate sed command
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS (BSD sed)
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$cjs_file_path"
else
# Linux (GNU sed)
sed -i 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$cjs_file_path"
fi

# Create package.json for ES modules
cat >dist/esm/package.json <<!EOF
{
"type": "module"
}
!EOF

# Detect the operating system and use the appropriate sed command
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS (BSD sed)
sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$esm_file_path"
find "$find_path" -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
else
# Linux (GNU sed)
sed -i 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$esm_file_path"
find "$find_path" -type f -name "*.js" -exec sed -i 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
fi
12 changes: 11 additions & 1 deletion fix-hybrid-module.test.cjs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ cat >dist/test/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF
!EOF

file_path="dist/test/cjs/QueryComplexity.js"

if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS (BSD sed)
sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$file_path"
else
# Linux (GNU sed)
sed -i 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$file_path"
fi
14 changes: 14 additions & 0 deletions fix-hybrid-module.test.esm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ cat >dist/test/esm/package.json <<!EOF
"type": "module"
}
!EOF

file_path="dist/test/esm/QueryComplexity.js"
find_path="dist/test/esm"

# Detect the operating system and use the appropriate sed command
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS (BSD sed)
sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$file_path"
find "$find_path" -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
else
# Linux (GNU sed)
sed -i 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$file_path"
find "$find_path" -type f -name "*.js" -exec sed -i 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} +
fi
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build:test:esm": "tsc -p ./tsconfig.test.esm.json && ./fix-hybrid-module.test.esm.sh",
"test": "npm run lint && npm run build:test:cjs && npm run testonly:cjs && npm run build:test:esm && npm run testonly:esm",
"testonly:cjs": "mocha --check-leaks --exit --full-trace 'dist/test/cjs/**/__tests__/**/*-test.js'",
"testonly:esm": "mocha -n experimental-json-modules --check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'",
"testonly:esm": "mocha -n experimental-json-modules --loader=ts-node/esm --check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'",
"dist": "npm run clean && npm run build",
"prepare": "npm run clean && npm run dist"
},
Expand All @@ -27,7 +27,7 @@
"lodash.get": "^4.4.2"
},
"peerDependencies": {
"graphql": "^14.6.0 || ^15.0.0 || ^16.0.0"
"graphql": "^15.0.0 || ^16.0.0"
},
"files": [
"dist",
Expand All @@ -47,7 +47,9 @@
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
},
"./esm": "./dist/esm/index.js",
"./cjs": "./dist/cjs/index.js"
},
"author": "Ivo Meißner",
"license": "MIT",
Expand Down
Loading