Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

fix(deps): update apollo graphql packages to v3 (major) #256

Merged
merged 2 commits into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"@types/lodash": "^4.14.170",
"ajv": "^8.6.0",
"ajv-formats": "^2.1.0",
"apollo-server": "^2.25.2",
"apollo-server-express": "^2.25.2",
"apollo-server": "^3.0.0",
"apollo-server-express": "^3.0.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
Expand Down Expand Up @@ -65,7 +65,8 @@
"@types/jest": "26.0.24",
"@types/node": "14.17.5",
"@types/validator": "13.6.3",
"apollo-server-testing": "2.25.2",
"@types/ws": "^7.4.6",
"graphql-tag": "^2.12.5",
"husky": "7.0.1",
"jest": "27.0.6",
"jest-extended": "0.11.5",
Expand Down
5 changes: 2 additions & 3 deletions src/testServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ApolloServer, ApolloServerExpressConfig } from 'apollo-server-express'
import { ApolloServerTestClient, createTestClient } from 'apollo-server-testing'
import { merge } from 'lodash'
import { serverConfig, Services } from './apolloServer'
import { fakeAdminAuth, fakeUserAuth } from './authenticateRequest'
Expand Down Expand Up @@ -28,7 +27,7 @@ const makeFakeGenerateCsvFn = () => {

export const makeTestServer = async (
overrides: Partial<ApolloServerExpressConfig> = {},
): Promise<ApolloServerTestClient> => {
): Promise<ApolloServer> => {
if (overrides.context == null) {
const userAccount = await UserAccount.create({
auth0Id: 'user-auth0-id',
Expand All @@ -42,7 +41,7 @@ export const makeTestServer = async (
})
}

return createTestClient(new ApolloServer(merge(serverConfig, overrides)))
return new ApolloServer(merge(serverConfig, overrides))
}

export const makeAdminTestServer = async (
Expand Down
58 changes: 29 additions & 29 deletions src/tests/groups_api.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApolloServerTestClient } from 'apollo-server-testing'
import { ApolloServer } from 'apollo-server-express'
import gql from 'graphql-tag'
import { omit } from 'lodash'
import { fakeUserAuth } from '../authenticateRequest'
Expand Down Expand Up @@ -31,8 +31,8 @@ describe('Groups API', () => {
...commonGroupData,
}

let testServer: ApolloServerTestClient,
adminTestServer: ApolloServerTestClient,
let testServer: ApolloServer,
adminTestServer: ApolloServer,
captain: UserAccount,
newCaptain: UserAccount

Expand Down Expand Up @@ -80,8 +80,8 @@ describe('Groups API', () => {
`

it('adds a new group', async () => {
const res = await testServer.mutate({
mutation: ADD_GROUP,
const res = await testServer.executeOperation({
query: ADD_GROUP,
variables: group1Params,
})

Expand All @@ -91,13 +91,13 @@ describe('Groups API', () => {
})

it('prevents group captains from creating more than 1 group', async () => {
await testServer.mutate({
mutation: ADD_GROUP,
await testServer.executeOperation({
query: ADD_GROUP,
variables: group1Params,
})

const res = await testServer.mutate({
mutation: ADD_GROUP,
const res = await testServer.executeOperation({
query: ADD_GROUP,
variables: group2Params,
})

Expand Down Expand Up @@ -153,8 +153,8 @@ describe('Groups API', () => {
})

it('updates the group', async () => {
const res = await adminTestServer.mutate({
mutation: UPDATE_GROUP,
const res = await adminTestServer.executeOperation({
query: UPDATE_GROUP,
variables: {
id: existingGroup.id,
input: updateParams,
Expand Down Expand Up @@ -182,8 +182,8 @@ describe('Groups API', () => {
})

it('updates the group not including type for captains', async () => {
const res = await testServer.mutate({
mutation: UPDATE_GROUP,
const res = await testServer.executeOperation({
query: UPDATE_GROUP,
variables: {
id: existingGroup.id,
input: omit(updateParams, 'groupType'),
Expand All @@ -195,8 +195,8 @@ describe('Groups API', () => {
})

it('supports setting website to null', async () => {
const res = await adminTestServer.mutate({
mutation: UPDATE_GROUP,
const res = await adminTestServer.executeOperation({
query: UPDATE_GROUP,
variables: {
id: existingGroup.id,
input: { ...updateParams, website: null },
Expand All @@ -208,8 +208,8 @@ describe('Groups API', () => {
})

it('validates the website look like a URL', async () => {
const res = await adminTestServer.mutate({
mutation: UPDATE_GROUP,
const res = await adminTestServer.executeOperation({
query: UPDATE_GROUP,
variables: {
id: existingGroup.id,
input: { ...updateParams, website: 'www.-example.com' },
Expand All @@ -222,8 +222,8 @@ describe('Groups API', () => {
})

it('disallows non-admins from updating group type', async () => {
const res = await testServer.mutate({
mutation: UPDATE_GROUP,
const res = await testServer.executeOperation({
query: UPDATE_GROUP,
variables: {
id: existingGroup.id,
input: updateParams,
Expand All @@ -238,8 +238,8 @@ describe('Groups API', () => {
it('disallows non-admin non-captains from updating', async () => {
const res = await (
await makeTestServer()
).mutate({
mutation: UPDATE_GROUP,
).executeOperation({
query: UPDATE_GROUP,
variables: {
id: existingGroup.id,
input: updateParams,
Expand All @@ -252,7 +252,7 @@ describe('Groups API', () => {
})

describe('reading', () => {
let testServer: ApolloServerTestClient
let testServer: ApolloServer
let captain1: UserAccount, captain2: UserAccount, daCaptain: UserAccount
let sendingGroup1: Group,
receivingGroup1: Group,
Expand Down Expand Up @@ -328,7 +328,7 @@ describe('Groups API', () => {
`
describe('with no id', () => {
it('returns an error', async () => {
const res = await testServer.query({ query: GROUP })
const res = await testServer.executeOperation({ query: GROUP })

expect(res.errors).not.toBeUndefined()
expect(res.errors).not.toBeEmpty()
Expand All @@ -346,7 +346,7 @@ describe('Groups API', () => {
describe('with a parameter passed in', () => {
describe('a valid id', () => {
it('returns the correct group', async () => {
const res = await testServer.query({
const res = await testServer.executeOperation({
query: GROUP,
variables: { id: sendingGroup1.id },
})
Expand All @@ -358,7 +358,7 @@ describe('Groups API', () => {

describe('with an invalid id', () => {
it('returns a nice error', async () => {
const res = await testServer.query({
const res = await testServer.executeOperation({
query: GROUP,
variables: { id: 17 },
})
Expand All @@ -384,7 +384,7 @@ describe('Groups API', () => {

describe('listing groups', () => {
it('lists existing groups', async () => {
const res = await testServer.query({
const res = await testServer.executeOperation({
query: gql`
query listGroups {
listGroups {
Expand Down Expand Up @@ -438,7 +438,7 @@ describe('Groups API', () => {
])(
'search for groups with type %s should yield %s',
async (groupTypes, expectedGroupNames) => {
const res = await testServer.query({
const res = await testServer.executeOperation({
query: gql`
query listGroupsByType($groupType: [GroupType!]) {
listGroups(groupType: $groupType) {
Expand Down Expand Up @@ -468,7 +468,7 @@ describe('Groups API', () => {
])(
'search for groups with captain %s should yield %s',
async (captainName, expectedGroupNames) => {
const res = await testServer.query({
const res = await testServer.executeOperation({
query: gql`
query listGroupsByCaptain($captainId: Int!) {
listGroups(captainId: $captainId) {
Expand Down Expand Up @@ -505,7 +505,7 @@ describe('Groups API', () => {
])(
`combining types %s and captain %s should yield %s`,
async (groupTypes, captainName, expectedGroupNames) => {
const res = await testServer.query({
const res = await testServer.executeOperation({
query: gql`
query listGroupsByCaptainAndType(
$groupType: [GroupType!]
Expand Down
6 changes: 6 additions & 0 deletions src/tests/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GraphQLResponse } from 'apollo-server-types'
import { Maybe } from 'graphql/jsutils/Maybe'
import Group from '../../models/group'
import Shipment from '../../models/shipment'
Expand Down Expand Up @@ -31,3 +32,8 @@ async function createShipment(input: ShipmentCreateInput): Promise<Shipment> {
}

export { createGroup, createShipment }

export type TypedGraphQLResponse<DataType extends Record<string, any>> = Omit<
GraphQLResponse,
'data'
> & { data: DataType | null | undefined }