Skip to content

Commit 2340231

Browse files
authored
Confirm that __typename is removed from result when union type is used (#1872)
1 parent 05033e6 commit 2340231

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/plugins/response-cache/test/response-cache.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,57 @@ describe('useResponseCache', () => {
18871887
});
18881888
});
18891889

1890+
it('does not include __typename in result if mot selected via selection set (union type)', async () => {
1891+
const schema = makeExecutableSchema({
1892+
typeDefs: /* GraphQL */ `
1893+
type Query {
1894+
user: User
1895+
}
1896+
1897+
union User = Admin | Customer
1898+
1899+
type Admin {
1900+
id: ID!
1901+
login: String!
1902+
}
1903+
1904+
type Customer {
1905+
id: ID!
1906+
name: String!
1907+
}
1908+
`,
1909+
resolvers: {
1910+
Query: {
1911+
user: () => ({ __typename: 'Admin', id: 1, login: 'root' }),
1912+
},
1913+
},
1914+
});
1915+
const testkit = createTestkit([useResponseCache({ session: () => null })], schema);
1916+
const result = await testkit.execute(/* GraphQL */ `
1917+
query {
1918+
user {
1919+
... on Admin {
1920+
id
1921+
login
1922+
}
1923+
... on Customer {
1924+
id
1925+
name
1926+
}
1927+
}
1928+
}
1929+
`);
1930+
assertSingleExecutionValue(result);
1931+
expect(result).toEqual({
1932+
data: {
1933+
user: {
1934+
id: '1',
1935+
login: 'root',
1936+
},
1937+
},
1938+
});
1939+
});
1940+
18901941
it('works properly if __typename within selection set is aliased', async () => {
18911942
const schema = makeExecutableSchema({
18921943
typeDefs: /* GraphQL */ `

0 commit comments

Comments
 (0)