Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
queicherius committed Dec 5, 2024
1 parent ec43763 commit 85f5609
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ export async function findManyCursorConnection<
}

const options = mergeDefaultOptions(pOptions)
const requestedFields = options.resolveInfo && Object.keys(graphqlFields(options.resolveInfo))
const hasRequestedField = (key: string) => !requestedFields || requestedFields.includes(key)

let requestedFields: Array<string> | undefined = undefined
if (options.resolveInfo) {
const _graphqlFields = graphqlFields(options.resolveInfo) as { [key: string]: unknown }
requestedFields = Object.keys(_graphqlFields)
}
const hasRequestedField = (key: string): boolean =>
!requestedFields || requestedFields.includes(key)

let records: Array<Record>
let totalCount: number
Expand Down
41 changes: 19 additions & 22 deletions tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { mocked } from 'jest-mock'
import { ConnectionArguments, findManyCursorConnection } from '../src'
import { PROFILE_FIXTURES, TODO_FIXTURES, USER_FIXTURES } from './fixtures'

function encodeCursor<Cursor>(prismaCursor: Cursor) {
function encodeCursor<Cursor>(prismaCursor: Cursor): string {
return Buffer.from(JSON.stringify(prismaCursor)).toString('base64')
}

function decodeCursor(cursor: string) {
function decodeCursor<Cursor>(cursor: string): Cursor {
return JSON.parse(Buffer.from(cursor, 'base64').toString('ascii'))
}

Expand All @@ -21,7 +21,7 @@ describe('prisma-relay-cursor-connection', () => {
jest.setTimeout(10000)
let client: PrismaClient

beforeAll(async () => {
beforeAll(() => {
client = new PrismaClient()
})

Expand Down Expand Up @@ -89,22 +89,22 @@ describe('prisma-relay-cursor-connection', () => {
expect(result).toMatchSnapshot()

// Test that the return types work via TS
result.edges[0].node.isCompleted
expect(result.edges[0].node.isCompleted)

// @ts-expect-error Typo in selected field
result.edges[0].node.isCompletedd
expect(result.edges[0].node.isCompletedd)

// @ts-expect-error Not selected field
result.edges[0].node.text
expect(result.edges[0].node.text)

// Test that the return types work via TS
result.nodes[0].isCompleted
expect(result.nodes[0].isCompleted)

// @ts-expect-error Typo in selected field
result.nodes[0].isCompletedd
expect(result.nodes[0].isCompletedd)

// @ts-expect-error Not selected field
result.nodes[0].text
expect(result.nodes[0].text)
})
})

Expand Down Expand Up @@ -200,22 +200,22 @@ describe('prisma-relay-cursor-connection', () => {
expect(result).toMatchSnapshot()

// Test that the return types work via TS
result.edges[0].node.email
expect(result.edges[0].node.email)

// @ts-expect-error Typo in selected field
result.edges[0].node.emmail
expect(result.edges[0].node.emmail)

// @ts-expect-error Not selected field
result.edges[0].node.text
expect(result.edges[0].node.text)

// Test that the return types work via TS
result.nodes[0].email
expect(result.nodes[0].email)

// @ts-expect-error Typo in selected field
result.nodes[0].emmail
expect(result.nodes[0].emmail)

// @ts-expect-error Not selected field
result.nodes[0].text
expect(result.nodes[0].text)
})
})

Expand Down Expand Up @@ -469,13 +469,13 @@ describe('prisma-relay-cursor-connection', () => {
expect(result).toMatchSnapshot()

// Test that the node.extraNodeField return types work via TS
result.edges[0]?.node.extraNodeField
expect(result.edges[0]?.node.extraNodeField)

// Test that the extraEdgeField return type work via TS
result.edges[0]?.extraEdgeField
expect(result.edges[0]?.extraEdgeField)

// Test that the node.extraNodeField return types work via TS
result.nodes[0]?.extraNodeField
expect(result.nodes[0]?.extraNodeField)
})
})

Expand Down Expand Up @@ -564,8 +564,7 @@ describe('prisma-relay-cursor-connection', () => {
})

// These are not real tests which run, but rather a way to ensure that the types are correct
// when tsc runs
const typecheckForInferredTypes = async () => {
export const typecheckForInferredTypes = async (): Promise<void> => {
const client = new PrismaClient()

// Default will get the inferred types from prisma
Expand Down Expand Up @@ -610,5 +609,3 @@ const typecheckForInferredTypes = async () => {
}[]
}
}

typecheckForInferredTypes

0 comments on commit 85f5609

Please sign in to comment.