-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Error when using useImplementingTypes and terminateCircularRelat…
…ionships at the same time
- Loading branch information
Showing
4 changed files
with
130 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tests/useImplementingTypesAndTerminateCircularRelationships/__snapshots__/spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should support useImplementingTypes and terminateCircularRelationships at the same time 1`] = ` | ||
" | ||
export const mockQuery = (overrides?: Partial<Query>, _relationshipsToOmit: Set<string> = new Set()): Query => { | ||
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit); | ||
relationshipsToOmit.add('Query'); | ||
return { | ||
getUser: overrides && overrides.hasOwnProperty('getUser') ? overrides.getUser! : relationshipsToOmit.has('User') ? {} as User : mockUser({}, relationshipsToOmit), | ||
}; | ||
}; | ||
export const mockUser = (overrides?: Partial<User>, _relationshipsToOmit: Set<string> = new Set()): User => { | ||
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit); | ||
relationshipsToOmit.add('User'); | ||
return { | ||
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'est', | ||
events: overrides && overrides.hasOwnProperty('events') ? overrides.events! : [relationshipsToOmit.has('MeetingEvent') ? {} as MeetingEvent : mockMeetingEvent({}, relationshipsToOmit) || relationshipsToOmit.has('OtherEvent') ? {} as OtherEvent : mockOtherEvent({}, relationshipsToOmit)], | ||
}; | ||
}; | ||
export const mockEvent = (overrides?: Partial<Event>, _relationshipsToOmit: Set<string> = new Set()): Event => { | ||
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit); | ||
relationshipsToOmit.add('Event'); | ||
return { | ||
startDate: overrides && overrides.hasOwnProperty('startDate') ? overrides.startDate! : 'sunt', | ||
endDate: overrides && overrides.hasOwnProperty('endDate') ? overrides.endDate! : 'harum', | ||
timeZone: overrides && overrides.hasOwnProperty('timeZone') ? overrides.timeZone! : 'voluptatem', | ||
}; | ||
}; | ||
export const mockMeetingEvent = (overrides?: Partial<MeetingEvent>, _relationshipsToOmit: Set<string> = new Set()): MeetingEvent => { | ||
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit); | ||
relationshipsToOmit.add('MeetingEvent'); | ||
return { | ||
endDate: overrides && overrides.hasOwnProperty('endDate') ? overrides.endDate! : 'quae', | ||
startDate: overrides && overrides.hasOwnProperty('startDate') ? overrides.startDate! : 'aspernatur', | ||
timeZone: overrides && overrides.hasOwnProperty('timeZone') ? overrides.timeZone! : 'quos', | ||
event: overrides && overrides.hasOwnProperty('event') ? overrides.event! : relationshipsToOmit.has('MeetingEvent') ? {} as MeetingEvent : mockMeetingEvent({}, relationshipsToOmit) || relationshipsToOmit.has('OtherEvent') ? {} as OtherEvent : mockOtherEvent({}, relationshipsToOmit), | ||
}; | ||
}; | ||
export const mockOtherEvent = (overrides?: Partial<OtherEvent>, _relationshipsToOmit: Set<string> = new Set()): OtherEvent => { | ||
const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit); | ||
relationshipsToOmit.add('OtherEvent'); | ||
return { | ||
endDate: overrides && overrides.hasOwnProperty('endDate') ? overrides.endDate! : 'ut', | ||
startDate: overrides && overrides.hasOwnProperty('startDate') ? overrides.startDate! : 'neque', | ||
timeZone: overrides && overrides.hasOwnProperty('timeZone') ? overrides.timeZone! : 'aut', | ||
somethingElse: overrides && overrides.hasOwnProperty('somethingElse') ? overrides.somethingElse! : 'ut', | ||
}; | ||
}; | ||
" | ||
`; |
32 changes: 32 additions & 0 deletions
32
tests/useImplementingTypesAndTerminateCircularRelationships/schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { buildSchema } from 'graphql'; | ||
|
||
export default buildSchema(/* GraphQL */ ` | ||
type Query { | ||
getUser(id: String!): User | ||
} | ||
type User { | ||
id: String! | ||
events: [Event!] | ||
} | ||
interface Event { | ||
startDate: String | ||
endDate: String | ||
timeZone: String | ||
} | ||
type MeetingEvent implements Event { | ||
endDate: String | ||
startDate: String | ||
timeZone: String | ||
event: Event! | ||
} | ||
type OtherEvent implements Event { | ||
endDate: String | ||
startDate: String | ||
timeZone: String | ||
somethingElse: String! | ||
} | ||
`); |
22 changes: 22 additions & 0 deletions
22
tests/useImplementingTypesAndTerminateCircularRelationships/spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { plugin } from '../../src'; | ||
import testSchema from './schema'; | ||
|
||
it('should support useImplementingTypes and terminateCircularRelationships at the same time', async () => { | ||
const result = await plugin(testSchema, [], { | ||
prefix: 'mock', | ||
useImplementingTypes: true, | ||
terminateCircularRelationships: true, | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
|
||
expect(result).toContain( | ||
"events: overrides && overrides.hasOwnProperty('events') ? overrides.events! : [relationshipsToOmit.has('MeetingEvent') ? {} as MeetingEvent : mockMeetingEvent({}, relationshipsToOmit) || relationshipsToOmit.has('OtherEvent') ? {} as OtherEvent : mockOtherEvent({}, relationshipsToOmit)]", | ||
); | ||
|
||
expect(result).toContain( | ||
"event: overrides && overrides.hasOwnProperty('event') ? overrides.event! : relationshipsToOmit.has('MeetingEvent') ? {} as MeetingEvent : mockMeetingEvent({}, relationshipsToOmit) || relationshipsToOmit.has('OtherEvent') ? {} as OtherEvent : mockOtherEvent({}, relationshipsToOmit)", | ||
); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); |