Open
Description
The problem
When using overrides, nested objects are not wrapping their correspondent mock function. Instead they just apply the raw object provided by the user. This could result in some missing keys for that GQL schema node.
It would be good if we apply the mock function for that nested object and pass it as an override.
aUser({
// This is missing other nested keys.
viewingControls: {
lastModifiedDate: '10/02/2001',
},
});
Example
Given some config, for ex.
[`${CODEGEN_DIR}graphql-mocks.ts`]: {
plugins: [
{
'typescript-mock-data': {
typesFile: './graphql.ts',
nestedOverrides: true
},
}
],
},
Instead of
export const aUser = (overrides?: Partial<User>, _relationshipsToOmit: Set<string> = new Set()): { __typename: 'User' } & User => {
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit);
relationshipsToOmit.add('User');
return {
__typename: 'User',
_id: overrides && overrides.hasOwnProperty('_id') ? overrides._id! : 'dc8ad6c2-78d6-4914-a958-38a7e195fcf9',
viewingControls: overrides && overrides.hasOwnProperty('viewingControls') ? overrides.viewingControls! : relationshipsToOmit.has('ViewingControls') ? {} as ViewingControls : aViewingControls({}, relationshipsToOmit),
};
};
we could
export const aUser = (overrides?: Partial<User>, _relationshipsToOmit: Set<string> = new Set()): { __typename: 'User' } & User => {
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit);
relationshipsToOmit.add('User');
return {
__typename: 'User',
_id: overrides && overrides.hasOwnProperty('_id') ? overrides._id! : 'dc8ad6c2-78d6-4914-a958-38a7e195fcf9',
viewingControls: overrides && overrides.hasOwnProperty('viewingControls') ? aViewingControls(overrides.viewingControls) : relationshipsToOmit.has('ViewingControls') ? {} as ViewingControls : aViewingControls({}, relationshipsToOmit),
};
};
Metadata
Metadata
Assignees
Labels
No labels