-
-
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.
fix(typeMerging): fix interface merging
thanks go to @gmac for finding this bug and contributing test code see: #1911 (comment)
- Loading branch information
Showing
2 changed files
with
109 additions
and
12 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,82 @@ | ||
import { graphql } from 'graphql'; | ||
import { makeExecutableSchema } from '@graphql-tools/schema'; | ||
import { stitchSchemas } from '../src/stitchSchemas'; | ||
|
||
describe('merging interfaces', () => { | ||
test('merges interfaces across subschemas', async () => { | ||
const namedItemSchema = makeExecutableSchema({ | ||
typeDefs: ` | ||
interface Placement { | ||
id: ID! | ||
name: String! | ||
} | ||
type Item implements Placement { | ||
id: ID! | ||
name: String! | ||
} | ||
type Query { | ||
itemById(id: ID!): Item | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
itemById(_obj, args) { | ||
return { id: args.id, name: `Item ${args.id}` }; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const indexedItemSchema = makeExecutableSchema({ | ||
typeDefs: ` | ||
interface Placement { | ||
id: ID! | ||
index: Int! | ||
} | ||
type Item implements Placement { | ||
id: ID! | ||
index: Int! | ||
} | ||
type Query { | ||
placementById(id: ID!): Placement | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
placementById(_obj, args) { | ||
return { __typename: 'Item', id: args.id, index: Number(args.id) }; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const stitchedSchema = stitchSchemas({ | ||
subschemas: [ | ||
{ | ||
schema: namedItemSchema, | ||
merge: { | ||
Item: { | ||
selectionSet: '{ id }', | ||
fieldName: 'itemById', | ||
args: ({ id }) => ({ id }), | ||
} | ||
} | ||
}, | ||
{ schema: indexedItemSchema }, | ||
], | ||
mergeTypes: true, | ||
}); | ||
|
||
const result = await graphql(stitchedSchema, ` | ||
query { | ||
placement: placementById(id: 23) { | ||
id | ||
index | ||
name | ||
} | ||
} | ||
`); | ||
|
||
expect(result.data.placement).toEqual({ id: '23', index: 23, name: 'Item 23' }); | ||
}); | ||
}); |