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

chore: Update graphql-server to Yoga v4 and latest subscriptions #8753

Merged
merged 12 commits into from
Jun 29, 2023
2 changes: 1 addition & 1 deletion packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"deepmerge": "4.3.1",
"execa": "5.1.1",
"fast-glob": "3.2.12",
"graphql": "16.6.0",
"graphql": "16.7.1",
"jest": "29.5.0",
"jscodeshift": "0.15.0",
"pascalcase": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"esbuild": "0.18.10",
"fast-glob": "3.2.12",
"file-loader": "6.2.0",
"graphql": "16.6.0",
"graphql": "16.7.1",
"graphql-tag": "2.12.6",
"html-webpack-plugin": "5.5.3",
"lodash": "4.17.21",
Expand Down
4 changes: 2 additions & 2 deletions packages/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"@types/testing-library__jest-dom": "5.14.6",
"graphql": "16.6.0",
"graphql": "16.7.1",
"jest": "29.5.0",
"nodemon": "2.0.22",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.1.3"
},
"peerDependencies": {
"graphql": "16.6.0",
"graphql": "16.7.1",
"react": "18.2.0"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
14 changes: 7 additions & 7 deletions packages/graphql-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@
"@envelop/filter-operation-type": "5.0.0",
"@envelop/live-query": "6.0.0",
"@envelop/on-resolve": "3.0.0",
"@escape.tech/graphql-armor": "2.0.0",
"@graphql-tools/merge": "8.4.2",
"@graphql-tools/schema": "9.0.19",
"@graphql-tools/utils": "9.2.1",
"@graphql-yoga/subscription": "3.1.0",
"@escape.tech/graphql-armor": "2.2.0",
"@graphql-tools/merge": "9.0.0",
"@graphql-tools/schema": "10.0.0",
"@graphql-tools/utils": "10.0.1",
"@graphql-yoga/subscription": "4.0.0",
"@n1ru4l/graphql-live-query": "0.10.0",
"@n1ru4l/in-memory-live-query-store": "0.10.0",
"@opentelemetry/api": "1.4.1",
"@redwoodjs/api": "5.0.0",
"@redwoodjs/project-config": "5.0.0",
"core-js": "3.31.0",
"graphql": "16.6.0",
"graphql": "16.7.1",
"graphql-scalars": "1.22.2",
"graphql-tag": "2.12.6",
"graphql-yoga": "3.9.1",
"graphql-yoga": "4.0.2",
"lodash": "4.17.21",
"uuid": "9.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,8 @@ describe('useArmor secures the GraphQLHandler endpoint for depth, aliases, cost,
*
* Note: When reporting the number of found tokens as in
*
* '"Syntax Error: Token limit of 2 exceeded, found 3."'
* '"Syntax Error: Token limit of 2 exceeded."'
*
* The number found is not the total tokens, but the value when found that exceeded the limit.
*
* Therefore found would be n + 1.
*
*/
describe('when protecting against token complexity', () => {
Expand All @@ -491,7 +488,7 @@ describe('useArmor secures the GraphQLHandler endpoint for depth, aliases, cost,
expect(response.statusCode).toBe(200)
expect(data).toBeUndefined()
expect(errors[0].message).toMatchInlineSnapshot(
'"Syntax Error: Token limit of 2 exceeded, found 3."'
'"Syntax Error: Token limit of 2 exceeded."'
)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { createLogger } from '@redwoodjs/api/logger'
import { createGraphQLHandler } from '../../functions/graphql'

jest.mock('../../makeMergedSchema', () => {
const { createGraphQLError } = require('graphql-yoga')
const { makeExecutableSchema } = require('@graphql-tools/schema')
const { ForbiddenError } = require('@redwoodjs/graphql-server/dist/errors')
const {
ForbiddenError,
RedwoodGraphQLError,
} = require('@redwoodjs/graphql-server/dist/errors')
const { EmailValidationError, RedwoodError } = require('@redwoodjs/api')

const { CurrencyResolver } = require('graphql-scalars')
Expand Down Expand Up @@ -37,14 +41,15 @@ jest.mock('../../makeMergedSchema', () => {
getUser(id: Int!): User!
invalidUser: User!
unexpectedUser: User!
graphQLErrorUser: User!
redwoodGraphQLErrorUser: User!
}
scalar Currency
type Product {
id: Int!
name: String!
currency_iso_4217: Currency!
}
Expand All @@ -70,6 +75,14 @@ jest.mock('../../makeMergedSchema', () => {
forbiddenUser: () => {
throw new ForbiddenError('You are forbidden')
},
graphQLErrorUser: () => {
throw createGraphQLError('You are forbidden by a GraphQLError')
},
redwoodGraphQLErrorUser: () => {
throw new RedwoodGraphQLError(
'You are forbidden by a RedwoodGraphQLError'
)
},
invalidUser: () => {
throw new EmailValidationError('emailmissingatexample.com')
},
Expand Down Expand Up @@ -262,7 +275,75 @@ describe('useRedwoodError', () => {
})

const response = await handler(mockedEvent, {} as Context)
const { data, errors } = JSON.parse(response.body)

expect(response.statusCode).toBe(200)
expect(data).toBeNull()
expect(errors[0].message).toContain(
'Emailmissingatexample.com must be formatted'
)
})
})

describe('with a RedwoodGraphQLError', () => {
it('does not mask error message', async () => {
const handler = createGraphQLHandler({
loggerConfig: { logger: createLogger({}), options: {} },
sdls: {},
directives: {},
services: {},
onException: () => {},
})

const mockedEvent = mockLambdaEvent({
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: '{ redwoodGraphQLErrorUser { id, name } }',
}),
httpMethod: 'POST',
})

const response = await handler(mockedEvent, {} as Context)
const { data, errors } = JSON.parse(response.body)

expect(response.statusCode).toBe(200)
expect(data).toBeNull()
expect(errors[0].message).toContain(
'You are forbidden by a RedwoodGraphQLError'
)
})
})

describe('with a GraphQLError', () => {
it('does not mask error message', async () => {
const handler = createGraphQLHandler({
loggerConfig: { logger: createLogger({}), options: {} },
sdls: {},
directives: {},
services: {},
onException: () => {},
})

const mockedEvent = mockLambdaEvent({
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: '{ graphQLErrorUser { id, name } }',
}),
httpMethod: 'POST',
})

const response = await handler(mockedEvent, {} as Context)
const { data, errors } = JSON.parse(response.body)

expect(response.statusCode).toBe(200)
expect(data).toBeNull()
expect(errors[0].message).toContain(
'You are forbidden by a GraphQLError'
)
})
})

Expand Down Expand Up @@ -297,7 +378,7 @@ describe('useRedwoodError', () => {
expect(data.products[0].currency_iso_4217).toEqual('USD')
})

it('shows the custom scalar currency type validation error message', async () => {
it('masks a custom scalar currency type runtime validation error message', async () => {
const handler = createGraphQLHandler({
loggerConfig: { logger: createLogger({}), options: {} },
sdls: {},
Expand All @@ -324,9 +405,7 @@ describe('useRedwoodError', () => {
const { data, errors } = JSON.parse(response.body)

expect(data).toBeNull()
expect(errors[0].message).toEqual(
'Value is not a valid currency value: Calamari flan'
)
expect(errors[0].message).toEqual('Something went wrong.')
})
})

Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server/src/plugins/useArmor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const useArmor = (logger: Logger, config?: ArmorConfig) => {
},
maxDepth: {
...config?.maxDepth,
flattenFragments: true,
onReject: [logRejection],
},
maxDirectives: {
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"esbuild": "0.18.10",
"fast-glob": "3.2.12",
"fs-extra": "11.1.1",
"graphql": "16.6.0",
"graphql": "16.7.1",
"kill-port": "1.6.1",
"prettier": "2.8.8",
"rimraf": "5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/prerender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"babel-plugin-ignore-html-and-css-imports": "0.1.0",
"cheerio": "1.0.0-rc.12",
"core-js": "3.31.0",
"graphql": "16.6.0",
"graphql": "16.7.1",
"mime-types": "2.1.35"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/structure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dotenv-defaults": "5.0.2",
"enquirer": "2.3.6",
"fast-glob": "3.2.12",
"graphql": "16.6.0",
"graphql": "16.7.1",
"lazy-get-decorator": "2.2.1",
"line-column": "1.0.2",
"lodash": "4.17.21",
Expand Down
4 changes: 2 additions & 2 deletions packages/studio/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@tailwindcss/forms": "0.5.3",
"@tremor/react": "3.2.3",
"graphiql": "2.4.7",
"graphql": "16.6.0",
"graphql-scalars": "1.21.3",
"graphql": "16.7.1",
"graphql-scalars": "1.22.2",
"json-bigint-patch": "0.0.8",
"pretty-ms": "7.0.0",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"fast-json-parse": "1.0.3",
"fastify": "4.18.0",
"fastify-raw-body": "4.2.0",
"graphql": "16.6.0",
"graphql": "16.7.1",
"graphql-scalars": "1.22.2",
"graphql-yoga": "3.9.1",
"jsonwebtoken": "9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@babel/runtime-corejs3": "7.22.5",
"@redwoodjs/auth": "5.0.0",
"core-js": "3.31.0",
"graphql": "16.6.0",
"graphql": "16.7.1",
"graphql-tag": "2.12.6",
"react-helmet-async": "1.3.0",
"react-hot-toast": "2.4.1",
Expand Down
1 change: 1 addition & 0 deletions tasks/run-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const createRedwoodJSApp = ({ typescript, bundler }) => {
'@prisma/client': getVersionFrmRwPkg('@prisma/client', 'api'),
'@prisma/internals': getVersionFrmRwPkg('@prisma/internals', 'cli'),
'graphql-yoga': getVersionFrmRwPkg('graphql-yoga', 'graphql-server'),
graphql: getVersionFrmRwPkg('graphql', 'graphql-server'),
}

fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2))
Expand Down
Loading