Skip to content

Commit

Permalink
feat: allow graphql@16 as peer dependency (#305)
Browse files Browse the repository at this point in the history
Co-authored-by: Pieter Van der Haegen <[email protected]>
  • Loading branch information
vdhpieter and vdhpieter authored Dec 1, 2021
1 parent 88ce220 commit b693d27
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 62 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
matrix:
node: [12, 14, 16]
environment: [dom, node]
name: Node ${{ matrix.node }} @env ${{matrix.environment}}
graphql-version: [14, 15, 16]
name: Node ${{ matrix.node }} @env ${{matrix.environment}} with grahpql@${{ matrix.graphql-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand All @@ -27,5 +28,8 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install
- run: yarn add graphql@${{ matrix.graphql-version }}
- run: yarn build
- run: yarn test:${{ matrix.environment }}
env:
GRAPHQL_VERSION: ${{ matrix.graphql-version }}
6 changes: 5 additions & 1 deletion .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
matrix:
node: [12, 14, 16]
environment: [dom, node]
name: Node ${{ matrix.node }}
graphql-version: [14, 15, 16]
name: Node ${{ matrix.node }} @env ${{matrix.environment}} with grahpql@${{ matrix.graphql-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand All @@ -28,8 +29,11 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install
- run: yarn add graphql@${{ matrix.graphql-version }}
- run: yarn build
- run: yarn test:${{ matrix.environment }}
env:
GRAPHQL_VERSION: ${{ matrix.graphql-version }}
release:
needs: [tests]
runs-on: ubuntu-latest
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"form-data": "^3.0.0"
},
"peerDependencies": {
"graphql": "14.x || 15.x"
"graphql": "14 - 16"
},
"devDependencies": {
"@prisma-labs/prettier-config": "^0.1.0",
Expand All @@ -58,14 +58,14 @@
"@types/graphql-upload": "^8.0.6",
"@types/jest": "^26.0.24",
"@types/node": "^16.4.3",
"apollo-server-express": "^3.0.2",
"apollo-server-express": "^3.5.0",
"body-parser": "^1.19.0",
"doctoc": "^2.0.1",
"dripip": "^0.10.0",
"express": "^4.17.1",
"fetch-cookie": "^1.0.0",
"get-port": "^5.1.1",
"graphql": "^15.5.1",
"graphql": "16",
"graphql-tag": "^2.12.5",
"graphql-upload": "^12.0.0",
"jest": "^27.0.6",
Expand All @@ -76,6 +76,7 @@
},
"prettier": "@prisma-labs/prettier-config",
"jest": {
"preset": "ts-jest"
"preset": "ts-jest",
"snapshotResolver": "<rootDir>/snapshot-resolver.js"
}
}
26 changes: 26 additions & 0 deletions snapshot-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const graphlExtension = '.graphql_' + (process.env.GRAPHQL_VERSION ? process.env.GRAPHQL_VERSION : '16')
const snapshotFolder = '/__snapshots__'

// resolves from test to snapshot path
const resolveSnapshotPath = (testPath, snapshotExtension) => {
const indexOfLatestSlash = testPath.lastIndexOf('/')
return (
testPath.substring(0, indexOfLatestSlash) +
snapshotFolder +
testPath.substring(indexOfLatestSlash) +
graphlExtension +
snapshotExtension
)
}

// resolves from snapshot to test path
const resolveTestPath = (snapshotFilePath, snapshotExtension) =>
snapshotFilePath.replace(snapshotFolder, '').slice(0, -snapshotExtension.length - graphlExtension.length)

module.exports = {
resolveSnapshotPath,
resolveTestPath,

// Example test path, used for preflight consistency check of the implementation above
testPathForConsistencyCheck: 'tests/gql.test.ts',
}
35 changes: 35 additions & 0 deletions tests/__snapshots__/document-node.test.ts.graphql_15.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`accepts graphql DocumentNode as alternative to raw string 1`] = `
Object {
"requests": Array [
Object {
"body": Object {
"query": "{
query {
users
}
}
",
},
"headers": Object {
"accept": "*/*",
"accept-encoding": "gzip,deflate",
"connection": "close",
"content-length": "45",
"content-type": "application/json",
"host": "DYNAMIC",
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
},
"method": "POST",
},
],
"spec": Object {
"body": Object {
"data": Object {
"foo": 1,
},
},
},
}
`;
34 changes: 34 additions & 0 deletions tests/__snapshots__/document-node.test.ts.graphql_16.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`accepts graphql DocumentNode as alternative to raw string 1`] = `
Object {
"requests": Array [
Object {
"body": Object {
"query": "{
query {
users
}
}",
},
"headers": Object {
"accept": "*/*",
"accept-encoding": "gzip,deflate",
"connection": "close",
"content-length": "43",
"content-type": "application/json",
"host": "DYNAMIC",
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
},
"method": "POST",
},
],
"spec": Object {
"body": Object {
"data": Object {
"foo": 1,
},
},
},
}
`;
File renamed without changes.
34 changes: 34 additions & 0 deletions tests/__snapshots__/gql.test.ts.graphql_15.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`gql passthrough allowing benefits of tooling for gql template tag 1`] = `
Object {
"requests": Array [
Object {
"body": Object {
"operationName": "allUsers",
"query": "query allUsers {
users
}
",
},
"headers": Object {
"accept": "*/*",
"accept-encoding": "gzip,deflate",
"connection": "close",
"content-length": "69",
"content-type": "application/json",
"host": "DYNAMIC",
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
},
"method": "POST",
},
],
"spec": Object {
"body": Object {
"data": Object {
"foo": 1,
},
},
},
}
`;
33 changes: 33 additions & 0 deletions tests/__snapshots__/gql.test.ts.graphql_16.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`gql passthrough allowing benefits of tooling for gql template tag 1`] = `
Object {
"requests": Array [
Object {
"body": Object {
"operationName": "allUsers",
"query": "query allUsers {
users
}",
},
"headers": Object {
"accept": "*/*",
"accept-encoding": "gzip,deflate",
"connection": "close",
"content-length": "67",
"content-type": "application/json",
"host": "DYNAMIC",
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
},
"method": "POST",
},
],
"spec": Object {
"body": Object {
"data": Object {
"foo": 1,
},
},
},
}
`;
14 changes: 14 additions & 0 deletions update-snapshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
install_and_test()
{
yarn add graphql@"$((GRAPHQL_VERSION))" --dev
yarn test
}

export GRAPHQL_VERSION=14
install_and_test

export GRAPHQL_VERSION=15
install_and_test

export GRAPHQL_VERSION=16
install_and_test
Loading

0 comments on commit b693d27

Please sign in to comment.