Skip to content

Commit

Permalink
Test and support older GraphQL.js versions (#1996)
Browse files Browse the repository at this point in the history
* try out

* no frozen lockfile

* title job

* use "v" prefix

* version*

* cache pnpm with node version

* graphql matrix for all tests

* Fix

* Changeset

* Update lock file

* Weird

* use createGraphQLError

* dont depend on graphql version

* unused dep

* drop duplicate

* update lockfile

* Go

* peer deps as dev deps where necessary

* prettier

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
  • Loading branch information
enisdenjo and ardatan committed Nov 2, 2022
1 parent 6adb3e4 commit cedde92
Show file tree
Hide file tree
Showing 37 changed files with 271 additions and 114 deletions.
12 changes: 12 additions & 0 deletions .changeset/metal-maps-dream.md
@@ -0,0 +1,12 @@
---
'@graphql-yoga/apollo-link': patch
'@graphql-yoga/urql-exchange': patch
'@graphql-yoga/common': patch
'@graphql-yoga/graphiql': patch
'graphql-yoga': patch
'@graphql-yoga/plugin-apollo-inline-trace': patch
'@graphql-yoga/plugin-apq': patch
'@graphql-yoga/plugin-persisted-operations': patch
---

Support older version of GraphQLjs
14 changes: 12 additions & 2 deletions .eslintrc.cjs
Expand Up @@ -51,15 +51,25 @@ module.exports = {
{
files: ['packages/**/*'],
rules: {
'import/no-extraneous-dependencies': [
'error',
{ devDependencies: ['**/*.test.ts', '**/*.spec.ts'] },
],
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'graphql',
importNames: ['execute', 'subscribe'],
importNames: [
'execute',
'subscribe',
'graphql',
'executeSync',
'graphqlSync',
],
message:
'Please use `execute` and `subscribe` from `@graphql-tools/executor` instead.',
'Please use `normalizedExecutor` from `@graphql-tools/executor` instead.',
},
],
},
Expand Down
117 changes: 99 additions & 18 deletions .github/workflows/ci.yml
Expand Up @@ -12,29 +12,88 @@ on:

jobs:
unit:
name: unit / nodejs v${{ matrix.node-version }}
uses: the-guild-org/shared-config/.github/workflows/ci-node-matrix.yml@main
with:
script: 'pnpm build && pnpm test'
nodeVersions: '[14,16,18]'
packageManager: pnpm
name: unit / nodejs v${{ matrix.node-version }} / graphql v${{ matrix.graphql-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 16, 18]
graphql-version: ['15.8.0', '16.6.0']
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Get pnpm store path
id: pnpm-store
run: echo "PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Cache pnpm
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-store.outputs.PATH }}
key: ${{ runner.os }}-pnpm-store-graphql-v${{ matrix.graphql-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-graphql-v${{ matrix.graphql-version }}-
- name: Set GraphQL Version
run: node scripts/override-graphql-version.js ${{ matrix.graphql-version }}

- name: Install Dependencies
run: pnpm i --no-frozen-lockfile # no frozen-lockfile because we change the resolutions

- name: Build Packages
run: pnpm build

- name: Run Tests
run: pnpm run test --ci

integration:
name: integration / nodejs v${{ matrix.node-version }}
name: integration / nodejs v${{ matrix.node-version }} / graphql v${{ matrix.graphql-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 16, 18]
fail-fast: false
graphql-version: ['15.8.0', '16.6.0']
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- uses: the-guild-org/shared-config/setup@main
name: setup env
- name: Install Node
uses: actions/setup-node@v3
with:
nodeVersion: ${{ matrix.node-version }}
packageManager: pnpm
node-version: ${{ matrix.node-version }}

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Get pnpm store path
id: pnpm-store
run: echo "PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Cache pnpm
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-store.outputs.PATH }}
key: ${{ runner.os }}-pnpm-store-graphql-v${{ matrix.graphql-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-graphql-v${{ matrix.graphql-version }}-
- name: Set GraphQL Version
run: node scripts/override-graphql-version.js ${{ matrix.graphql-version }}

- name: Install Dependencies
run: pnpm i --no-frozen-lockfile # no frozen-lockfile because we change the resolutions

- name: Build Packages
run: pnpm build
Expand All @@ -43,21 +102,43 @@ jobs:
run: pnpm test:integration --ci

leaks:
name: leaks / nodejs v${{ matrix.node-version }}
name: leaks / nodejs v${{ matrix.node-version }} / graphql v${{ matrix.graphql-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 16, 18]
fail-fast: false
graphql-version: ['15.8.0', '16.6.0']
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- uses: the-guild-org/shared-config/setup@main
name: setup env
- name: Install Node
uses: actions/setup-node@v3
with:
nodeVersion: ${{ matrix.node-version }}
packageManager: pnpm
node-version: ${{ matrix.node-version }}

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Get pnpm store path
id: pnpm-store
run: echo "PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Cache pnpm
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-store.outputs.PATH }}
key: ${{ runner.os }}-pnpm-store-graphql-v${{ matrix.graphql-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-graphql-v${{ matrix.graphql-version }}-
- name: Set GraphQL Version
run: node scripts/override-graphql-version.js ${{ matrix.graphql-version }}

- name: Install Dependencies
run: pnpm i --no-frozen-lockfile # no frozen-lockfile because we change the resolutions

- name: Build Packages
run: pnpm build
Expand Down
5 changes: 2 additions & 3 deletions examples/error-handling/src/yoga.ts
@@ -1,6 +1,5 @@
import { createYoga, createSchema } from 'graphql-yoga'
import { createYoga, createSchema, createGraphQLError } from 'graphql-yoga'
import { fetch } from '@whatwg-node/fetch'
import { GraphQLError } from 'graphql'

const users = [
{
Expand Down Expand Up @@ -43,7 +42,7 @@ export const yoga = createYoga({
user: async (_, args) => {
const user = users.find((user) => user.id === args.byId)
if (!user) {
throw new GraphQLError(`User with id '${args.byId}' not found.`, {
throw createGraphQLError(`User with id '${args.byId}' not found.`, {
extensions: {
code: 'USER_NOT_FOUND',
someRandomExtensions: {
Expand Down
7 changes: 4 additions & 3 deletions examples/hackernews/src/schema.ts
@@ -1,3 +1,4 @@
import { createGraphQLError } from 'graphql-yoga'
import { makeExecutableSchema } from '@graphql-tools/schema'
import type { Link } from '@prisma/client'
import { PrismaClientKnownRequestError } from '@prisma/client/runtime'
Expand Down Expand Up @@ -42,7 +43,7 @@ const applyTakeConstraints = (params: {
value: number
}) => {
if (params.value < params.min || params.value > params.max) {
throw new GraphQLError(
throw createGraphQLError(
`'take' argument value '${params.value}' is outside the valid range of '${params.min}' to '${params.max}'.`,
)
}
Expand Down Expand Up @@ -122,7 +123,7 @@ const resolvers = {
const linkId = parseIntSafe(args.linkId)
if (linkId === null) {
return Promise.reject(
new GraphQLError(
createGraphQLError(
`Cannot post common on non-existing link with id '${args.linkId}'.`,
),
)
Expand All @@ -141,7 +142,7 @@ const resolvers = {
err.code === 'P2003'
) {
return Promise.reject(
new GraphQLError(
createGraphQLError(
`Cannot post common on non-existing link with id '${args.linkId}'.`,
),
)
Expand Down
10 changes: 7 additions & 3 deletions examples/node-ts/src/yoga.ts
@@ -1,5 +1,9 @@
import { createYoga, Plugin, createSchema } from 'graphql-yoga'
import { GraphQLError } from 'graphql'
import {
createYoga,
Plugin,
createSchema,
createGraphQLError,
} from 'graphql-yoga'

// available when handling requests, needs to be provided by the implementor
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down Expand Up @@ -52,7 +56,7 @@ function useDisableSubscription(): Plugin<
return {
onSubscribe({ args }) {
if (args.contextValue.disableSubscription) {
throw new GraphQLError('Subscriptions have been disabled', {
throw createGraphQLError('Subscriptions have been disabled', {
extensions: {
http: {
status: 400, // report error with a 400
Expand Down
@@ -1,6 +1,6 @@
import { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store'
import { GraphQLLiveDirective, useLiveQuery } from '@envelop/live-query'
import { CORSOptions, createYoga } from 'graphql-yoga'
import { CORSOptions, createYoga } from '../src/index.js'
import { renderGraphiQL } from '@graphql-yoga/render-graphiql'
import puppeteer from 'puppeteer'
import { createServer, Server } from 'http'
Expand Down
Expand Up @@ -133,7 +133,7 @@ describe('incremental delivery: node-fetch', () => {
type: GraphQLFile,
},
},
resolve: async (_, { file }: { file: File }) => file,
resolve: async (_, { file }) => file,
},
parseFileStream: {
type: GraphQLString,
Expand All @@ -144,7 +144,7 @@ describe('incremental delivery: node-fetch', () => {
type: GraphQLFile,
},
},
resolve: async (_, { file }: { file: File }) => {
resolve: async (_, { file }) => {
const chunks = []
for await (const chunk of file.stream()) {
chunks.push(Buffer.from(chunk))
Expand All @@ -161,7 +161,7 @@ describe('incremental delivery: node-fetch', () => {
type: GraphQLFile,
},
},
resolve: async (_, { file }: { file: File }) => {
resolve: async (_, { file }) => {
return Buffer.from(await file.arrayBuffer()).toString('utf8')
},
},
Expand Down
2 changes: 0 additions & 2 deletions packages/graphql-yoga/__tests__/500.spec.ts
@@ -1,6 +1,4 @@
import { Plugin } from '@envelop/core'
import { createGraphQLError } from '@graphql-tools/utils'
import { GraphQLError } from 'graphql'
import { createSchema } from '../src/schema'
import { createYoga } from '../src/server'

Expand Down
9 changes: 4 additions & 5 deletions packages/graphql-yoga/__tests__/error-masking.spec.ts
@@ -1,5 +1,4 @@
import { GraphQLError } from 'graphql'
import { createSchema, createYoga } from 'graphql-yoga'
import { createGraphQLError, createSchema, createYoga } from 'graphql-yoga'

describe('error masking', () => {
function createTestSchema() {
Expand All @@ -13,7 +12,7 @@ describe('error masking', () => {
resolvers: {
Query: {
hello: () => {
throw new GraphQLError('This error never gets masked.')
throw createGraphQLError('This error never gets masked.')
},
hi: () => {
throw new Error(
Expand Down Expand Up @@ -218,7 +217,7 @@ describe('error masking', () => {
const yoga = createYoga({
logging: false,
context: () => {
throw new GraphQLError('I like turtles')
throw createGraphQLError('I like turtles')
},
schema: createTestSchema(),
})
Expand All @@ -242,7 +241,7 @@ describe('error masking', () => {
const yoga = createYoga({
logging: false,
context: () => {
throw new GraphQLError('I like turtles', {
throw createGraphQLError('I like turtles', {
extensions: {
foo: 1,
},
Expand Down

0 comments on commit cedde92

Please sign in to comment.