nexus/tests/nonNullDefaults.spec.ts

58 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

2020-11-28 03:22:48 +08:00
import { lexicographicSortSchema, printSchema } from 'graphql'
import { core, intArg, makeSchema, queryType } from '../src'
2019-02-03 06:44:06 +08:00
describe('nonNullDefaults', () => {
test('true/true on schema', () => {
2019-02-03 06:44:06 +08:00
const schema = makeSchema({
types: [makeQuery()],
outputs: false,
nonNullDefaults: {
input: true,
output: true,
},
})
2020-11-28 03:22:48 +08:00
expect(printSchema(lexicographicSortSchema(schema))).toMatchSnapshot()
})
test('true/true on type', () => {
2019-02-03 06:44:06 +08:00
const schema = makeSchema({
types: [makeQuery({ nonNullDefaults: { input: true, output: true } })],
outputs: false,
})
2020-11-28 03:22:48 +08:00
expect(printSchema(lexicographicSortSchema(schema))).toMatchSnapshot()
})
test('false/false on schema', () => {
2019-02-03 06:44:06 +08:00
const schema = makeSchema({
types: [makeQuery()],
outputs: false,
nonNullDefaults: {
input: false,
output: false,
},
})
2020-11-28 03:22:48 +08:00
expect(printSchema(lexicographicSortSchema(schema))).toMatchSnapshot()
})
test('false/false on type', () => {
2019-02-03 06:44:06 +08:00
const schema = makeSchema({
types: [makeQuery({ nonNullDefaults: { input: false, output: false } })],
outputs: false,
})
2020-11-28 03:22:48 +08:00
expect(printSchema(lexicographicSortSchema(schema))).toMatchSnapshot()
})
})
2019-02-03 06:44:06 +08:00
function makeQuery(config?: Partial<core.NexusObjectTypeConfig<string>>) {
return queryType({
...config,
definition(t) {
t.boolean('test', {
2019-02-03 06:44:06 +08:00
args: {
test: intArg(),
},
})
t.list.field('stringList', {
type: 'String',
})
2019-02-03 06:44:06 +08:00
},
})
2019-02-03 06:44:06 +08:00
}