Skip to content

Commit

Permalink
Use GraphQL Yoga
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Mar 14, 2022
1 parent b56ce8f commit 27c8499
Show file tree
Hide file tree
Showing 28 changed files with 170 additions and 317 deletions.
1 change: 0 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@types/node-fetch",
"chalk",
"pascalcase",
"node-fetch",
"@redwoodjs/api",
"@redwoodjs/api-server",
"@redwoodjs/auth",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"dependencies": {
"@babel/runtime-corejs3": "7.16.7",
"@prisma/client": "3.10.0",
"cross-undici-fetch": "0.1.25",
"crypto-js": "4.1.1",
"jsonwebtoken": "8.5.1",
"jwks-rsa": "2.0.5",
"md5": "2.3.0",
"node-fetch": "2.6.7",
"pascalcase": "1.0.0",
"pino": "7.8.1",
"uuid": "8.3.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/__tests__/normalizeRequest.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { APIGatewayProxyEvent } from 'aws-lambda'
import { Headers } from 'node-fetch'
import { Headers } from 'cross-undici-fetch'

import { normalizeRequest } from '../transforms'

Expand Down
9 changes: 4 additions & 5 deletions packages/api/src/cors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Request } from 'graphql-helix'
import { Headers } from 'node-fetch'
import { Headers } from 'cross-undici-fetch'

import type { Request } from './transforms'

export type CorsConfig = {
origin?: boolean | string | string[]
Expand Down Expand Up @@ -62,9 +63,7 @@ export function createCorsContext(cors: CorsConfig | undefined) {
return request.method === 'OPTIONS'
},
getRequestHeaders(request: Request): CorsHeaders {
const eventHeaders = new Headers(
request.headers as Record<string, string>
)
const eventHeaders = new Headers(request.headers as HeadersInit)
const requestCorsHeaders = new Headers(corsHeaders)

if (cors && cors.origin) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/transforms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { APIGatewayProxyEvent } from 'aws-lambda'
import { Headers } from 'node-fetch'
import { Headers } from 'cross-undici-fetch'

// This is the same interface used by graphql-helix
// But not importing here to avoid adding a dependency
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/authClients/__tests__/dbAuth.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { dbAuth } from '../dbAuth'

global.RWJS_API_DBAUTH_URL = '/.redwood/functions'

jest.mock('node-fetch', () => {
jest.mock('cross-undici-fetch', () => {
return
})

Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"@babel/runtime-corejs3": "7.16.7",
"@vscode/ripgrep": "1.14.2",
"core-js": "3.21.1",
"cross-undici-fetch": "0.1.25",
"deepmerge": "4.2.2",
"fast-glob": "3.2.11",
"findup-sync": "5.0.0",
"jest": "27.5.1",
"jscodeshift": "0.13.1",
"node-fetch": "2.6.7",
"prettier": "2.5.1",
"tasuku": "1.0.2",
"toml": "3.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'

import { fetch } from 'cross-undici-fetch'
import fg from 'fast-glob'
import fetch from 'node-fetch'

import getRWPaths from '../../../lib/getRWPaths'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'

import fetch from 'node-fetch'
import { fetch } from 'cross-undici-fetch'

import getRootPackageJson from '../../../lib/getRootPackageJSON'
import getRWPaths from '../../../lib/getRWPaths'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs'
import path from 'path'

import { fetch } from 'cross-undici-fetch'
import fg from 'fast-glob'
import fetch from 'node-fetch'

import getRWPaths from '../../../lib/getRWPaths'

Expand Down
2 changes: 1 addition & 1 deletion packages/codemods/src/lib/fetchFileFromTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetch from 'node-fetch'
import { fetch } from 'cross-undici-fetch'

/**
* @param tag should be something like 'v0.42.1'
Expand Down
7 changes: 2 additions & 5 deletions packages/graphql-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,23 @@
"test:watch": "yarn test --watch"
},
"dependencies": {
"@envelop/core": "2.1.0",
"@envelop/depth-limit": "1.3.0",
"@envelop/disable-introspection": "3.1.0",
"@envelop/filter-operation-type": "3.1.0",
"@envelop/parser-cache": "4.1.0",
"@envelop/validation-cache": "4.1.0",
"@graphql-tools/merge": "8.2.3",
"@graphql-tools/schema": "8.3.2",
"@graphql-tools/utils": "8.6.2",
"@graphql-yoga/common": "0.1.0-beta.4",
"@prisma/client": "3.10.0",
"@redwoodjs/api": "0.49.1",
"core-js": "3.21.1",
"cross-undici-fetch": "0.1.25",
"graphql": "16.3.0",
"graphql-helix": "1.12.0",
"graphql-playground-html": "1.6.30",
"graphql-scalars": "1.15.0",
"graphql-tag": "2.12.6",
"lodash.merge": "4.6.2",
"lodash.omitby": "4.6.0",
"node-fetch": "2.6.7",
"uuid": "8.3.2"
},
"devDependencies": {
Expand Down
98 changes: 0 additions & 98 deletions packages/graphql-server/src/cors.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/graphql-server/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// based on ApolloError https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-errors/src/index.ts
import { EnvelopError } from '@envelop/core'
import { GraphQLYogaError } from '@graphql-yoga/common'

export class RedwoodGraphQLError extends EnvelopError {
export class RedwoodGraphQLError extends GraphQLYogaError {
constructor(message: string, extensions?: Record<string, any>) {
super(message, extensions)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { envelop, Plugin } from '@envelop/core'
import { envelop, Plugin } from '@graphql-yoga/common'

import { context, getAsyncStoreInstance } from '../../index'
import { useRedwoodGlobalContextSetter } from '../../plugins/useRedwoodGlobalContextSetter'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { APIGatewayProxyEvent } from 'aws-lambda'
import { Headers } from 'node-fetch'
import { Headers } from 'cross-undici-fetch'

import { normalizeRequest } from '@redwoodjs/api'

Expand Down Expand Up @@ -62,32 +62,38 @@ test('Normalizes an aws event with base64', () => {
true
)

expect(normalizeRequest(corsEventB64)).toEqual({
const normalizedRequest = normalizeRequest(corsEventB64)
const expectedRequest = {
headers: new Headers(corsEventB64.headers),
method: 'POST',
query: null,
body: {
bazinga: 'hello_world',
},
}

expect(normalizedRequest.method).toEqual(expectedRequest.method)
expect(normalizedRequest.query).toEqual(expectedRequest.query)
expect(normalizedRequest.body).toEqual(expectedRequest.body)
expectedRequest.headers.forEach((value, key) => {
expect(normalizedRequest.headers.get(key)).toEqual(value)
})
})

test('Handles CORS requests with and without b64 encoded', () => {
const corsEventB64 = createMockedEvent('OPTIONS', undefined, true)

expect(normalizeRequest(corsEventB64)).toEqual({
headers: new Headers(corsEventB64.headers),
method: 'OPTIONS',
query: null,
body: undefined,
})

const corsEventWithoutB64 = createMockedEvent('OPTIONS', undefined, false)

expect(normalizeRequest(corsEventWithoutB64)).toEqual({
const normalizedRequest = normalizeRequest(corsEventB64)
const expectedRequest = {
headers: new Headers(corsEventB64.headers),
method: 'OPTIONS',
query: null,
body: undefined,
}
expect(normalizedRequest.method).toEqual(expectedRequest.method)
expect(normalizedRequest.query).toEqual(expectedRequest.query)
expect(normalizedRequest.body).toEqual(expectedRequest.body)
expectedRequest.headers.forEach((value, key) => {
expect(normalizedRequest.headers.get(key)).toEqual(value)
})
})
Loading

0 comments on commit 27c8499

Please sign in to comment.