Skip to content

Commit

Permalink
test: selecting typename should not return optional (#8813)
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Jan 16, 2023
1 parent ddffc10 commit 7912f8f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ export type AnimalFragmentFragment = AnimalFragment_Bat_Fragment | AnimalFragmen
"
`;
exports[`TypeScript Operations Plugin Issues #8793 selecting __typename should not be optional 1`] = `
"export type SnakeQueryQueryVariables = Exact<{ [key: string]: never; }>;
export type SnakeQueryQuery = { __typename: 'Query', snake: { __typename: 'Snake' } | { __typename: 'Error' } };
"
`;
exports[`TypeScript Operations Plugin Selection Set Should generate the correct __typename when using both inline fragment and spread over type 1`] = `
"export type UserQueryQueryVariables = Exact<{ [key: string]: never; }>;
Expand Down
48 changes: 48 additions & 0 deletions packages/plugins/typescript/operations/tests/ts-documents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5945,6 +5945,54 @@ function test(q: GetEntityBrandDataQuery): void {

expect(content).toMatchSnapshot();
});

it('#8793 selecting __typename should not be optional', async () => {
const testSchema = buildSchema(/* GraphQL */ `
interface Animal {
name: String!
}
type Bat implements Animal {
name: String!
features: BatFeatures!
}
type BatFeatures {
color: String!
wingspan: Int!
}
type Snake implements Animal {
name: String!
features: SnakeFeatures!
}
type SnakeFeatures {
color: String!
length: Int!
}
type Error {
message: String!
}
union SnakeResult = Snake | Error
type Query {
snake: SnakeResult!
}
`);

const query = parse(/* GraphQL */ `
query SnakeQuery {
__typename
snake {
__typename
}
}
`);

const config = { preResolveTypes: true };

const { content } = await plugin(testSchema, [{ location: '', document: query }], config, {
outputFile: 'graphql.ts',
});

expect(content).toMatchSnapshot();
});
});

describe('conditional directives handling', () => {
Expand Down
2 changes: 1 addition & 1 deletion website/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default withGuildDocs({
'/docs/custom-codegen/using-handlebars': '/docs/custom-codegen',
'/plugins/presets/near-operation-file': '/plugins/presets/near-operation-file-preset',
'/plugins/typescript/near-operation-file': '/plugins/presets/near-operation-file-preset',
'/typescript/typescript-resolvers': '/plugins/typescript/typescript-resolvers'
'/typescript/typescript-resolvers': '/plugins/typescript/typescript-resolvers',
})
.concat(PLUGINS_REDIRECTS)
.map(([from, to]) => ({
Expand Down

0 comments on commit 7912f8f

Please sign in to comment.