mirror of
https://github.com/expo/apollo-codegen.git
synced 2026-11-21 09:59:25 -10:00
* Handle fragment interfaces better Instead of concat'ing inline fragment fields, it makes more sense to create a type for each inline fragment and then union'ing them. * Implement typescript inline fragment interfaces * Update typescript snapshots * Remove explicit typename validation for non-Swift targets * Do not set description on field for __typename If we're allowing explicit typename, we cannot make the assumption that every field is a normal field -- rather that some fields are introspection fields that do not have a description. * Retrieve the __typename from the parentType * remove console.log * some minor fixes * Handle fragment interfaces better Instead of concat'ing inline fragment fields, it makes more sense to create a type for each inline fragment and then union'ing them. * Implement typescript inline fragment interfaces * Update typescript snapshots * Only generate typename within the flow/typescript codegen instead of adding it to the IR * Fix fragments in various areas - Fix fragments that are in selection sets that are not fragments - Fix fragments in fragment on interface in fragment on interface - Ensure works with type alias * Use better unique names to name resulting fragment types - If inline fragments in fragments, nothing changes - If inline fragments in a selection set that is not part of a fragment, use the operation name as the suffix. * get __typename added to all the right places * Handle fragment interfaces better Instead of concat'ing inline fragment fields, it makes more sense to create a type for each inline fragment and then union'ing them. * Implement typescript inline fragment interfaces * Update typescript snapshots * Remove explicit typename validation for non-Swift targets * Do not set description on field for __typename If we're allowing explicit typename, we cannot make the assumption that every field is a normal field -- rather that some fields are introspection fields that do not have a description. * Retrieve the __typename from the parentType * remove console.log * some minor fixes * Only generate typename within the flow/typescript codegen instead of adding it to the IR * Fix fragments in various areas - Fix fragments that are in selection sets that are not fragments - Fix fragments in fragment on interface in fragment on interface - Ensure works with type alias * Use better unique names to name resulting fragment types - If inline fragments in fragments, nothing changes - If inline fragments in a selection set that is not part of a fragment, use the operation name as the suffix. * get __typename added to all the right places * downgrade inflected
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import {readFileSync} from 'fs';
|
|
import path from 'path';
|
|
|
|
import {loadSchema, loadAndMergeQueryDocuments} from '../src/loading';
|
|
|
|
import {validateQueryDocument} from '../src/validation';
|
|
|
|
const schema = loadSchema(require.resolve('./starwars/schema.json'));
|
|
|
|
describe('Validation', () => {
|
|
test(`should throw an error for AnonymousQuery.graphql`, () => {
|
|
const inputPaths = [
|
|
path.join(__dirname, './starwars/AnonymousQuery.graphql'),
|
|
];
|
|
const document = loadAndMergeQueryDocuments(inputPaths);
|
|
|
|
expect(
|
|
() => validateQueryDocument(schema, document)
|
|
).toThrow(
|
|
'Validation of GraphQL query document failed'
|
|
);
|
|
});
|
|
|
|
test(`should throw an error for ExplicitTypename.graphql when the target is Swift`, () => {
|
|
const inputPaths = [
|
|
path.join(__dirname, './starwars/ExplicitTypename.graphql'),
|
|
];
|
|
const document = loadAndMergeQueryDocuments(inputPaths);
|
|
|
|
expect(
|
|
() => validateQueryDocument(schema, document, 'swift')
|
|
).toThrow(
|
|
'Validation of GraphQL query document failed'
|
|
);
|
|
});
|
|
|
|
test(`should not throw an error for ExplicitTypename.graphql when the target is not Swift`, () => {
|
|
const inputPaths = [
|
|
path.join(__dirname, './starwars/ExplicitTypename.graphql'),
|
|
];
|
|
const document = loadAndMergeQueryDocuments(inputPaths);
|
|
|
|
validateQueryDocument(schema, document, 'flow');
|
|
validateQueryDocument(schema, document, 'typescript');
|
|
validateQueryDocument(schema, document, 'ts');
|
|
validateQueryDocument(schema, document, 'json');
|
|
});
|
|
|
|
test(`should throw an error for TypenameAlias.graphql`, () => {
|
|
const inputPaths = [
|
|
path.join(__dirname, './starwars/TypenameAlias.graphql'),
|
|
];
|
|
const document = loadAndMergeQueryDocuments(inputPaths);
|
|
|
|
expect(
|
|
() => validateQueryDocument(schema, document)
|
|
).toThrow(
|
|
'Validation of GraphQL query document failed'
|
|
);
|
|
});
|
|
});
|