fix: add deprecated, description, nullable to connectionField (#578)

This commit is contained in:
Tim Griesser 2020-10-27 14:21:30 -04:00 committed by GitHub
parent 2aaaf5cb9f
commit cc12ec16fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 55 additions and 10 deletions

View File

@ -26,7 +26,7 @@ const schema = makeSchema({
], ],
contextType: 't.Context', contextType: 't.Context',
}, },
prettierConfig: require.resolve('../../../package.json'), prettierConfig: require.resolve('../../../.prettierrc'),
}) })
const store = createStore() const store = createStore()

View File

@ -26,5 +26,5 @@ export const schema = makeSchema({
Date: 'Date', Date: 'Date',
}, },
}, },
prettierConfig: require.resolve('../../../package.json'), prettierConfig: require.resolve('../../../.prettierrc'),
}) })

View File

@ -10,7 +10,7 @@ const schema = makeSchema({
schema: path.join(__dirname, '../githunt-api-schema.graphql'), schema: path.join(__dirname, '../githunt-api-schema.graphql'),
typegen: path.join(__dirname, './githunt-typegen.ts'), typegen: path.join(__dirname, './githunt-typegen.ts'),
}, },
prettierConfig: require.resolve('../../../package.json'), prettierConfig: require.resolve('../../../.prettierrc'),
}) })
const server = new ApolloServer({ const server = new ApolloServer({

View File

@ -146,6 +146,27 @@ type Query {
): BooleanConnection ): BooleanConnection
complexQuery(count: Int!): [ComplexObject] complexQuery(count: Int!): [ComplexObject]
dateAsList: [Date] 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 extended: SomeItem
getNumberOrNull(a: Int!): Int getNumberOrNull(a: Int!): Int
guardedConnection( guardedConnection(
@ -200,6 +221,10 @@ type Query {
""" """
first: Int! first: Int!
): UserConnection ): UserConnection
"""
A connection with some user nodes
"""
usersConnectionNodes( usersConnectionNodes(
""" """
Returns the elements in the list that come after the specified cursor Returns the elements in the list that come after the specified cursor

View File

@ -43,7 +43,7 @@ const schema = makeSchema({
}, },
}), }),
], ],
prettierConfig: require.resolve('../../../package.json'), prettierConfig: require.resolve('../../../.prettierrc'),
}) })
const server = new ApolloServer({ const server = new ApolloServer({

View File

@ -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', { t.connectionField('guardedConnection', {
type: 'Date', type: 'Date',
disableBackwardPagination: true, disableBackwardPagination: true,
@ -217,6 +226,7 @@ export const Query = objectType({
t.connectionField('usersConnectionNodes', { t.connectionField('usersConnectionNodes', {
type: User, type: User,
description: 'A connection with some user nodes',
cursorFromNode(node, args, ctx, info, { index, nodes }) { cursorFromNode(node, args, ctx, info, { index, nodes }) {
if (args.last && !args.before) { if (args.last && !args.before) {
const totalCount = USERS_DATA.length const totalCount = USERS_DATA.length

View File

@ -201,6 +201,7 @@ export interface NexusGenFieldTypes {
booleanConnection: NexusGenRootTypes['BooleanConnection'] | null // BooleanConnection booleanConnection: NexusGenRootTypes['BooleanConnection'] | null // BooleanConnection
complexQuery: Array<NexusGenRootTypes['ComplexObject'] | null> | null // [ComplexObject] complexQuery: Array<NexusGenRootTypes['ComplexObject'] | null> | null // [ComplexObject]
dateAsList: Array<NexusGenScalars['Date'] | null> | null // [Date] dateAsList: Array<NexusGenScalars['Date'] | null> | null // [Date]
deprecatedConnection: NexusGenRootTypes['BooleanConnection'] // BooleanConnection!
extended: NexusGenRootTypes['SomeItem'] | null // SomeItem extended: NexusGenRootTypes['SomeItem'] | null // SomeItem
getNumberOrNull: number | null // Int getNumberOrNull: number | null // Int
guardedConnection: NexusGenRootTypes['DateConnection'] | null // DateConnection guardedConnection: NexusGenRootTypes['DateConnection'] | null // DateConnection
@ -310,6 +311,7 @@ export interface NexusGenFieldTypeNames {
booleanConnection: 'BooleanConnection' booleanConnection: 'BooleanConnection'
complexQuery: 'ComplexObject' complexQuery: 'ComplexObject'
dateAsList: 'Date' dateAsList: 'Date'
deprecatedConnection: 'BooleanConnection'
extended: 'SomeItem' extended: 'SomeItem'
getNumberOrNull: 'Int' getNumberOrNull: 'Int'
guardedConnection: 'DateConnection' guardedConnection: 'DateConnection'
@ -396,6 +398,13 @@ export interface NexusGenArgTypes {
// args // args
count: number // Int! count: number // Int!
} }
deprecatedConnection: {
// args
after?: string | null // String
before?: string | null // String
first?: number | null // Int
last?: number | null // Int
}
getNumberOrNull: { getNumberOrNull: {
// args // args
a: number // Int! a: number // Int!

View File

@ -31,5 +31,5 @@ export const schema = makeSchema({
], ],
contextType: 'swapi.ContextType', contextType: 'swapi.ContextType',
}, },
prettierConfig: require.resolve('../../../package.json'), prettierConfig: require.resolve('../../../.prettierrc'),
}) })

View File

@ -29,7 +29,7 @@ export const schema = makeSchema({
}, },
// debug: true, // debug: true,
}, },
prettierConfig: require.resolve('../../../package.json'), prettierConfig: require.resolve('../../../.prettierrc'),
}) })
/** /**

View File

@ -34,7 +34,7 @@
"clean": "rm -rf dist*", "clean": "rm -rf dist*",
"deploy-site": "yarn && yarn build", "deploy-site": "yarn && yarn build",
"dev": "tsc -p tsconfig.cjs.json -w", "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", "dev:test": "jest --watch",
"examples": "yarn link-examples && yarn gulp run-examples", "examples": "yarn link-examples && yarn gulp run-examples",
"format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts' 'examples/*/src/**.ts'", "format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts' 'examples/*/src/**.ts'",

View File

@ -34,11 +34,11 @@ gulp.task('link-examples', async () => {
}) })
gulp.task('api-tsc', () => { 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', () => { gulp.task('core-tsc', () => {
runService('yarn', 'tsc -w -p tsconfig.json', { runService('yarn', 'tsc -w -p tsconfig.cjs.json', {
stdio: 'ignore', stdio: 'ignore',
cwd: path.join(__dirname, '..'), cwd: path.join(__dirname, '..'),
}) })

View File

@ -1,6 +1,6 @@
import { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql' import { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql'
import { ArgsRecord, intArg, stringArg } from '../definitions/args' 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 { ObjectDefinitionBlock, objectType } from '../definitions/objectType'
import { AllNexusOutputTypeDefs } from '../definitions/wrapping' import { AllNexusOutputTypeDefs } from '../definitions/wrapping'
import { dynamicOutputMethod } from '../dynamicMethod' import { dynamicOutputMethod } from '../dynamicMethod'
@ -246,6 +246,7 @@ export type ConnectionFieldConfig<TypeName extends string = any, FieldName exten
nodes?: never nodes?: never
} }
) & ) &
Pick<CommonFieldConfig, 'deprecation' | 'description' | 'nullable'> &
NexusGenPluginFieldConfig<TypeName, FieldName> NexusGenPluginFieldConfig<TypeName, FieldName>
const ForwardPaginateArgs = { const ForwardPaginateArgs = {