-
-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand extended interface selections for subservice compatibility (#1912
) * failing test. * expand extended interfaces. * shrink diff. * add additional merging test. * specify missing type.
- Loading branch information
Showing
2 changed files
with
212 additions
and
31 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
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,125 @@ | ||
import { graphql } from 'graphql'; | ||
import { makeExecutableSchema } from '@graphql-tools/schema'; | ||
import { stitchSchemas } from '../src/stitchSchemas'; | ||
|
||
describe('extended interfaces', () => { | ||
test('expands extended interface types for subservices', async () => { | ||
const itemsSchema = makeExecutableSchema({ | ||
typeDefs: ` | ||
interface Slot { | ||
id: ID! | ||
} | ||
type Item implements Slot { | ||
id: ID! | ||
name: String! | ||
} | ||
type Query { | ||
slot: Slot | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
slot(obj, args, context, info) { | ||
return { __typename: 'Item', id: '23', name: 'The Item' }; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const stitchedSchema = stitchSchemas({ | ||
subschemas: [ | ||
{ schema: itemsSchema }, | ||
], | ||
typeDefs: ` | ||
extend interface Slot { | ||
name: String! | ||
} | ||
`, | ||
}); | ||
|
||
const { data } = await graphql(stitchedSchema, ` | ||
query { | ||
slot { | ||
id | ||
name | ||
} | ||
} | ||
`); | ||
|
||
expect(data.slot).toEqual({ id: '23', name: 'The Item' }); | ||
}); | ||
|
||
test('merges types behind gateway interface extension', async () => { | ||
const itemsSchema = makeExecutableSchema({ | ||
typeDefs: ` | ||
type Item { | ||
id: ID! | ||
name: String! | ||
} | ||
type Query { | ||
itemById(id: ID!): Item | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
itemById(obj, args, context, info) { | ||
return { id: args.id, name: `Item ${args.id}` }; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const placementSchema = makeExecutableSchema({ | ||
typeDefs: ` | ||
interface Placement { | ||
id: ID! | ||
} | ||
type Item implements Placement { | ||
id: ID! | ||
} | ||
type Query { | ||
placementById(id: ID!): Placement | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
placementById(obj, args, context, info) { | ||
return { __typename: 'Item', id: args.id }; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const stitchedSchema = stitchSchemas({ | ||
subschemas: [ | ||
{ | ||
schema: itemsSchema, | ||
merge: { | ||
Item: { | ||
selectionSet: '{ id }', | ||
fieldName: 'itemById', | ||
args: ({ id }) => ({ id }), | ||
} | ||
} | ||
}, | ||
{ schema: placementSchema }, | ||
], | ||
typeDefs: ` | ||
extend interface Placement { | ||
name: String! | ||
} | ||
`, | ||
}); | ||
|
||
const result = await graphql(stitchedSchema, ` | ||
query { | ||
placement: placementById(id: 23) { | ||
id | ||
name | ||
} | ||
} | ||
`); | ||
|
||
expect(result.data.placement).toEqual({ id: '23', name: 'Item 23' }); | ||
}); | ||
}); |