Merge pull request #2693 from payloadcms/fix/2685-graphql-relations
Fix/2685 graphql relations
This commit is contained in:
@@ -64,6 +64,11 @@ export default buildConfig({
|
||||
type: 'relationship',
|
||||
relationTo: relationSlug,
|
||||
},
|
||||
{
|
||||
name: 'relationToCustomID',
|
||||
type: 'relationship',
|
||||
relationTo: 'custom-ids',
|
||||
},
|
||||
// Relation hasMany
|
||||
{
|
||||
name: 'relationHasManyField',
|
||||
@@ -86,10 +91,26 @@ export default buildConfig({
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'custom-ids',
|
||||
access: {
|
||||
read: () => true,
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'id',
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
collectionWithName(relationSlug),
|
||||
collectionWithName('dummy'),
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
onInit: async payload => {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
@@ -98,12 +119,29 @@ export default buildConfig({
|
||||
},
|
||||
});
|
||||
|
||||
await payload.create({
|
||||
collection: 'custom-ids',
|
||||
data: {
|
||||
id: 1,
|
||||
title: 'hello',
|
||||
},
|
||||
});
|
||||
|
||||
await payload.create({
|
||||
collection: slug,
|
||||
data: {
|
||||
title: 'has custom ID relation',
|
||||
relationToCustomID: 1,
|
||||
},
|
||||
});
|
||||
|
||||
await payload.create({
|
||||
collection: slug,
|
||||
data: {
|
||||
title: 'post1',
|
||||
},
|
||||
});
|
||||
|
||||
await payload.create({
|
||||
collection: slug,
|
||||
data: {
|
||||
|
||||
@@ -364,6 +364,29 @@ describe('collections-graphql', () => {
|
||||
expect(docs).toContainEqual(expect.objectContaining({ id: specialPost.id }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('relationships', () => {
|
||||
it('should query on relationships with custom IDs', async () => {
|
||||
const query = `query {
|
||||
Posts(where: { title: { equals: "has custom ID relation" }}) {
|
||||
docs {
|
||||
id
|
||||
title
|
||||
relationToCustomID {
|
||||
id
|
||||
}
|
||||
}
|
||||
totalDocs
|
||||
}
|
||||
}`;
|
||||
|
||||
const response = await client.request(query);
|
||||
const { docs, totalDocs } = response.Posts;
|
||||
|
||||
expect(totalDocs).toStrictEqual(1);
|
||||
expect(docs[0].relationToCustomID.id).toStrictEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error Handler', () => {
|
||||
|
||||
Reference in New Issue
Block a user