@apollo/federation
Version:
Apollo Federation Utilities
106 lines (94 loc) • 2.66 kB
text/typescript
import { noFed2Subgraphs as validateNoFed2Subgraphs } from '../';
import {
gql,
graphqlErrorSerializer,
} from 'apollo-federation-integration-testsuite';
expect.addSnapshotSerializer(graphqlErrorSerializer);
describe('noFed2Subgraphs', () => {
it('does not compose when fed2 semantics are detected. fed2.0', () => {
const serviceA = {
typeDefs: gql`
extend schema
type Product {
sku: String!
upc: String!
color: Color!
}
type Color {
id: ID!
value: String!
}
`,
name: 'serviceA',
};
const errors = validateNoFed2Subgraphs(serviceA);
expect(errors).toMatchInlineSnapshot(`
Array [
Object {
"code": "NO_FED2_SUBGRAPHS",
"locations": Array [],
"message": "[serviceA] Schema contains a Federation 2 subgraph. Only federation 1 subgraphs can be composed with the fed1 composer.",
},
]
`);
});
it('does not compose when fed2 semantics are detected. link 1.0', () => {
const serviceA = {
typeDefs: gql`
extend schema
type Product {
sku: String!
upc: String!
color: Color!
}
type Color {
id: ID!
value: String!
}
`,
name: 'serviceA',
};
const errors = validateNoFed2Subgraphs(serviceA);
expect(errors).toMatchInlineSnapshot(`
Array [
Object {
"code": "NO_FED2_SUBGRAPHS",
"locations": Array [],
"message": "[serviceA] Schema contains a Federation 2 subgraph. Only federation 1 subgraphs can be composed with the fed1 composer.",
},
]
`);
});
it('composes just fine when versions are sufficiently old', () => {
const serviceA = {
typeDefs: gql`
extend schema
type Product {
sku: String!
upc: String!
color: Color!
}
type Color {
id: ID!
value: String!
}
`,
name: 'serviceA',
};
const errors = validateNoFed2Subgraphs(serviceA);
expect(errors).toEqual([]);
});
});