Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Multi-level item in selectionSet is not received #12701

Merged
merged 18 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/api-graphql/__tests__/APIClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,32 @@ describe('flattenItems', () => {

expect(selSet).toEqual(expected);
});

test('mix of related and non-related fields in a nested model creates a nested object with all necessary fields', () => {
const selSet = customSelectionSetToIR(
modelIntroSchema.models,
'CommunityPost',
['poll.question', 'poll.answers.answer', 'poll.answers.votes.id']
);

const expected = {
poll: {
question: '',
answers: {
items: {
answer: '',
votes: {
items: {
id: '',
},
},
},
},
},
};

expect(selSet).toEqual(expected);
});
});

describe('generateSelectionSet', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,342 @@ const amplifyConfig = {
sortKeyFieldNames: ['cpk_sort_key'],
},
},

//

CommunityPoll: {
name: 'CommunityPoll',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
question: {
name: 'question',
isArray: false,
type: 'String',
isRequired: true,
attributes: [],
},
answers: {
name: 'answers',
isArray: true,
type: {
model: 'CommunityPollAnswer',
},
isRequired: true,
attributes: [],
isArrayNullable: false,
association: {
connectionType: 'HAS_MANY',
associatedWith: ['communityPollAnswersId'],
},
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
},
syncable: true,
pluralName: 'CommunityPolls',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'auth',
properties: {
rules: [
{
allow: 'public',
provider: 'apiKey',
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
CommunityPollAnswer: {
name: 'CommunityPollAnswer',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
answer: {
name: 'answer',
isArray: false,
type: 'String',
isRequired: true,
attributes: [],
},
votes: {
name: 'votes',
isArray: true,
type: {
model: 'CommunityPollVote',
},
isRequired: true,
attributes: [],
isArrayNullable: false,
association: {
connectionType: 'HAS_MANY',
associatedWith: ['communityPollAnswerVotesId'],
},
},
communityPollAnswersId: {
name: 'communityPollAnswersId',
isArray: false,
type: 'ID',
isRequired: false,
attributes: [],
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
},
syncable: true,
pluralName: 'CommunityPollAnswers',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'key',
properties: {
name: 'gsi-CommunityPoll.answers',
fields: ['communityPollAnswersId'],
},
},
{
type: 'auth',
properties: {
rules: [
{
allow: 'public',
provider: 'apiKey',
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
CommunityPollVote: {
name: 'CommunityPollVote',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
communityPollAnswerVotesId: {
name: 'communityPollAnswerVotesId',
isArray: false,
type: 'ID',
isRequired: false,
attributes: [],
},
owner: {
name: 'owner',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
},
syncable: true,
pluralName: 'CommunityPollVotes',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'key',
properties: {
name: 'gsi-CommunityPollAnswer.votes',
fields: ['communityPollAnswerVotesId'],
},
},
{
type: 'auth',
properties: {
rules: [
{
provider: 'userPools',
ownerField: 'owner',
allow: 'owner',
identityClaim: 'cognito:username',
operations: ['create', 'update', 'delete', 'read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
CommunityPost: {
name: 'CommunityPost',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
content: {
name: 'content',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
poll: {
name: 'poll',
isArray: false,
type: {
model: 'CommunityPoll',
},
isRequired: false,
attributes: [],
association: {
connectionType: 'HAS_ONE',
associatedWith: ['id'],
targetNames: ['communityPostPollId'],
},
},

communityPostPollId: {
name: 'communityPostPollId',
isArray: false,
type: 'ID',
isRequired: false,
attributes: [],
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
},
syncable: true,
pluralName: 'CommunityPosts',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'auth',
properties: {
rules: [
{
allow: 'public',
provider: 'apiKey',
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
},
enums: {
Status: {
Expand Down