Skip to content

Commit

Permalink
Merge pull request #10322 from dricholm/ra-data-graphql-simple-variab…
Browse files Browse the repository at this point in the history
…les-meta

fix(ra-data-graphql-simple): Unify meta location in buildVariables
  • Loading branch information
djhi authored Nov 8, 2024
2 parents 60d2de9 + a5555d3 commit dac5101
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
55 changes: 35 additions & 20 deletions packages/ra-data-graphql-simple/src/buildVariables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('buildVariables', () => {
},
],
};

describe('GET_LIST', () => {
it('returns correct variables', () => {
const params = {
Expand Down Expand Up @@ -55,8 +56,8 @@ describe('buildVariables', () => {

it('should return correct meta', () => {
const params = {
filter: {},
meta: { sparseFields: [] },
filter: { views: 100 },
meta: { sparseFields: ['field'] },
};

expect(
Expand All @@ -67,8 +68,8 @@ describe('buildVariables', () => {
{}
)
).toEqual({
filter: {},
meta: { sparseFields: [] },
filter: { views: 100 },
meta: { sparseFields: ['field'] },
});
});
});
Expand Down Expand Up @@ -99,11 +100,11 @@ describe('buildVariables', () => {
title: 'Foo',
});
});

it('should return correct meta', () => {
const params = {
data: {
meta: { sparseFields: [] },
},
data: { title: 'Foo' },
meta: { sparseFields: ['field'] },
};
const queryType = {
args: [],
Expand All @@ -117,7 +118,8 @@ describe('buildVariables', () => {
queryType
)
).toEqual({
meta: { sparseFields: [] },
title: 'Foo',
meta: { sparseFields: ['field'] },
});
});
});
Expand Down Expand Up @@ -153,9 +155,9 @@ describe('buildVariables', () => {

it('should return correct meta', () => {
const params = {
data: {
meta: { sparseFields: [] },
},
id: 'post1',
data: { title: 'Foo' },
meta: { sparseFields: ['field'] },
};
const queryType = {
args: [],
Expand All @@ -169,7 +171,9 @@ describe('buildVariables', () => {
queryType
)
).toEqual({
meta: { sparseFields: [] },
id: 'post1',
title: 'Foo',
meta: { sparseFields: ['field'] },
});
});
});
Expand All @@ -194,7 +198,8 @@ describe('buildVariables', () => {

it('should return correct meta', () => {
const params = {
meta: { sparseFields: [] },
ids: ['tag1'],
meta: { sparseFields: ['field'] },
};

expect(
Expand All @@ -205,8 +210,10 @@ describe('buildVariables', () => {
{}
)
).toEqual({
filter: {},
meta: { sparseFields: [] },
filter: {
ids: ['tag1'],
},
meta: { sparseFields: ['field'] },
});
});
});
Expand Down Expand Up @@ -238,7 +245,9 @@ describe('buildVariables', () => {

it('should return correct meta', () => {
const params = {
meta: { sparseFields: [] },
target: 'author_id',
id: 'author1',
meta: { sparseFields: ['field'] },
};

expect(
Expand All @@ -249,8 +258,8 @@ describe('buildVariables', () => {
{}
)
).toEqual({
filter: {},
meta: { sparseFields: [] },
filter: { author_id: 'author1' },
meta: { sparseFields: ['field'] },
});
});
});
Expand All @@ -260,6 +269,7 @@ describe('buildVariables', () => {
const params = {
id: 'post1',
};

expect(
buildVariables(introspectionResult)(
{ type: { name: 'Post', inputFields: [] } },
Expand All @@ -274,8 +284,10 @@ describe('buildVariables', () => {

it('should return correct meta', () => {
const params = {
meta: { sparseFields: [] },
id: 'post1',
meta: { sparseFields: ['field'] },
};

expect(
buildVariables(introspectionResult)(
{ type: { name: 'Post', inputFields: [] } },
Expand All @@ -284,7 +296,8 @@ describe('buildVariables', () => {
{}
)
).toEqual({
meta: { sparseFields: [] },
id: 'post1',
meta: { sparseFields: ['field'] },
});
});
});
Expand All @@ -294,6 +307,7 @@ describe('buildVariables', () => {
const params = {
ids: ['post1'],
};

expect(
buildVariables(introspectionResult)(
{ type: { name: 'Post', inputFields: [] } },
Expand All @@ -315,6 +329,7 @@ describe('buildVariables', () => {
title: 'New Title',
},
};

expect(
buildVariables(introspectionResult)(
{ type: { name: 'Post', inputFields: [] } },
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-data-graphql-simple/src/buildVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ const buildGetListVariables =
const buildCreateUpdateVariables = (
resource: IntrospectedResource,
raFetchMethod,
{ id, data }: any,
{ id, data, meta }: any,
queryType: IntrospectionField
) =>
Object.keys(data).reduce(
Expand Down Expand Up @@ -358,5 +358,5 @@ const buildCreateUpdateVariables = (
[key]: data[key],
};
},
{ id }
{ id, meta }
);

0 comments on commit dac5101

Please sign in to comment.