Skip to content

Commit

Permalink
fix: add deprecated, description, nullable to connectionField (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Oct 27, 2020
1 parent 2aaaf5c commit cc12ec1
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/apollo-fullstack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const schema = makeSchema({
],
contextType: 't.Context',
},
prettierConfig: require.resolve('../../../package.json'),
prettierConfig: require.resolve('../../../.prettierrc'),
})

const store = createStore()
Expand Down
2 changes: 1 addition & 1 deletion examples/ghost/src/ghost-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export const schema = makeSchema({
Date: 'Date',
},
},
prettierConfig: require.resolve('../../../package.json'),
prettierConfig: require.resolve('../../../.prettierrc'),
})
2 changes: 1 addition & 1 deletion examples/githunt-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const schema = makeSchema({
schema: path.join(__dirname, '../githunt-api-schema.graphql'),
typegen: path.join(__dirname, './githunt-typegen.ts'),
},
prettierConfig: require.resolve('../../../package.json'),
prettierConfig: require.resolve('../../../.prettierrc'),
})

const server = new ApolloServer({
Expand Down
25 changes: 25 additions & 0 deletions examples/kitchen-sink/kitchen-sink-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ type Query {
): BooleanConnection
complexQuery(count: Int!): [ComplexObject]
dateAsList: [Date]
deprecatedConnection(
"""
Returns the elements in the list that come after the specified cursor
"""
after: String

"""
Returns the elements in the list that come before the specified cursor
"""
before: String

"""
Returns the first n elements from the list.
"""
first: Int

"""
Returns the last n elements from the list.
"""
last: Int
): BooleanConnection! @deprecated(reason: "Dont use this, use booleanConnection instead")
extended: SomeItem
getNumberOrNull(a: Int!): Int
guardedConnection(
Expand Down Expand Up @@ -200,6 +221,10 @@ type Query {
"""
first: Int!
): UserConnection

"""
A connection with some user nodes
"""
usersConnectionNodes(
"""
Returns the elements in the list that come after the specified cursor
Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const schema = makeSchema({
},
}),
],
prettierConfig: require.resolve('../../../package.json'),
prettierConfig: require.resolve('../../../.prettierrc'),
})

const server = new ApolloServer({
Expand Down
10 changes: 10 additions & 0 deletions examples/kitchen-sink/src/kitchen-sink-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ export const Query = objectType({
},
})

t.connectionField('deprecatedConnection', {
type: 'Boolean',
deprecation: 'Dont use this, use booleanConnection instead',
nullable: false,
nodes() {
return [true]
},
})

t.connectionField('guardedConnection', {
type: 'Date',
disableBackwardPagination: true,
Expand All @@ -217,6 +226,7 @@ export const Query = objectType({

t.connectionField('usersConnectionNodes', {
type: User,
description: 'A connection with some user nodes',
cursorFromNode(node, args, ctx, info, { index, nodes }) {
if (args.last && !args.before) {
const totalCount = USERS_DATA.length
Expand Down
9 changes: 9 additions & 0 deletions examples/kitchen-sink/src/kitchen-sink.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export interface NexusGenFieldTypes {
booleanConnection: NexusGenRootTypes['BooleanConnection'] | null // BooleanConnection
complexQuery: Array<NexusGenRootTypes['ComplexObject'] | null> | null // [ComplexObject]
dateAsList: Array<NexusGenScalars['Date'] | null> | null // [Date]
deprecatedConnection: NexusGenRootTypes['BooleanConnection'] // BooleanConnection!
extended: NexusGenRootTypes['SomeItem'] | null // SomeItem
getNumberOrNull: number | null // Int
guardedConnection: NexusGenRootTypes['DateConnection'] | null // DateConnection
Expand Down Expand Up @@ -310,6 +311,7 @@ export interface NexusGenFieldTypeNames {
booleanConnection: 'BooleanConnection'
complexQuery: 'ComplexObject'
dateAsList: 'Date'
deprecatedConnection: 'BooleanConnection'
extended: 'SomeItem'
getNumberOrNull: 'Int'
guardedConnection: 'DateConnection'
Expand Down Expand Up @@ -396,6 +398,13 @@ export interface NexusGenArgTypes {
// args
count: number // Int!
}
deprecatedConnection: {
// args
after?: string | null // String
before?: string | null // String
first?: number | null // Int
last?: number | null // Int
}
getNumberOrNull: {
// args
a: number // Int!
Expand Down
2 changes: 1 addition & 1 deletion examples/star-wars/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export const schema = makeSchema({
],
contextType: 'swapi.ContextType',
},
prettierConfig: require.resolve('../../../package.json'),
prettierConfig: require.resolve('../../../.prettierrc'),
})
2 changes: 1 addition & 1 deletion examples/ts-ast-reader/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const schema = makeSchema({
},
// debug: true,
},
prettierConfig: require.resolve('../../../package.json'),
prettierConfig: require.resolve('../../../.prettierrc'),
})

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"clean": "rm -rf dist*",
"deploy-site": "yarn && yarn build",
"dev": "tsc -p tsconfig.cjs.json -w",
"dev:examples": "yarn -s link-examples && tsc -w",
"dev:examples": "yarn -s link-examples && yarn dev",
"dev:test": "jest --watch",
"examples": "yarn link-examples && yarn gulp run-examples",
"format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts' 'examples/*/src/**.ts'",
Expand Down
4 changes: 2 additions & 2 deletions scripts/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ gulp.task('link-examples', async () => {
})

gulp.task('api-tsc', () => {
runService('yarn', 'tsc -w -p api/tsconfig.json', { stdio: 'ignore' })
runService('yarn', 'tsc -w -p api/tsconfig.cjs.json', { stdio: 'ignore' })
})

gulp.task('core-tsc', () => {
runService('yarn', 'tsc -w -p tsconfig.json', {
runService('yarn', 'tsc -w -p tsconfig.cjs.json', {
stdio: 'ignore',
cwd: path.join(__dirname, '..'),
})
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/connectionPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql'
import { ArgsRecord, intArg, stringArg } from '../definitions/args'
import { FieldOutConfig } from '../definitions/definitionBlocks'
import { CommonFieldConfig, FieldOutConfig } from '../definitions/definitionBlocks'
import { ObjectDefinitionBlock, objectType } from '../definitions/objectType'
import { AllNexusOutputTypeDefs } from '../definitions/wrapping'
import { dynamicOutputMethod } from '../dynamicMethod'
Expand Down Expand Up @@ -246,6 +246,7 @@ export type ConnectionFieldConfig<TypeName extends string = any, FieldName exten
nodes?: never
}
) &
Pick<CommonFieldConfig, 'deprecation' | 'description' | 'nullable'> &
NexusGenPluginFieldConfig<TypeName, FieldName>

const ForwardPaginateArgs = {
Expand Down

0 comments on commit cc12ec1

Please sign in to comment.