Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/basics/unionTypesFragment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { readFileSync } from 'fs';
import * as path from 'path';
import { graphqlToOpenApi } from '../../index';
import * as assert from 'assert';
import * as stringify from 'json-stable-stringify';

describe('unionTypes', function () {
it('should produce a valid openapi spec', function () {
const schema = readFileSync(
path.join(__dirname, 'unionTypesSchema.graphql')
).toString();
const inputQueryFilename = path.join(
__dirname,
'unionTypesQueryFragment.graphql'
);
const query = readFileSync(inputQueryFilename).toString();
// eslint-disable-next-line @typescript-eslint/no-var-requires
const expectedOutput = require('./unionTypes.json');
const actualOutput = graphqlToOpenApi({
schema,
query,
}).openApiSchema;
const normalizedActualOutput = stringify(actualOutput, { space: ' ' });
const normalizedExpectedOutput = stringify(expectedOutput, { space: ' ' });
assert.ok(!!actualOutput);
assert.equal(normalizedActualOutput, normalizedExpectedOutput);
});
});
35 changes: 35 additions & 0 deletions tests/basics/unionTypesQueryFragment.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
fragment FurOrHairFragment on FurOrHair {
... on Fur {
color
}
... on Hair {
color
texture
}
}

query queryInvolvingUnionTypes($name: String!) {
favoritePets(
name: $name
) {
... on Cat {
adultFur {
color
texture
}
}
... on Dog {
puppyFur {
...FurOrHairFragment
}
adultFurs {
... on Fur {
texture
}
... on Hair {
color
}
}
}
}
}