Skip to content

Commit 026fe91

Browse files
committed
fix(settings): connections includes props from core 2
1 parent 36ab27a commit 026fe91

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/runtime/schema/settings.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,45 @@ it('has defaults', () => {
2828
})
2929

3030
describe('connctions', () => {
31-
it('can be changed, preserving the core defaults', () => {
31+
it('can be set empty, doing nothing', () => {
3232
const original = cloneDeep(sm.data)
3333
sm.change({ connections: {} })
3434
expect(sm.data).toEqual(original)
3535
})
36+
it('new types can be added getting the core settings', () => {
37+
sm.change({ connections: { a: {} } })
38+
expect(sm.data.connections).toMatchInlineSnapshot(`
39+
Object {
40+
"a": Object {
41+
"nexusFieldName": "connection",
42+
"nexusSchemaImportId": "nexus/components/schema",
43+
},
44+
"default": Object {
45+
"nexusFieldName": "connection",
46+
"nexusSchemaImportId": "nexus/components/schema",
47+
},
48+
}
49+
`)
50+
})
51+
it('existing custom types can be changed, preserving its core settings', () => {
52+
sm.change({ connections: { a: {} } }) // test above says this has the core settings
53+
sm.change({ connections: { a: { disableForwardPagination: true } } })
54+
expect(sm.data.connections.a).toMatchInlineSnapshot(`
55+
Object {
56+
"disableForwardPagination": true,
57+
"nexusFieldName": "connection",
58+
"nexusSchemaImportId": "nexus/components/schema",
59+
}
60+
`)
61+
})
62+
it('default types can be changed, preserving its core settings', () => {
63+
sm.change({ connections: { default: { disableForwardPagination: true } } })
64+
expect(sm.data.connections.default).toMatchInlineSnapshot(`
65+
Object {
66+
"disableForwardPagination": true,
67+
"nexusFieldName": "connection",
68+
"nexusSchemaImportId": "nexus/components/schema",
69+
}
70+
`)
71+
})
3672
})

src/runtime/schema/settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ export function changeSettings(state: SettingsData, newSettings: SettingsInput):
146146
}
147147

148148
if (newSettings.connections) {
149+
Object.keys(newSettings.connections)
150+
// must already have the defaults
151+
.filter((key) => state.connections[key] === undefined)
152+
.forEach((key) => {
153+
state.connections[key] = Lo.merge(state.connections[key], connectionPluginConfigManagedByNexus)
154+
})
149155
Lo.merge(state.connections, newSettings.connections)
150156
}
151157
}

0 commit comments

Comments
 (0)