Skip to content

Commit

Permalink
Add test for inline fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgarner committed Aug 20, 2020
1 parent 128040f commit 2154132
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion src/RelationMapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('RelationMapper', () => {
]);
});

it('maps GQL selections containing fragments to ORM relations', async () => {
it('maps GQL selections containing spread fragments to ORM relations', async () => {
// language=GraphQL
const query = `
fragment ProductFragment on Product {
Expand Down Expand Up @@ -214,6 +214,82 @@ describe('RelationMapper', () => {
},
]);
});

it('accepts GQL selections containing inline fragments', async () => {
// language=GraphQL
const query = `
fragment ProductFragment on Product {
id
name
media {
... on Image {
id
sizes {
medium {
id
fileName
}
}
product {
id
}
}
... on Video {
id
duration
product {
id
}
}
}
}
query products {
products {
...ProductFragment
}
}
`;

const resolveInfoHook = (info: GraphQLResolveInfo): void => {
const relations = new RelationMapper(connection).buildRelationListForQuery(Product, info);

expect(relations).toEqual([]);
};
const result = await graphql(executableSchema, query, {}, { resolveInfoHook });

// check we hit our assertions inside the resolveInfoHook callback
expect.assertions(1 + 4);

// check the query result looks right
expect(result).toBeDefined();
expect(result.errors).toBeUndefined();
expect(result.data).toBeDefined();
expect(result.data?.products).toEqual([
{
id: mockData.productA.id,
name: mockData.productA.name,
media: [
{
id: mockData.imageA.id,
sizes: {
medium: mockData.imageA.sizeMedium,
},
product: {
id: mockData.productA.id,
},
},
{
id: mockData.videoA.id,
duration: mockData.videoA.duration,
product: {
id: mockData.productA.id,
},
},
],
},
]);
});
});

describe('isFieldSelected()', () => {
Expand Down

0 comments on commit 2154132

Please sign in to comment.